3

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

4

1 回答 1

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
}
于 2011-10-05T07:00:58.620 回答