Character replacement during indexing can be used, for example, to convert all text to lowercase characters or to remove diacritics from text. Such replacements can reduce the size of an index on disk if the case of characters or diacritics are not significant. See also Character replacements page in the Managing dictionaries section.
The example below demonstrates how to configure and use character replacements during indexing.
constindexFolder='c:/MyIndex/';constdocumentFolder='c:/MyDocuments/';// Enabling character replacements in the index settings
constsettings=newgroupdocs.search.IndexSettings();settings.setUseCharacterReplacements(true);// Creating an index in the specified folder
constindex=newgroupdocs.search.Index(indexFolder,settings);// Configuring character replacements
// Deleting all existing character replacements from the dictionary
index.getDictionaries().getCharacterReplacements().clear();// 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);// Indexing documents from the specified folder
index.add(documentFolder);// Searching in the index
// Case-sensitive search is no longer possible for this index, since all characters are lowercase
// By default, case-insensitive search is performed
constquery='Einstein';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: