《Lucene in Action》 MoreLikeThis 实例
2011-12-07 10:56
375 查看
《Lucene in Action》第二版中对MoreLikeThis 介绍的例子,搜索类似的书籍,代码如下,供大家学习参考:
引用请注明:【爱开卷360】《Lucene in Action》 MoreLikeThis 实例
public class BooksMoreLikeThis { public static void main(String[] args) throws Throwable { String indexDir = System.getProperty("index.dir"); FSDirectory directory = FSDirectory.open(new File(indexDir)); IndexReader reader = IndexReader.open(directory); IndexSearcher searcher = new IndexSearcher(reader); int numDocs = reader.maxDoc(); MoreLikeThis mlt = new MoreLikeThis(reader); mlt.setFieldNames(new String[] {"title", "author"}); mlt.setMinTermFreq(1); //默认值是2,建议自己做限制,否则可能查不出结果 mlt.setMinDocFreq(1); //默认值是5,建议自己做限制,否则可能查不出结果 for (int docID = 0; docID < numDocs; docID++) { System.out.println(); Document doc = reader.document(docID); System.out.println(doc.get("title")); Query query = mlt.like(docID); System.out.println(" query=" + query); TopDocs similarDocs = searcher.search(query, 10); if (similarDocs.totalHits == 0) System.out.println(" None like this"); for(int i=0;i<similarDocs.scoreDocs.length;i++) { if (similarDocs.scoreDocs[i].doc != docID) { doc = reader.document(similarDocs.scoreDocs[i].doc); System.out.println(" -> " + doc.getField("title").stringValue()); } } } searcher.close(); reader.close(); directory.close(); } }
引用请注明:【爱开卷360】《Lucene in Action》 MoreLikeThis 实例
相关文章推荐
- 《Lucene in Action》 MoreLikeThis 实例
- Who should read this book?《Lucene in action》——谁应该读这本书?
- [ lucene扩展 ] MoreLikeThis 相似检索
- Lucene相似搜索组件MoreLikeThis原理与代码分析
- 【Lucene】利用MoreLikeThis实现"你可能感兴趣的"搜索
- Lucene中MoreLikeThis查询结果为空
- 资讯的低准确相似文档——Lucene的MoreLikeThis
- solr或lucene中出现there are more terms than documents in field "name", but it's impossible to sort on tokenized fields异常
- 分布式搜索elasticsearch java API 之(八)------使用More like this实现基于内容的推荐
- This version of the rendering library is more recent than your version of ADT plug-in. Please update
- 《Lucene In Action》第四章.Analysis(分词)
- lucene&nbsp;in&nbsp;action&nbsp;第二章(3)(索…
- (原创)《Lucene in Action 2nd Edition》Chapter11.2.2中的工具类SearcherManager翻译为C#版本
- This version of the rendering library is more recent than your version of ADT plug-in. Please update
- This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in问题
- ElasticSearch java API-使用More like this实现基于内容的推荐
- LuceneInAction(第2版)学习笔记——第四章 Lucene的分析过程
- This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in
- This version of the rendering library is more recent than your version of ADT plug-in. Please update
- solr学习之九:MoreLikeThis相似查询