如何找到类似的文件 [英] How to find similar documents

查看:79
本文介绍了如何找到类似的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何在Lucene中找到给定文档的类似文档。我不知道文字是什么,我只知道文件是什么。有没有办法在lucene中找到类似的文件。我是新手,所以我可能需要一些手。

解决方案

您可能需要检查lucene的MoreLikeThis功能。

MoreLikeThis根据文档中的术语构建lucene查询,以查找索引中的其他类似文档。

/java/3_0_1/api/contrib-queries/org/apache/lucene/search/similar/MoreLikeThis.html\">http://lucene.apache.org/java/3_0_1/api/contrib-queries/org/apache/ lucene / search / similar / MoreLikeThis.html



示例代码示例(java参考) -

  MoreLikeThis mlt = new MoreLikeThis(reader); //通过索引阅读器
mlt.setFieldNames(new String [] {title,author}); //指定相似的字段

Query query = mlt.like(docID); //传递文档ID
TopDocs similarDocs = searcher.search(query,10); //使用搜索者
if(similarDocs.totalHits == 0)
//处理
}


How do you find a similar documents of a given document in Lucene. I do not know what the text is i only know what the document is. Is there a way to find similar documents in lucene. I am a newbie so I may need some hand holding.

解决方案

you may want to check the MoreLikeThis feature of lucene.

MoreLikeThis constructs a lucene query based on terms within a document to find other similar documents in the index.

http://lucene.apache.org/java/3_0_1/api/contrib-queries/org/apache/lucene/search/similar/MoreLikeThis.html

Sample code example (java reference) -

MoreLikeThis mlt = new MoreLikeThis(reader); // Pass the index reader
mlt.setFieldNames(new String[] {"title", "author"}); // specify the fields for similiarity

Query query = mlt.like(docID); // Pass the doc id 
TopDocs similarDocs = searcher.search(query, 10); // Use the searcher
if (similarDocs.totalHits == 0)
    // Do handling
}

这篇关于如何找到类似的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆