Simple Search for Java is not working

@Kushal.20,

Good to know that.

Yes, you have to put all the documents (you want to perform search on) in a folder. Then create index for this folder in order to perform search.

Yes this is how it works. We’d recommend you to go through the documentation as well.

Any suggestions, why ?
If I want my entire directory to be searched instead of any specific folder, then ?

@Kushal.20,

You can set DOCUMENTS_PATH to “E://” or like this,

// Add documents to index
index.addToIndex("E://");

Please note that in the example project, INDEX_PATH is the path where indexes will be saved and DOCUMENTS_PATH is source documents path. It contains files over which you want to perform search operations.
Have a look at supported document formats and this output.png (74.1 KB). We performed a search over E drive.

This may take time because there could be a lot of data in your E drive and API has to create index for such data. Eventually, you can perform search over a directory but indexing may take time depending on data in it.

Okay !
Thanks a lot , @atirtahir3

1 Like

@Kushal.20,

You are welcome.

1 Like

@atirtahir3
Hi !
After 2-3 days, am again performing simple search with the same steps, as I did previously. The only difference is the search query. I have changed the search query this time, but it is not responding. While, I search for the queries that I searched previously are giving me results.
Why is it so ?
I have even cleared the Document Indexes folders, then called creatIndexOnDisk , and then called simpleSearch method. But, no response.
Can you diagnose this for me, please?
Thanks !

@Kushal.20,

What is your search term/query that is not showing results? And what output do you get, please share screenshot.

I am searching for the word, ‘away’
Here goes my code :
public static void simpleSearch() {
// Create index
Index index = new Index(Utilities.INDEX_PATH);

	// Add documents to index
	index.addToIndex(Utilities.DOCUMENTS_PATH);
	// Search in index
	SearchResults searchResults = index.search("away");
	// Print results in the console
	for (DocumentResultInfo result : searchResults) {
		System.out.println(result.getHitCount() + " hits are in " + result.getFileName());
	}
}

Here is the output : simpleSearch.PNG (31.6 KB)

@Kushal.20,

Do you know any document that has ‘away’ word in it under documents directory?

@atirtahir3
I have shared with you the code and the screenshot of the output console.
yes, it does exist. I have 2-3 documents containing ‘away’ in my directory.
I am afraid, as I assured my colleagues that I have got this working. Please help me get through this ASAP.

@Kushal.20,

Please share all the documents with ‘away’ word. Share password , if they are password protected. We’ll then investigate it.

@atirtahir3
Please find them here : docs.zip (1.1 MB)

@Kushal.20,

We didn’t face any issue - See output.PNG (63.2 KB). What we did:

  • Deleted indexed files
  • Added new files (provided by you) in the document directory
  • Created index in directory
  • Performed simple search

@atirtahir3
Exactly, Its working perfectly at your end.
Is there any need to create index every time, when I need to search a new query ?
Where am I going wrong then? I followed the same steps too !
There seems to be an issue or two at my end, for sure, because that day too, I got it working for me after so much efforts.
Any idea ? Maybe some environment or config requirements ?
Is there any issue with the evaluation version ?

@Kushal.20,

Did you apply license properly? Even if you have a temporary license and it is applied properly, you will not face limitations. Make sure license is not expired.

You don’t have to create index every time until and unless you do some changes in the existing documents or you add new files in the documents directory.
Only in case of any change in the documents directory you have to update index. Currently, there’s some issue in updating the index and we are investigating this. So, you have to clear index directory and then create index again.

@atirtahir3
I don’t understand, what the issue is !
I am using the 30 days temporary licensed version for GroupDocs. The license is perfectly applied and I got it about an hour ago, approx, so I don’t think so there could be any case of expiry.

I am unable to understand the behaviour, sometimes it is working, for the previously searched terms, it’s working fine, on the other hand sometimes(mostly) it’s giving no response. I am following the same prescribed steps , still facing this unexpected behaviour.
I am searching for, ‘this’ and I have it in my documents, still getting no response.Is this how I need to struggle everytime for a new search ?
What to do in this case ?

@Kushal.20,

Let us elaborate you why you don’t get hits/output when you search ‘This’ word. You have to disable using stop words in your code as follows:

index.getIndexingSettings().setUseStopWords(false);
index.addToIndex(Utilities.DOCUMENTS_PATH);

Please go through this article for further clarification. Using stop words is enabled by default. So it doesn’t index words such as a, an, the, it, were, this etc. Hence, they don’t appear in search results.
Please disable them and try again (Set setUseStopWords to false).
You don’t have to do any struggle if you search any term that is already available in the docs. But when you update a doc or add new doc in the directory then you have to update index and perform search.

Below is the code to find out if the search term/word is Stop Word or not:

SearchResults searchResults = index.search(searchQuery);
System.out.println("Search result message: " + searchResults.getMessage());

@atirtahir3
Thanks for the information ! This is helpful.
I disabled these stop words, and it worked. :v: :slight_smile:
While, using index.update(), is giving an ArrayIndexOutOfBoundException. Following is the exception stack trace :

Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 0
at com.groupdocs.search.et.a(Unknown Source)
at com.groupdocs.search.ay.a(Unknown Source)
at com.groupdocs.search.ay.dl(Unknown Source)
at com.groupdocs.search.ay.a(Unknown Source)
at com.groupdocs.search.bZ.o(Unknown Source)
at com.groupdocs.search.cm.b(Unknown Source)
at com.groupdocs.search.ch.a(Unknown Source)
at com.groupdocs.search.Index.a(Unknown Source)
at com.groupdocs.search.Index.a(Unknown Source)
at com.groupdocs.search.Index.update(Unknown Source)
at com.groupdocs.search.Index.update(Unknown Source)
at com.groupdocs.search.examples.Searching.simpleSearch(Searching.java:46)
at com.groupdocs.search.examples.MainClass.main(MainClass.java:17)

And, this is the code snippet :
public static void simpleSearch() {

	License lic = new License();
	lic.setLicense("xyz");
	
	// Create index
	Index index = new Index(Utilities.INDEX_PATH);
	index.getIndexingSettings().setUseStopWords(false);
	// Add documents to index
	index.addToIndex(Utilities.DOCUMENTS_PATH);
	
	// Search in index
	String searchQuery = "you";
	index.update();
	SearchResults searchResults = index.search(searchQuery);
	index.highlightInText(Utilities.DOCUMENT_TEXT_PATH, searchResults.get_Item(0));
	// Print results in the console
	for (DocumentResultInfo result : searchResults) {
		System.out.println(result.getHitCount() + " hits are in " + result.getFileName());
	}
}

This is solved as soon as I remove, index.update()

1 Like

@Kushal.20,

This is under investigation with ID : SEARCHJAVA-82. As we have any further update on this, you’ll be notified.

Okay. Thanks ! @atirtahir3

1 Like