gpt4 book ai didi

lucene - 如何查找相似文档

转载 作者:行者123 更新时间:2023-12-02 09:25:07 25 4
gpt4 key购买 nike

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

最佳答案

您可能想检查 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
}

关于lucene - 如何查找相似文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7657673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com