0
votes

My requirement is if user searches the 'Page number' using Lucene search, Search results should take care of matching the Page number in the result with Exact Page number match on top of the list.

Now in my case I tried to sort using SortField -

new Sort(new SortField("bookPageNumber", SortField.STRING));

Suppose I searched term '5' then in the search result instead of showing Exact Page number match on top of the list it shows searched term '5' which is present at each page.

Can anyone suggest how to include Page Number in Lucene Search results on top of the list.

My code -

QueryParser qParser;
qParser = new QueryParser("contents", new StandardAnalyzer(Version.LUCENE_CURRENT));
qParser.setDefaultOperator(QueryParser.Operator.AND);
String searchResultMaxCount = "10";
int maxCount = Integer.parseInt(searchResultMaxCount);
Query query = qParser.parse("5");
Sort sort = new Sort(new SortField("bookPageNumber", SortField.STRING));
TopDocs topDocs = indexSearcher.search(query, null, maxCount, sort);
1
How are you indexing your documents? Is each page a separate document?femtoRgon
No, it is indexed as a single document.Jatin
any update on this?dom
did you get any solution?Ganesh Gudghe

1 Answers

0
votes

I think this would be a nice example to change the scoring of a field with boosts. With a boost you're able to manipulate the score of your search results. In your case: add a boost to your bookPageNumberField.

You can do that in two ways: Add a boost while indexing or add one while searching with a query.

More Informations here: http://lucene.apache.org/core/6_6_0/core/org/apache/lucene/search/package-summary.html#scoringBasics