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

21 篇文章 0 订阅

原先在处理范围搜索的时候,发现了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 NumericUtils
   
   
    
    extends 
    
    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到底在哪里使用,现在还是无解,有知道的可以告诉我下,谢谢。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值