Stop word dictionary

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 Count property.

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.

To export words to a file, use the ExportDictionary method.

To import words from a file, use the ImportDictionary method.

The following example demonstrates the use of methods of the stop word dictionary.

C#

string indexFolder = @"c:\MyIndex\";
 
// Creating an index from in specified folder
Index index = new Index(indexFolder);
 
if (index.Dictionaries.StopWordDictionary.Count > 0)
{
    // Removing all words from the dictionary
    index.Dictionaries.StopWordDictionary.Clear();
}
 
// Adding stop words to the dictionary
string[] words = new string[] { "a", "an", "the", "but", "by" };
index.Dictionaries.StopWordDictionary.AddRange(words);
 
if (index.Dictionaries.StopWordDictionary.Contains("but") &&
    index.Dictionaries.StopWordDictionary.Contains("by"))
{
    // Removing words from the dictionary
    index.Dictionaries.StopWordDictionary.RemoveRange(new string[] { "but", "by" });
}
 
// Export words to a file
index.Dictionaries.StopWordDictionary.ExportDictionary(@"C:\Words.txt");
 
// Import words from a file
index.Dictionaries.StopWordDictionary.ImportDictionary(@"C:\Words.txt");

More resources

GitHub examples

You may easily run the code from documentation articles and see the features in action in our GitHub examples:

Free online document search App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our free online Free Online Document Search App.

© Aspose Pty Ltd 2001-2022. All Rights Reserved.