开发者

Numeric Range Query

开发者 https://www.devze.com 2023-01-29 00:13 出处:网络
I read that for handling date range query NumericRangeQue开发者_如何学Cry is better than TermRangeQuery in \"Lucene in action\", But i couldnot find the reason. i want to know the reason behind it.

I read that for handling date range query NumericRangeQue开发者_如何学Cry is better than TermRangeQuery in "Lucene in action", But i couldnot find the reason. i want to know the reason behind it. I used TermRangeQuery and NumericRangequery both for handling date range query and i found that searching is fast via NumericRangeQuery.

My second point is to query using NumericRangeQuery i have to create indexes using NumericField by which i can create indexes upto milisecond but what if i want to reduce my resolution upto hour or day.


  • Why is numeric so much faster than term?

As you have noted, there is a "precision step". This means that numbers are only stored to a certain precision, which means that there is a (very) limited number of terms. According to the documentation, it is rare to have more than 300 terms in an index. Check out the wikipedia article on Tries if you are interested in the theory.

  • How can you reduce precision?

The NumericField class has a "precision" parameter in the constructor. Note that the range query also has a precision parameter, and they must be the same. That JavaDoc page has a link to a paper written about the implementation explaining more of what precision means.


Explanation by @Xodarap about Numeric field is correct. Essentially, the precision is dropped for the numbers to reduce the actual term space. Also, I suppose, TermRangeQuery uses String comparison whereas NumericRange query is working with integers. That should squeeze some more performance.

You can index at any desirable resolution - millisecond to day. Date.getTime() gives you milliseconds since epoch. You can divide this number by 1000 to get time with resolution at second. Or you can divide by 60,000 to get resolution at minute. And so on.

0

精彩评论

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

关注公众号