LuceneInAction-explain()理解搜索结果评分
来源:互联网 发布:mirna数据库 编辑:程序博客网 时间:2024/06/05 15:52
Explainer.java
import org.apache.lucene.analysis.SimpleAnalyzer;import org.apache.lucene.document.Document;import org.apache.lucene.queryParser.QueryParser;import org.apache.lucene.search.Explanation;import org.apache.lucene.search.TopDocs;import org.apache.lucene.search.ScoreDoc;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.Query;import org.apache.lucene.store.FSDirectory;import org.apache.lucene.store.Directory;import org.apache.lucene.util.Version;import java.io.File;// From chapter 3public class Explainer { public static void main(String[] args) throws Exception { String indexDir = "indexes/MeetLucene"; String queryExpression = "apache"; Directory directory = FSDirectory.open(new File(indexDir)); QueryParser parser = new QueryParser(Version.LUCENE_30, "contents", new SimpleAnalyzer()); Query query = parser.parse(queryExpression); System.out.println("Query: " + queryExpression); IndexSearcher searcher = new IndexSearcher(directory); TopDocs topDocs = searcher.search(query, 10); for (ScoreDoc match : topDocs.scoreDocs) { Explanation explanation = searcher.explain(query, match.doc); //#A System.out.println("----------"); Document doc = searcher.doc(match.doc); System.out.println(doc.get("filename")); System.out.println(explanation.toString()); //#B } searcher.close(); directory.close(); }}/*#A Generate Explanation#B Output Explanation*/
结果:
Query: apache----------apache1.0.txt0.5776299 = (MATCH) fieldWeight(contents:apache in 0), product of: 3.8729835 = tf(termFreq(contents:apache)=15) 2.3862944 = idf(docFreq=3, maxDocs=16) 0.0625 = fieldNorm(field=contents, doc=0)----------apache1.1.txt0.49465272 = (MATCH) fieldWeight(contents:apache in 1), product of: 3.3166249 = tf(termFreq(contents:apache)=11) 2.3862944 = idf(docFreq=3, maxDocs=16) 0.0625 = fieldNorm(field=contents, doc=1)----------apache2.0.txt0.13050047 = (MATCH) fieldWeight(contents:apache in 2), product of: 2.0 = tf(termFreq(contents:apache)=4) 2.3862944 = idf(docFreq=3, maxDocs=16) 0.02734375 = fieldNorm(field=contents, doc=2)
0 0
- LuceneInAction-explain()理解搜索结果评分
- LuceneInAction-理解索引和搜索过程的核心类
- LuceneInAction-近实时搜索
- LuceneInAction-实现简单的搜索功能
- MySQL explain结果详解
- mysql explain 结果解释
- 评分制搜索文章
- mysql explain 结果释义梗概
- oracle explain plan结果简介
- EXPLAIN 的理解
- LuceneInAction(第2版)学习笔记——第三章 为应用程序添加搜索功能
- LuceneInAction(第2版)学习笔记——第五章 高级搜索技术
- 小程序展示评分结果合评分功能
- explain select ....结果中各字段含义
- explain一条HiveSQL,分析这个结果
- MySQL Explain 结果解读与实践
- MySQL explain query 结果域值含义
- mysql explain用法和结果的含义
- Linux内核-内存-伙伴系统算法
- java:多线程的使用(一)
- PAT-1001. A+B Format (20)
- JAVA获取某个类加载路径
- 数据库SQL解析执行过程
- LuceneInAction-explain()理解搜索结果评分
- mybatis反向工程生成插件使用
- PTC与Unity宣布战略合作-借助Vuforia加快增强现实开发
- 嵌套评论的数据库表设计(路径枚举)
- 超自然的箭头函数学习初步
- 122. Best Time to Buy and Sell Stock II [LeetCode]
- 深入研究Servlet线程安全性问题
- 2016年总结2017年计划
- 【原】ORACLE安装时,先决条件检查失败