The getCount method allows you to get the number of character replacements defined in the dictionary.
To add character replacements to the dictionary, use the addRange method.
To remove character replacements from the dictionary, the removeRange method is used.
The contains method is used to determine if the dictionary contains a replacement for the specified character.
To get a replacement for the specified character, use the getReplacement method.
To remove all replacements from the dictionary, use the clear method.
To export all replacements to a file, use the exportDictionary method.
To import character replacements from a file, use the importDictionary method.
The following example demonstrates the use of the character replacement dictionary methods.
constindexFolder='c:/MyIndex/';constdocumentsFolder='c:/MyDocuments/';// Enabling character replacements in the index settings
constsettings=newgroupdocs.search.IndexSettings();settings.setUseCharacterReplacements(true);// Creating an index from in specified folder
constindex=newgroupdocs.search.Index(indexFolder,settings,true);if(index.getDictionaries().getCharacterReplacements().getCount()>0){// Deleting all character replacements from the dictionary
index.getDictionaries().getCharacterReplacements().clear();}// Adding character replacement
constrange=java.newArray('com.groupdocs.search.dictionaries.CharacterReplacementPair',[newgroupdocs.search.CharacterReplacementPair(java.newChar('-'),java.newChar('~')),]);index.getDictionaries().getCharacterReplacements().addRange(range);if(index.getDictionaries().getCharacterReplacements().contains(java.newChar('-'))){constreplacement=index.getDictionaries().getCharacterReplacements().getReplacement(java.newChar('-'));console.log('The replacement for hyphen is '+replacement);// Deleting the hyphen character replacement from the dictionary
index.getDictionaries().getCharacterReplacements().removeRange(java.newArray('char',['-']));}// Creating new character replacements
constcount=65536;constarray=newArray(count);for(leti=0;i<count;i++){consttext=String.fromCharCode(i);constcharacter=java.newChar(text);constreplacement=java.newChar(text.toLowerCase()[0]);array[i]=newgroupdocs.search.CharacterReplacementPair(character,replacement);}constcharacterReplacements=java.newArray('com.groupdocs.search.dictionaries.CharacterReplacementPair',array);// Adding character replacements to the dictionary
index.getDictionaries().getCharacterReplacements().addRange(characterReplacements);// Export character replacements to a file
constfileName=Utils.OutputPath+'AdvancedUsage/ManagingDictionaries/characterReplacements/CharacterReplacements.dat';index.getDictionaries().getCharacterReplacements().exportDictionary(fileName);// Import character replacements from a file
index.getDictionaries().getCharacterReplacements().importDictionary(fileName);// Indexing documents from the specified folder
index.add(documentsFolder);// Search in the index
constquery='Elliot';constoptions=newgroupdocs.search.SearchOptions();options.setUseCaseSensitiveSearch(true);constresult=index.search(query,options);
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: