如何找到类似的文件

Luk*_*101 3 lucene full-text-search morelikethis

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

Jay*_*dra 9

你可能想检查一下lucene的MoreLikeThis功能.

MoreLikeThis基于文档中的术语构造lucene查询,以在索引中查找其他类似文档.

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

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

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
}
Run Code Online (Sandbox Code Playgroud)