Free Support Forum - groupdocs.com

Simple Search for Java is not working


#15

@Kushal.20,

You are welcome.


#16

@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 !


#17

@Kushal.20,

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


#18

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)


#19

@Kushal.20,

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


#20

@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.


#21

@Kushal.20,

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


#22

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


#23

@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

#24

@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 ?


#25

@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.


#26

@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 ?


#27

@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());

#28

@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()


#29

@Kushal.20,

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


#30

Okay. Thanks ! @atirtahir3


#31

@Kushal.20,

Let me share reason for this issue.
The problem occurs during re-indexing of password protected documents that are available in the directory. It will be fixed and you’ll be notified about that.
Right now, as a temporary solution, you can exclude password protected documents from indexing or provide the valid passwords for them.


#32

Hi ! @atirtahir3
Hope you are doing good !
Well, why is it so, that every new time simple search stops performing.
I came back to it today to try some new queries but it again stopped working. Everything is same, license is applied, I created index each time I ran it.
Please help me with this as it is very annoying. I am actually searching a for a fast and efficient document search tool. Groupdocs solved many of my requirements, but this behaviour each time, I am afraid !


#33

@Kushal.20,

We are sorry for the inconvenience you are facing.

Can you please share string/word that you are trying to search and in which document such a word exists, we’ll then investigate it at our end. (assuming that you are searching on same document directory)?


#34

@Kushal.20,

We are pleased to notify you that your reported issue SEARCHJAVA-82 is now resolved in version 19.5.1. Please download and integrate latest release of the API and share your feedback.