【转】lucene4 VSM的变动情况参考

简介: 假期重新把之前在新浪博客里面的文字梳理了下,搬到这里

New Lucene 4 Functions Improve Enterprise Search Indexing

原文链接http://java.dzone.com/articles/new-index-statistics-lucene-40

In the past, Lucene recorded only the bare minimal aggregate index statistics necessary to support its hard-wiredclassic vector space scoring model.

Fortunately, this situation iswildly improved in trunk(to be 4.0), where wehave a selection of modern scoring models, includingOkapi BM25,Language models,Divergence from Randomness modelsandInformation-based models. To support these, we now save a number of commonly used index statistics per index segment, and make them available at search time.

To understand the new statistics, let's pretend we've indexed the following two example documents, each with only one field "title":

·      document 1: The Lion, the Witch, and the Wardrobe

·      document 2: The Da Vinci Code

Assume we tokenize on whitespace, commas are removed, all terms are downcased and we don't discard stop-words. Here are the statistics Lucene tracks:

   TermsEnum.docFreq()

How many documents contain at least one occurrence of the term in the field; 3.x indices also save this (TermEnum.docFreq()). For term "lion" docFreq is 1, and for term "the" it's 2.

 

   Terms.getSumDocFreq()

Number of postings, i.e. sum of TermsEnum.docFreq() across all terms in the field. For our example documents this is 9.

 

   TermsEnum.totalTermFreq()

Number of occurrences of this term in the field, across all documents. For term "the" it's 4, for term "vinci" it's 1.

 

   Terms.getSumTotalTermFreq()

Number of term occurrences in the field, across all documents; this is the sum of TermsEnum.totalTermFreq() across all unique terms in the field. For our example documents this is 11.

 

   Terms.getDocCount()

How many documents have at least one term for this field. In our example documents, this is 2, but if for example one of the documents was missing the title field, it would be 1.

 

   Terms.getUniqueTermCount()

How many unique terms were seen in this field. For our example documents this is 8. Note that this statistic is of limited utility for scoring, because it's only available per-segment and you cannot (efficiently!) compute this across all segments in the index (unless there is only one segment).

 

   Fields.getUniqueTermCount()

Number of unique terms across all fields; this is the sum of Terms.getUniqueTermCount() across all fields. In our example documents this is 8. Note that this is also only available per-segment.

 

   Fields.getUniqueFieldCount()

Number of unique fields. For our example documents this is 1; if we also had a body field and an abstract field, it would be 3. Note that this is also only available per-segment.



3.x indices only store TermsEnum.docFreq(), so if you want to experiment with the new scoring models in Lucene 4.0, you should either re-index or upgrade your index using IndexUpgrader. Note that the new scoring models all use the same single-byte norms format, so you can freely switch between them without re-indexing.

In addition to what's stored in the index, there are also these statistics available per-field, per-document while indexing, in the FieldInvertState passed to Similarity.computeNorm method for both 3.x and 4.0:


   length

How many tokens in the document. For document 1 it's 7; for document 2 it's 4.

 

   uniqueTermCount

For this field in this document, how many unique terms are there? For document 1, it's 5; for document 2 it's 4.

 

   maxTermFrequency

What was the count for the most frequent term in this document. For document 1 it's 3 ("the" occurs 3 times); for document 2 it's 1.



In 3.x, if you want to consume these indexing-time statistics, you'll have to save them away yourself (e.g., somehow encoding them into the single-byte norm value). However, since 4.0 uses
doc valuesfor norms, you have more freedom to encode these statistics however you'd like. Your custom similarity can then pull from these.

From these available statistics you're now free to derive other commonly used statistics:

·      Average document length is Terms.getSumTotalTermFreq() divided by Terms.getDocCount().

·      Average within-document term frequency is FieldInvertState.length divided by FieldInvertState.uniqueTermCount.

·      Average document length across the collection is Terms.getSumTotalTermFreq() divided by maxDoc (or Terms.getDocCount(), if not all documents have the field).

·      Average number of unique terms per document is Terms.getSumDocFreq() divided by maxDoc (or Terms.getDocCount(field), if not all documents have the field).

Remember that the statistics do not reflect deleted documents, until those documents are merged away; in general this also means that segment merging will alter scores! Similarly, if the field omits term frequencies, then the statistics will not be correct (though they will still be consistent with one another: we will pretend each term occurred once per document).

Published at DZone with permission ofMichael Mccandless, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, In

目录
相关文章
|
Shell
Mac终端工具Terminal (2):打开新终端窗口或者页签
Mac终端工具Terminal (2):打开新终端窗口或者页签
2119 0
|
SQL 弹性计算 安全
购买阿里云活动内云服务器之后设置密码、安全组、增加带宽、挂载云盘教程
当我们通过阿里云的活动购买完云服务器之后,并不是立马就能使用了,还需要我们设置云服务器密码,配置安全组等基本操作之后才能使用,有的用户还需要购买并挂载数据盘到云服务器上,很多新手用户由于是初次使用阿里云服务器,因此并不知道这些设置的操作流程,下面给大家介绍下这些设置的具体操作流程。
购买阿里云活动内云服务器之后设置密码、安全组、增加带宽、挂载云盘教程
|
数据采集 NoSQL Redis
Python爬虫-代理池原理和搭建
代理池架构,代理池的实现
845 0
|
11月前
|
弹性计算 安全 Linux
2026年新手小白租用阿里云服务器全流程步骤(手把手教程)
对于首次接触云服务器的新手来说,租用流程可能略显复杂。以阿里云为例,其提供多种服务器类型与配置选项,适配不同需求。下面用通俗语言拆解从注册到完成租用的全步骤,结合最新配置细节与价格参考,帮助快速拥有专属云服务器。
|
12月前
|
人工智能 运维 安全
SOC 2.0 来了:不是加人加班,而是加“智能”!——智能化安全运营中心的建设之道
SOC 2.0 来了:不是加人加班,而是加“智能”!——智能化安全运营中心的建设之道
725 15
|
5月前
|
人工智能 弹性计算 关系型数据库
阿里云解决方案免费试用活动解析,免费领取100试用点,便于客户完成 POC 验证
阿里云全新上线解决方案免费试用活动,用户实名认证后可免费领取100试用点,每完成1个解决方案试用还可额外获得10试用点激励,最高累计领取200试用点,额度有效期1年。活动覆盖27个热门场景方案,涵盖AI智能体部署、大模型调用、数字人生成、多模态内容创作、数据库迁移、图数据分析等方向,最低1试用点/小时起即可体验百炼大模型、函数计算、ECS等云产品组合,帮助开发者和企业零成本完成业务上线前的POC验证,大幅降低AI应用探索门槛。
|
监控 Cloud Native Java
jdk25
JDK 25聚焦夯实基础,推动Java持续进化。以虚拟线程优化、值对象预研为核心,强化并发性能与内存效率;推进字符串模板、未命名变量等新特性落地,提升编码简洁性;增强ZGC、JFR等底层能力,助力云原生与可观测性。虽无颠覆变革,却彰显Java“守正出新”的实用主义哲学,为未来重大升级铺平道路。(238字)
1269 145
|
JSON 前端开发 关系型数据库
如何物业管理(园区式)系统的房屋及设备设施板块?(附架构图+流程图+代码参考)
本文介绍了园区物业管理系统中房屋与设备设施管理的核心内容,涵盖设备信息、巡检、报修、保养四大功能模块,提供系统架构图、数据模型设计、关键实现建议及可落地的代码样例。通过打通资产与运维流程,实现降本增效、减少停机与投诉,助力运维数据化、智能化。
|
网络协议 关系型数据库 应用服务中间件
如何迁移网站数据到新的服务器
迁移网站数据到新服务器是一个系统化的过程,需谨慎操作以避免数据丢失或服务中断。小编为您整理发布如何迁移网站数据到新的服务器,以下是详细步骤和注意事项。
|
12月前
|
机器学习/深度学习 人工智能 算法
基于计算机视觉的鸟类数量统计技术原理解析
在鸟类识别中,大规模、密集鸟群的准确计数极具挑战。传统检测方法(如YOLO)难以应对高密度场景,主流方案转向**目标检测跟踪**与**密度估计**两大路线。前者逐只识别追踪,适用于稀疏场景;后者通过点标注生成密度图,直接回归总数,更高效精准,适合万级鸟群统计。实际应用常结合两者,辅以多尺度拍摄与无人机巡航,实现“总数+物种+行为”综合监测。
713 2