Free Support Forum -

Synonym search using Java


I am using for java for synonym search.

My requirement is that I have a data set, with all the synonyms for a word and I have to return the data in case any synonym is matched

In case I search for small or little I should get small in the output.

I have tried below code:
public class Searching {
public static void synonymSearch() {
Index index = new Index(Utilities.INDEX_PATH);
SearchParameters parameters = new SearchParameters();

	String searchString = "virtual";
	SearchResults searchResults =, parameters);
	// Print found results in the console
	for (DocumentResultInfo documentResultInfo : searchResults) {
		System.out.println(documentResultInfo.getFileName() + "\n");


But I am getting filename in the output instead of data.

Please help me.


1 Like


You can get data as well. Below is the code to achieve this:

SearchResults searchResults =, parameters);
index.highlightInText("D:\\highlighted.html", searchResults.get_Item(0)); 

This is what (1.1 KB) you will get in the output. If you see the code below,


0 is the file hit number. For example, if there are 10 files, and search result hit is found in the very first file then its hit number is 0.

Thanks for the reply.

My problem statement is that I have a data set of synonyms in csv format.

User will provide the input, I have to search for it inside my data set and have to return first matching element.

example if I search for big or large my output will be big

Is this possible?? If yes please help me in this.



We are investigating this scenario. Your investigation ticket ID is SEARCHJAVA-97. As we have any further update, you’ll be notified.


We have an update on SEARCHJAVA-97. Synonym Search searches for any of a synonym from a group. As you want to search always the first word from a group for any input word contained in this group. GroupDocs.Search for Java doesn’t provide such feature. However, you can use HashMap<String, String> class to get the first word for any word contained in a group.
For example, if you have a group of 4 words: w1, w2, w3, w4. You could do something like this:

HashMap<String, String> map = new HashMap<String, String>();
map.put(w2, w1);
map.put(w3, w1);
map.put(w4, w1);
String word = map.get(query);
if (word == null) word = query;

Hope it will be helpful.