Homophone search

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Search MCP server lets your agent work with files on your machine; they are never uploaded. It runs in Docker: replace /path/to/documents with the folder it may use.

claude mcp add groupdocs-search -- docker run --rm -i -v /path/to/documents:/data ghcr.io/groupdocs-search/search-net-mcp:latest
Folders, licensing and more →

Homophone search, or in other words phonic search, allows you to find not only the words specified in the search query, but also their homophones, that is, words that are pronounced the same but differ in meaning.

To enable homophone search, you must set the use_homophone_search property of the SearchOptions class to True. By default, homophone search is disabled. Homophone search cannot be combined with case-sensitive search. If homophone search is enabled together with case-sensitive search, or if the homophone dictionary of the index is empty, the search returns an empty result and the error is reported through the error_occurred event (see Search options).

The default homophone dictionary contains homophones only for the English language. To manage the homophone dictionary, see the Homophone dictionary page in the Managing dictionaries section.

The following example demonstrates the homophone search.

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 object
options = SearchOptions()
options.use_homophone_search = True  # Enabling homophone search

# Search for the word 'coal'
# In addition to the word 'coal', the words 'cole' and 'kohl' will also be found
result = index.search("coal", options)

# 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/quantum-theory.txt, documents/coal-mining.txt, documents/cosmetics-history.txt

Documents found: 2
    coal-mining.txt ['coal', 'cole']
    cosmetics-history.txt ['kohl']

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.