关于TrieField的全面认识、理解、运用

简介: 关于trieField的理解补充下3篇文档,相当的系统、全面!看相关文档连接,不解释。 http://lucene.apache.org/core/old_versioned_docs/versions/3_5_0/api/all/org/apache/lucene/search/NumericR

关于trieField的理解补充下3篇文档,相当的系统、全面!看相关文档连接,不解释。


http://lucene.apache.org/core/old_versioned_docs/versions/3_5_0/api/all/org/apache/lucene/search/NumericRangeQuery.html

http://blog.csdn.net/fancyerii/article/details/7256379

http://hadoopcn.iteye.com/blog/1550402

http://rdc.taobao.com/team/jm/archives/1699

 


 
extends 
MultiTermQuery

A 
Query
 that matches numeric values within a
specified range. To use this, you must first index the numeric
values using 
NumericField
 (expert: 
NumericTokenStream
). If your terms are instead
textual, you should use 
TermRangeQuery
. 
NumericRangeFilter
 is the filter equivalent of
this query.

You create a new NumericRangeQuery with the static factory
methods, eg:

 

matches all documents whose float valued "weight" field ranges
from 0.03 to 0.10, inclusive.

The performance of NumericRangeQuery is much better than the
corresponding 
TermRangeQuery
 because the number of terms that
must be searched is usually far fewer, thanks to trie indexing,
described below.

You can optionally specify a 
precisionStep
 when creating this query. This is
necessary if you've changed this configuration from its default (4)
during indexing. Lower values consume more disk space but speed up
searching. Suitable values are between 1 and 8. A
good starting point to test is 4, which is the default value
for all Numeric* classes. See 
below
 for details.

This query defaults to 
MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT
 for 32 bit
(int/float) ranges with precisionStep ≤8 and 64 bit (long/double)
ranges with precisionStep ≤6. Otherwise it uses 
MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE
 as the number of
terms is likely to be high. With precision steps of ≤4, this query
can be run with one of the BooleanQuery rewrite methods without
changing BooleanQuery's default max clause count.

How it works

See the publication about panFMP, where this algorithm was described
(referred to as TrieRangeQuery):

Schindler, U, Diepenbroek, M, 2008.
Generic XML-based Framework for Metadata Portals.
Computers & Geosciences 34 (12), 1947-1955. doi:10.1016/j.cageo.2008.02.023

A quote from this paper: Because Apache Lucene is a
full-text search engine and not a conventional database, it cannot
handle numerical ranges (e.g., field value is inside user defined
bounds, even dates are numerical values). We have developed an
extension to Apache Lucene that stores the numerical values in a
special string-encoded format with variable precision (all
numerical values like doubles, longs, floats, and ints are
converted to lexicographic sortable string representations and
stored with different precisions (for a more detailed description
of how the values are stored, see 
NumericUtils
). A range is then 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.

For the variant that stores long values in 8 different
precisions (each reduced by 8 bits) that uses a lowest precision of
1 byte, the index contains only a maximum of 256 distinct values in
the lowest precision. Overall, a range could consist of a
theoretical maximum of 7*255*2 + 255 = 3825 distinct
terms (when there is a term for every distinct value of an
8-byte-number in the index and the range covers almost all of them;
a maximum of 255 distinct values is used because it would always be
possible to reduce the full 256 values to one term with degraded
precision). In practice, we have seen up to 300 terms in most cases
(index with 500,000 metadata records and a uniform value
distribution).

Precision
Step

You can choose any precisionStep when encoding
values. Lower step values mean more precisions and so more terms in
index (and index gets larger). On the other hand, the maximum
number of terms to match reduces, which optimized query speed. The
formula to calculate the maximum term count is:

 

(this formula is only correct, when
bitsPerValue/precisionStep is an integer; in other
cases, the value must be rounded up and the last summand must
contain the modulo of the division as precision step)
. For
longs stored using a precision step of 4, n = 15*15*2 + 15 =
465
, and for a precision step of 2, n = 31*3*2 + 3 =
189
. But the faster search speed is reduced by more seeking
in the term enum of the index. Because of this, the ideal
precisionStep value can only be found out by testing.
Important: You can index with a lower precision step value
and test search speed using a multiple of the original step
value.

Good values for precisionStep are depending on
usage and data type:

  • The default for all data types is 4, which is used, when
    no precisionStep is given.
  • Ideal value in most cases for 64 bit data types
    (long, double) is 6 or 8.
  • Ideal value in most cases for 32 bit data types
    (int, float) is 4.
  • For low cardinality fields larger precision steps are good. If
    the cardinality is < 100, it is fair to use 
    Integer.MAX_VALUE
     (see below).
  • Steps ≥64 for long/double and ≥32 for
    int/float produces one token per value in the index and
    querying is as slow as a conventional 
    TermRangeQuery
    . But it can be used to produce
    fields, that are solely used for sorting (in this case simply use

    Integer.MAX_VALUE
     as precisionStep).
    Using 
    NumericFields
     for sorting is ideal, because
    building the field cache is much faster than with text-only
    numbers. These fields have one term per value and therefore also
    work with term enumeration for building distinct lists (e.g. facets
    / preselected values to search for). Sorting is also possible with
    range query optimized fields using one of the above
    precisionSteps.

Comparisons of the different types of RangeQueries on an index
with about 500,000 docs showed that 
TermRangeQuery
 in boolean rewrite mode (with
raised 
BooleanQuery
 clause count) took about 30-40 secs
to complete, 
TermRangeQuery
 in constant score filter rewrite
mode took 5 secs and executing this class took <100ms to
complete (on an Opteron64 machine, Java 1.5, 8 bit precision step).
This query type was developed for a geographic portal, where the
performance for e.g. bounding boxes or exact date/time stamps is
important.

Since:
2.9
See Also:

Serialized Form
相关文章
|
4月前
|
存储 弹性计算 安全
2026年阿里云服务器租用价格:包年、包月、按量付费收费标准与活动价格
阿里云2026年推出多款特惠云服务器,其中经济型e实例2核2G配置99元/年,u1实例2核4G配置199元/年,轻量应用服务器2核2G峰值200M带宽抢购价38元/年。新老用户均可购买99元云服务器,199元云服务器限企业用户。此外,阿里云还提供加99元解锁弹性数据库和高效存储保障的套餐优惠,以及特惠建站套餐和特惠上云套餐。GPU服务器新人专享包月5折起,包年4折起优惠。购买前建议领取优惠券以降低购买成本。
|
存储 SQL 关系型数据库
深入探究InnoDB的MVCC快照机制
本文详细介绍了InnoDB存储引擎中的两种并发控制方法:MVCC(多版本并发控制)和LBCC(基于锁的并发控制)。MVCC通过记录版本信息和使用快照读取机制,实现了高并发下的读写操作,而LBCC则通过加锁机制控制并发访问。文章深入探讨了MVCC的工作原理,包括插入、删除、修改流程及查询过程中的快照读取机制。通过多个案例演示了不同隔离级别下MVCC的具体表现,并解释了事务ID的分配和管理方式。最后,对比了四种隔离级别的性能特点,帮助读者理解如何根据具体需求选择合适的隔离级别以优化数据库性能。
942 5
深入探究InnoDB的MVCC快照机制
|
12月前
|
持续交付 网络安全 数据安全/隐私保护
ios微信双开(免费版)怎么弄的?如何下载
作为一名移动端自动化开发工程师,我曾在多个iOS越狱项目中处理过应用多开需求。本文将
|
12月前
|
数据采集 机器学习/深度学习 边缘计算
Python爬虫动态IP代理报错全解析:从问题定位到实战优化
本文详解爬虫代理设置常见报错场景及解决方案,涵盖IP失效、403封禁、性能瓶颈等问题,提供动态IP代理的12种核心处理方案及完整代码实现,助力提升爬虫系统稳定性。
603 0
html+js+css实现的建筑方块立体数字时钟源码
html+js+css实现的建筑方块立体数字时钟源码
680 33
|
机器学习/深度学习 算法 机器人
强化学习:时间差分(TD)(SARSA算法和Q-Learning算法)(看不懂算我输专栏)——手把手教你入门强化学习(六)
本文介绍了时间差分法(TD)中的两种经典算法:SARSA和Q-Learning。二者均为无模型强化学习方法,通过与环境交互估算动作价值函数。SARSA是On-Policy算法,采用ε-greedy策略进行动作选择和评估;而Q-Learning为Off-Policy算法,评估时选取下一状态中估值最大的动作。相比动态规划和蒙特卡洛方法,TD算法结合了自举更新与样本更新的优势,实现边行动边学习。文章通过生动的例子解释了两者的差异,并提供了伪代码帮助理解。
1160 2
|
Python
Python中键错误(KeyError)
【7月更文挑战第14天】
816 1
|
Shell Linux 开发工具
Vmware 虚拟机挂起恢复后发现无法 Ping 通,无法连接到主机
在Linux主机上,以`root`用户停止NetworkManager服务并重启网络: ```shell systemctl stop NetworkManager systemctl restart network ``` 或修改网卡配置文件`ifcfg-ens33`,添加`NM_CONTROLLED=&quot;no&quot;`,然后重启`network`服务: ```shell vim /etc/sysconfig/network-scripts/ifcfg-ens33 systemctl restart network ```
819 6
|
SQL 存储 关系型数据库
SqlAlchemy 2.0 中文文档(三十四)(1)
SqlAlchemy 2.0 中文文档(三十四)
419 0
|
Web App开发 开发者 iOS开发
新版本浏览器为何无法访问部分本地项目
情况 Chrome 以及Safari 浏览器在最近的自动升级之后,在地址栏输入本地项目地址(simple.app)时,显示: 新版本浏览器无法访问部分本地项目,对开发者有相当大的影响 新版本浏览器无法访问部分本地项目,对开发者有相当大的影响 Chrome 版本为63.0,Safari 的版本为11.0.2。
1390 0

热门文章

最新文章