- 浏览: 759206 次
- 性别:
- 来自: 杭州
-
文章分类
最新评论
-
lgh1992314:
a offset: 26b offset: 24c offse ...
java jvm字节占用空间分析 -
ls0609:
语音实现在线听书http://blog.csdn.net/ls ...
Android 语音输入API使用 -
wangli61289:
http://viralpatel-net-tutorials ...
Android 语音输入API使用 -
zxjlwt:
学习了素人派http://surenpi.com
velocity宏加载顺序 -
tt5753:
谢啦........
Lucene的IndexWriter初始化时的LockObtainFailedException的解决方法
lucene的评分机制:所有hits的分数<=1.0
每个document(d)的分数:
∑tf(t in d)*idf(t)*boost(t.field in d)*lengthNorm(t.field in d)
t In q
查询的得分:
score(q,d)=coord(q,d)·queryNorm(q)·∑tf(t in d)*idf(t)*boost(t.field in d)*lengthNorm(t.field in d)
t In q
tf(t in d):文档中d出现搜索项t的频率
idf(t):搜索项t在倒排文档中出现的频率
boost(t.field in d):域的加权因子,在插入文档中设置
lengthNorm(t.field in d):域的标准化值,即在某一域中所有项的个数。通常在索引时计算该值并存储到索引文件中。
coord(q,d):协调因子(normalization value),该因子的值基于文档中包含查询项的个数
queryNorm(q):每个查询的标准化值,指每个查询项的权重的平方和
query对象的加权因子,查询时如果是多个子句,则可以通过加权某一个查询子句来加权某一个query对象。
DefaultSimilarity.java默认处理计分规则/** Expert: Default scoring implementation. */
public class DefaultSimilarity extends Similarity { /** Implemented as * <code>state.getBoost()*lengthNorm(numTerms)</code>, where * <code>numTerms</code> is {@link FieldInvertState#getLength()} if {@link * #setDiscountOverlaps} is false, else it's {@link * FieldInvertState#getLength()} - {@link * FieldInvertState#getNumOverlap()}. * * @lucene.experimental */ @Override public float computeNorm(String field, FieldInvertState state) { final int numTerms; if (discountOverlaps) numTerms = state.getLength() - state.getNumOverlap(); else numTerms = state.getLength(); return state.getBoost() * ((float) (1.0 / Math.sqrt(numTerms))); } /** Implemented as <code>1/sqrt(sumOfSquaredWeights)</code>. */ @Override public float queryNorm(float sumOfSquaredWeights) { return (float)(1.0 / Math.sqrt(sumOfSquaredWeights)); } /** Implemented as <code>sqrt(freq)</code>. */ @Override public float tf(float freq) { return (float)Math.sqrt(freq); } /** Implemented as <code>1 / (distance + 1)</code>. */ @Override public float sloppyFreq(int distance) { return 1.0f / (distance + 1); } /** Implemented as <code>log(numDocs/(docFreq+1)) + 1</code>. */ @Override public float idf(int docFreq, int numDocs) { return (float)(Math.log(numDocs/(double)(docFreq+1)) + 1.0); } /** Implemented as <code>overlap / maxOverlap</code>. */ @Override public float coord(int overlap, int maxOverlap) { return overlap / (float)maxOverlap; } // Default true protected boolean discountOverlaps = true; /** Determines whether overlap tokens (Tokens with * 0 position increment) are ignored when computing * norm. By default this is true, meaning overlap * tokens do not count when computing norms. * * @lucene.experimental * * @see #computeNorm */ public void setDiscountOverlaps(boolean v) { discountOverlaps = v; } /** @see #setDiscountOverlaps */ public boolean getDiscountOverlaps() { return discountOverlaps; } }
IndexSearcher.java的explain方法返回的Explanation对象包含了所有评分因子中各个因子的详细信息。
测试程序和数据参考http://zhwj184.iteye.com/admin/blogs/1522709
import java.io.File; import java.io.IOException; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.index.IndexReader; import org.apache.lucene.queryParser.ParseException; import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.search.Explanation; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Version; public class DocSearch { private static IndexSearcher isearcher = null; public static void search(String key) throws IOException, ParseException{ Directory directory = FSDirectory.open(new File("E:\\output\\lucence\\index")); // Now search the index: IndexReader ireader = IndexReader.open(directory); // read-only=true isearcher = new IndexSearcher(ireader); // Parse a simple query that searches for "text": Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT); QueryParser parser = new QueryParser(Version.LUCENE_CURRENT,"context", analyzer); Query query = parser.parse(key); ScoreDoc[] hits = isearcher.search(query, null, 1000).scoreDocs; // Iterate through the results: for (int i = 0; i < hits.length; i++) { Document hitDoc = isearcher.doc(hits[i].doc); System.out.println(hitDoc.getValues("id")[0] + "\t" + hitDoc.getValues("context")[0] + "\t" + hits[i].score); Explanation explan = isearcher.explain(query, hits[i].doc); System.out.println(explan); } } public static void main(String[] args) throws IOException, ParseException { search("旧水泥袋"); isearcher.close(); } }
输出结果:
只截取第一篇文档的评分信息
4801857 采购旧编织袋、旧水泥袋 4.0172114 4.0172114 = (MATCH) sum of: 1.4140004 = (MATCH) weight(context:旧 in 1682), product of: 0.54585564 = queryWeight(context:旧), product of: 5.861472 = idf(docFreq=13, maxDocs=1809) 0.09312603 = queryNorm 2.5904293 = (MATCH) fieldWeight(context:旧 in 1682), product of: 1.4142135 = tf(termFreq(context:旧)=2) 5.861472 = idf(docFreq=13, maxDocs=1809) 0.3125 = fieldNorm(field=context, doc=1682) 0.60229266 = (MATCH) weight(context:水 in 1682), product of: 0.42365694 = queryWeight(context:水), product of: 4.549286 = idf(docFreq=51, maxDocs=1809) 0.09312603 = queryNorm 1.4216518 = (MATCH) fieldWeight(context:水 in 1682), product of: 1.0 = tf(termFreq(context:水)=1) 4.549286 = idf(docFreq=51, maxDocs=1809) 0.3125 = fieldNorm(field=context, doc=1682) 1.1562659 = (MATCH) weight(context:泥 in 1682), product of: 0.58700174 = queryWeight(context:泥), product of: 6.3033047 = idf(docFreq=8, maxDocs=1809) 0.09312603 = queryNorm 1.9697827 = (MATCH) fieldWeight(context:泥 in 1682), product of: 1.0 = tf(termFreq(context:泥)=1) 6.3033047 = idf(docFreq=8, maxDocs=1809) 0.3125 = fieldNorm(field=context, doc=1682) 0.84465253 = (MATCH) weight(context:袋 in 1682), product of: 0.42188305 = queryWeight(context:袋), product of: 4.5302377 = idf(docFreq=52, maxDocs=1809) 0.09312603 = queryNorm 2.0021012 = (MATCH) fieldWeight(context:袋 in 1682), product of: 1.4142135 = tf(termFreq(context:袋)=2) 4.5302377 = idf(docFreq=52, maxDocs=1809) 0.3125 = fieldNorm(field=context, doc=1682)
发表评论
-
对字符串进行验证之前先进行规范化
2013-09-17 23:18 13968对字符串进行验证之前先进行规范化 应用系统中经常对字 ... -
使用telnet连接到基于spring的应用上执行容器中的bean的任意方法
2013-08-08 09:17 1495使用telnet连接到基于spring的应用上执行容器中 ... -
jdk7和8的一些新特性介绍
2013-07-06 16:07 10124更多ppt内容请查看:htt ... -
Lucene的IndexWriter初始化时的LockObtainFailedException的解决方法
2013-06-28 21:35 11829原文链接: http://www.javaarch.net ... -
java对于接口和抽象类的代理实现,不需要有具体实现类
2013-06-12 09:50 2966原文链接:http://www.javaarch.net/j ... -
Excel2007格式分析和XML解析
2013-06-07 09:56 10764在物料清单采购中,用到excel上传文件解析功能,不 ... -
Java EE 7中对WebSocket 1.0的支持
2013-06-05 09:27 3854原文链接:http://www.javaarch.n ... -
java QRCode生成示例
2013-06-05 09:26 1522原文链接:http://www.javaarch.n ... -
Spring Security Logout
2013-06-03 00:05 2381原文地址:http://www.javaarch.net/ ... -
Spring Security Basic Authentication
2013-06-03 00:04 1752原文地址:http://www.javaarch.net/ ... -
Spring Security Form Login
2013-06-02 16:16 2157原文地址:http://www.javaarch.net/j ... -
spring3 的restful API RequestMapping介绍
2013-06-02 14:53 1164原文链接:http://www.javaarch.net/j ... -
Java Web使用swfobject调用flex图表
2013-05-28 19:05 1137Java Web使用swfobject调用 ... -
spring使用PropertyPlaceholderConfigurer扩展来满足不同环境的参数配置
2013-05-21 15:57 3350spring使用PropertyPlaceholderCon ... -
java国际化
2013-05-20 20:57 4484java国际化 本文来自:http://www.j ... -
RSS feeds with Java
2013-05-20 20:52 1237RSS feeds with Java 原文来自:htt ... -
使用ibatis将数据库从oracle迁移到mysql的几个修改点
2013-04-29 10:40 1688我们项目在公司的大战略下需要从oracle ... -
线上机器jvm dump分析脚本
2013-04-19 10:48 2918#!/bin/sh DUMP_PIDS=`p ... -
spring3学习入门示例工程
2013-04-18 09:28 11411. github地址 https://github ... -
spring map使用annotation泛型注入问题分析
2013-04-15 13:30 8557今天在整一个spring的ioc学习demo,碰到 ...
相关推荐
6. **多线程支持**:Lucene 3.6.0支持多线程索引和查询,通过适当的同步机制保证了并发环境下的正确性。 7. **JAR文件**:Lucene 3.6.0的发布包含了一系列JAR文件,如core库、示例程序、测试工具等,方便开发者直接...
6. 更新管理:优化了索引更新机制,支持实时索引,允许在不关闭索引的情况下进行文档的添加、删除和修改。 7. API改进:提供更加稳定和易于使用的API,简化了开发者的工作流程。 三、Lucene的应用场景 Lucene广泛...
lucene-core-3.6.0-sources 绝对可用
lucene-3.6.0 api 手册, 最新的 , lucene 是个好东东, 一直在用, 之前还在使用3.1的,发现已经到3.6了, 落后啊
包含翻译后的API文档:lucene-core-7.2.1-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.apache.lucene:lucene-core:7.2.1; 标签:apache、lucene、core、中文文档、jar包、java; 使用方法:解压翻译后的API...
**Lucene技术文档doc** **一、Lucene简介** Lucene是Apache软件基金会下的Jakarta项目组的一个核心项目,它是一款高性能、可扩展的全文检索引擎库。作为一个开源的Java库,Lucene提供了完整的搜索功能,包括索引、...
lucene-core-3.6.0.jar,很好,很实用的一个包
3. 相关性(Relevance):Lucene使用TF-IDF(词频-逆文档频率)算法计算文档与查询的相关性,确定搜索结果的排名。 四、扩展与优化 1. 分布式搜索(Solr):Apache Solr基于Lucene,提供分布式、集群化搜索解决...
搜索则是通过查询解析和评分机制来定位匹配的文档,而结果排序则依据相关性来确定返回给用户的顺序。 2. **API详解** 在Lucene 4.6.0中,主要API包括Analyzer、IndexWriter、Directory、QueryParser、Searcher等。...
本篇文章将围绕"Lucene-2.0学习文档"的主题,结合Indexer.java、MyScoreDocComparator.java和MySortComparatorSource.java这三个关键文件,深入探讨Lucene的核心概念和实际应用。 首先,我们来看`Indexer.java`。这...
《Lucene帮助文档详解》 Lucene是一款强大的全文搜索引擎库,由Apache软件基金会开发并维护。这个名为“lucene帮助文档.chm”的压缩包文件,包含了一份详尽的Lucene使用指南,通常以CHM(Microsoft Compiled ...
包含翻译后的API文档:lucene-core-7.7.0-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.apache.lucene:lucene-core:7.7.0; 标签:apache、lucene、core、中文文档、jar包、java; 使用方法:解压翻译后的API...
在本安装文档中,我们将详细介绍如何一步步地安装并配置WebLucene,以便于你能够快速地将它集成到你的项目中。 首先,我们需要了解安装WebLucene所需的环境。WebLucene基于Java,因此确保你的系统已经安装了Java ...
Lucene提供了缓存机制,如字段缓存(FieldCache)和术语缓存(Term Dictionary Cache),以减少磁盘I/O,提升检索速度。另外,通过设置合适的相关度评分算法(如TF-IDF)和使用过滤器(Filter)可以进一步优化搜索...
在这个使用案例中,我们将深入探讨如何利用Lucene实现对Word文档中的关键字检索并高亮显示结果。 首先,我们需要理解Lucene的基本工作原理。Lucene通过建立倒排索引(Inverted Index)来加速查询。倒排索引是一种...
- **lucene-core-3.6.0-javadoc.jar**:这个文件包含了Lucene 3.6.0核心组件的API文档,是开发者理解和使用Lucene的重要参考资料。它详细解释了每个类、接口和方法的功能和用法,便于查阅和学习。 - **lucene-test-...
Lucene 提供了索引和搜索文本的基本工具,包括分词、建立倒排索引、查询解析和评分机制等。 **安装与配置** 安装 Lucene 非常简单,只需要将对应的 JAR 包添加到项目依赖中。在 Maven 项目中,可以在 pom.xml 文件...
**Lucene电子文档搜索** Lucene是一个开源的全文搜索引擎库,由Apache软件基金会开发并维护。它提供了高级的文本分析和索引功能,使得开发者能够快速地在大量数据中实现高效的搜索功能。Lucene.Net是Lucene的一个...
6. **缓存(Caching)**: 为了提高搜索性能,Lucene 引入了多种缓存机制,如 DocValues 缓存、Filter 缓存等。 **应用场景** Lucene 应用于各种需要全文搜索的场合,如内容管理系统、知识库、论坛、电子商务网站、...