您的位置:首页 > 其它

lucene (2.9--- 3.6) 范围搜索优化

2012-07-25 11:23 316 查看
原先在处理范围搜索的时候,发现了SortField.BYTE 但是在建索引的时候NumericField并没有setByteValue,只有(int/ long / folat /double),很是奇怪;

逛了一些论坛,也没见啥好的解释;后来看到了

NumericUtils

的解释,很有意思,

http://lucene.apache.org/core/old_versioned_docs/versions/2_9_0/api/all/org/apache/lucene/util/NumericUtils.html#doubleToSortableLong%28double%29

public final class NumericUtilsextends Object


This is a helper class to generate prefix-encoded representations for numerical values and supplies converters to represent float/double values as sortable integers/longs.

To quickly execute range queries in Apache Lucene, a range is divided recursively into multiple intervals for searching: The center of the range is searched only with the lowest possible precision in the trie, while the boundaries are matched more exactly.
This reduces the number of terms dramatically.

首先解释下prefix-encoded ,前缀编码,解释下,网上看到的解释,见下

A{1。01。000。001}
B{1。01。011。010}
C{0。10。110。11}
D{0。1。00。11}


选A
B中01是011和010的前缀
C中11是110的前缀
D中1是11的前缀,0是00的前缀


前缀码:给定一个序列的集合,若不存在一个序列是另一个序列的前缀,则该序列集合称为前缀码。

那么我可以理解为范围查找使用prefix-encoded是提高性能的一种办法;

范围搜索使用方式

TermRangeQuery query =new TermRangeQuery("size",NumericUtils.longToPrefixCoded(100),NumericUtils.longToPrefixCoded(500)


但是回到文章开始SortField.BYTE到底在哪里使用,现在还是无解,有知道的可以告诉我下,谢谢。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: