How does Numeric Range Search works in Java?

Hi !
I tried using NumericRange Search. I created a new document and added “1,2,3,5,10” in it.
It should give hits as 5 right ? Is this the way it works ?
But, I am getting total hits as 7 in the document.
Please guide me with it’s working, as nothing more than the code and basic one liner, is given on the website. So, please help me understand it’s working, what it counts, how it calculates the hits ?

Thanks !

@Kushal.20,

Can you please tell what was your search query/string? Also share the document you created.

@atirtahir3
Here goes my code :

public static void numericRangeSearch() {
Index index = new Index(Utilities.INDEX_PATH);
index.addToIndex(Utilities.DOCUMENTS_PATH);

	// Search for numbers
	String searchQuery = "1~~10";
	SearchResults searchResults = index.search(searchQuery);
	if (searchResults.getCount() > 0) {
		// Print list of found files in the console
		for (DocumentResultInfo documentResultInfo : searchResults) {
			System.out.println("Document path: " + documentResultInfo.getFileName());
			System.out.println("Hit count: " + documentResultInfo.getHitCount());
		}
	} else {
		System.out.println("No results found");
	}
}

Also, I am attaching my file where I checked for the search. Please find the same as attached . New Text Document.zip (190 Bytes)

I am getting this as output on the console :
Document path: E:\docs\New Text Document.txt
Hit count: 7

@Kushal.20,

We are investigating this. Your investigation ticket ID is SEARCHJAVA-80. As we have any further updates, we’ll notify you.

@Kushal.20,

This result is expected. Why? Because the index searches not only in text content of the document, but also in all other fields of the document.
And other fields like ‘creationdate’ and ‘modificationdate’ always contain numbers. In order to visualize this, add below code in your example project:

SearchResults searchResults = index.search(searchQuery);
index.highlightInText("D:\\highlighted.html", searchResults.get_Item(2));

In get_item(0), you have to specify txt file position in my case txt file position is 2 as per below output:

inside for
1 hits are in D:\search\Data\Documents\Excel.xlsx
inside for
5 hits are in D:\search\Data\Documents\New Microsoft Word Document.docx
inside for
5 hits are in D:\search\Data\Documents\New Text Document.txt

You can see highlighted.zip (494 Bytes) results.
However, to search only in content field you should use query like in the following snippet:

String searchQuery = "content: 1 ~~ 10";
SearchResults searchResults = index.search(searchQuery);

Hope it will help.

@atirtahir3
Okay buddy, got the mechanism now.
Thanks for this ! It helped ! :slight_smile:
I am facing some problem with Password Protected Search. Anyways, I would create another topic for that.
Thanks, once again ! :v:

1 Like

@Kushal.20,

You are welcome :slight_smile:

1 Like