gpt4 book ai didi

python - Lucene:返回短语文档出现的最快方法?

转载 作者:太空宇宙 更新时间:2023-11-03 13:53:22 24 4
gpt4 key购买 nike

我正在尝试使用 Lucene(实际上是 PyLucene!)来找出有多少文档包含我的确切短语。我的代码目前看起来像这样......但它运行得相当慢。有谁知道返回文档计数的更快方法吗?

phraseList = ["some phrase 1", "some phrase 2"] #etc, a list of phrases...

countsearcher = IndexSearcher(SimpleFSDirectory(File(STORE_DIR)), True)
analyzer = StandardAnalyzer(Version.LUCENE_CURRENT)

for phrase in phraseList:
query = QueryParser(Version.LUCENE_CURRENT, "contents", analyzer).parse("\"" + phrase + "\"")
scoreDocs = countsearcher.search(query, 200).scoreDocs
print "count is: " + str(len(scoreDocs))

最佳答案

通常,编写自定义命中收集器是使用位集计算命中数的最快方法,如 Collector 的 javadoc 中所示。 .

另一种方法是获取 TopDocs 并将结果数指定为一个。

TopDocs topDocs = searcher.search(query, filter, 1);

topDocs.totalHits 将为您提供结果总数。我不确定这是否与计算分数一样快,这在上述方法中被跳过。

这些解决方案适用于 Java。您必须检查 Python 中的等效技术。

关于python - Lucene:返回短语文档出现的最快方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2796660/

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