In Lucene, I would like to build a 'fuzzy' query over numeric fields. Currently all I found was the NumericRangeQuery class to search numeric fields. In the application I am building, the user is to specify a set of types and the amount of objects of this type he would wish to occur in a specific collection. For example, the user may query for "4 spoons, 13 forks and 1 knife".
I would need a query that scores each numeric field based on the distance of the desired amount and the actual amount. For example, score = (distance + 1)^-1 should yield nice results. Is there a simple, efficient way of doing this?
A Payload should do actually what you want. It allows you to attach arbitrary data to each of your terms, that can then be retrieved during searching to effect scoring, matching and sorting.
Specifically, have a look at the PayloadNearQuery.
From the example you have described however it is a little ambiguous as to exactly what you need to do. e.g. do the numbers 4, 13 and 1 have anything to do with the number of hits for a query for spoons, forks and knife? Or, are you storing those counts in the index?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With