Search for different word forms

The search for different word forms allows you to search for nouns in the singular or plural, degrees of comparison of adjectives, forms of regular and irregular verbs, etc.

Search for different word forms is enabled if the use_word_forms_search property of the SearchOptions class is set to True. By default, the search for different word forms is disabled. The search for different word forms cannot be combined with case-sensitive search. If both are enabled, the search returns an empty result and the error is reported through the error_occurred event (see Search options).

To generate various forms of words, a class that implements the IWordFormsProvider interface is used. The default class is EnglishWordFormsProvider, which supports English-only word forms. To add support for word forms in other languages, see the Word forms provider page.

The following example demonstrates how to perform search for different word forms in an index.

import os

from groupdocs.search import Index
from groupdocs.search.options import SearchOptions

# Creating an index in the specified folder
index = Index("./index")

# Indexing documents from the specified folder
index.add("./documents")

# Creating a search options instance
options = SearchOptions()
options.use_word_forms_search = True  # Enabling search for word forms

# Searching in the index
result = index.search("relative", options)

# The following words can be found:
# relative
# relatives
# relatively

# Printing the words found in each document
print("Documents found:", result.document_count)
for document in result:
    print("   ", os.path.basename(document.document_info.file_path), document.terms)

The following sample files are used in this example: documents/relativity-primer.txt, documents/family-visit.txt

Documents found: 1
    family-visit.txt ['relative', 'relatives', 'relatively']

Download full output

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 the full-featured 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.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.