Question

I have a Hibernate search that searches from many a field of an object. Is it possible to know which of the fields matched the results for each result object?

Was it helpful?

Solution

Not out of the box. Some information about which fields matched can be extracted from the Lucene Explanation object which you can retrieve via projection in Hibernate Search. The problem is that this object is designed for visual inspection of the search results not as a programmatic interface. You could parse the string output, but the format might change in later versions of Lucene.

Another option would be to iterate the matching documents and manually (eg via regular expressions) try to find out which fields matched. This is quite tricky as well, since depending on your Lucene query it might be quite hard to come up with a regular expression.

It comes down to your concrete usecase. What do you need this information for? Maybe there is an alternative solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top