Lucene LongField exact search with Query

↘锁芯ラ 提交于 2019-12-05 15:16:27

Consider the warning on the NumericUtils API

NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

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.

Instead, use a NumericRangeQuery to search for numeric values. Precise matches can be obtained by setting maximum and minimum ranges to equal values.

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.

BytesRef ref = new BytesRef();    
NumericUtils.longToPrefixCoded( 12L, 0, ref );
Query q = new TermQuery( new Term( fieldname, ref ) );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!