Lucene LongField使用查询进行精确搜索 [英] Lucene LongField exact search with Query
问题描述
如何使用TermQuery完全匹配LongField?
How can I use a TermQuery to exactly match a LongField?
推荐答案
请考虑 注意:此API仅供内部使用,在下一版本中可能会以不兼容的方式进行更改.
我注意到这对于某些人来说是一个问题,因为NumericUtils API确实确实从版本4.0 .我建议避免直接使用它.
I've noticed this becoming a problem for some people, since the NumericUtils API did indeed change significantly from Version 3.6 to Version 4.0. I would recommend avoiding using it directly.
相反,请使用 NumericRangeQuery 搜索数值.可以通过将最大和最小范围设置为相等的值来获得精确的匹配.
Instead, use a NumericRangeQuery to search for numeric values. Precise matches can be obtained by setting maximum and minimum ranges to equal values.
此外,刻意选择哪些字段应为数字字段可能会有所帮助. NumericFields旨在允许数字范围查询和排序.如果您不需要使用它作为数字值进行搜索,则它可能不应该是NumericField.例如,识别号通常应该是关键字,而不是数字.
Also, deliberately selecting which fields should be numeric may be helpful. NumericFields are designed to allow numeric range querying and sorting. If you don't need to search using it as a numeric value, it probably shouldn't be a NumericField. Identification numbers, for instance, generally should be keywords, not numbers.
这篇关于Lucene LongField使用查询进行精确搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!