开发者

Searching numeric fields

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 fie开发者_开发百科ld 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜