Skip to content

Instantly share code, notes, and snippets.

@groupdocs-com-kb
Last active January 11, 2025 11:57
Perform Homophone Search using Java. For more information, please follow link: https://kb.groupdocs.com/search/java/perform-homophone-search-using-java/
import com.groupdocs.search.Index;
import com.groupdocs.search.IndexSettings;
import com.groupdocs.search.licenses.License;
import com.groupdocs.search.options.Compression;
import com.groupdocs.search.options.SearchOptions;
import com.groupdocs.search.options.TextStorageSettings;
import com.groupdocs.search.results.SearchResult;
public class PerformHomophoneSearchusingJava {
public static void main(String[] args) throws Exception {
// Apply the license to remove the restrictions
// imposed by the Search library
License license = new License();
license.setLicense("GroupDocs.Search.lic");
// The path where the index will be stored
String indexFolder = "c:\\MyIndex\\";
// The folder containing the documents you want to search
String documentsFolder = "c:\\MyDocuments\\";
// Creating an index settings instance
IndexSettings settings = new IndexSettings();
// Enabling the storage of extracted text in the index
settings.setTextStorageSettings(new TextStorageSettings(Compression.High));
// Creating an index in the specified folder
Index index = new Index(indexFolder, settings);
// Indexing documents from the specified folder
index.add(documentsFolder);
// Creating a search options object
SearchOptions options = new SearchOptions();
options.setUseHomophoneSearch(true); // Enabling homophone search
// Search for the word 'coal'
// In addition to the word 'coal', the words 'cole' and 'kohl' will also be found
SearchResult result = index.search("coal", options);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment