The StopWordDictionary class is designed to store stop words in an index. Information on using stop words during indexing is provided on the Indexing with stop words page.
To get the number of stop words in the dictionary, use the getCount method.
To add stop words to the dictionary, use the addRange method.
To remove words from the dictionary, use the removeRange method.
To check for a word in a dictionary, use the contains method.
To remove all words from the dictionary, use the clear method.
The following example demonstrates the use of methods of the stop word dictionary.
constindexFolder='c:/MyIndex/';constdocumentsFolder='c:/MyDocuments/';// Creating an index from in specified folder
constindex=newgroupdocs.search.Index(indexFolder);if(index.getDictionaries().getStopWordDictionary().getCount()>0){// Removing all words from the dictionary
index.getDictionaries().getStopWordDictionary().clear();}// Adding stop words to the dictionary
constwords=java.newArray('java.lang.String',['a','an','the','but','by']);index.getDictionaries().getStopWordDictionary().addRange(words);if(index.getDictionaries().getStopWordDictionary().contains('but')&&index.getDictionaries().getStopWordDictionary().contains('by')){// Removing words from the dictionary
index.getDictionaries().getStopWordDictionary().removeRange(java.newArray('java.lang.String',['but','by']));}// Export words to a file
constfileName=Utils.OutputPath+'AdvancedUsage/ManagingDictionaries/stopWordDictionary/Words.txt';index.getDictionaries().getStopWordDictionary().exportDictionary(fileName);// Import words from a file
index.getDictionaries().getStopWordDictionary().importDictionary(fileName);// Indexing documents from the specified folder
index.add(documentsFolder);// Search in the index
constquery='but';constresult=index.search(query);
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: