【问题标题】:Lucene: Fastest way to return the document occurance of a phrase?Lucene:返回文档出现短语的最快方法是什么?
【发布时间】:2011-02-17 07:22:54
【问题描述】:

我正在尝试使用 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))

【问题讨论】:

    标签: python search lucene


    【解决方案1】:

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

    其他方法是获取TopDocs,结果数指定为1。

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

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

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

    【讨论】:

      猜你喜欢
      • 2016-02-27
      • 1970-01-01
      • 1970-01-01
      • 2013-01-11
      • 1970-01-01
      • 2013-10-03
      • 1970-01-01
      • 2012-12-18
      • 1970-01-01
      相关资源
      最近更新 更多