【问题标题】:Get field's tokens from lucene index从 lucene 索引中获取字段的标记
【发布时间】:2012-03-19 20:39:37
【问题描述】:

如何从 lucene 索引中获取用于 Document 内的 Field 的令牌(无论是令牌列表、TokenStream 还是其他东西)?也就是说,是否可以从索引中获取tokens(来自示例)中使用的令牌? (我不知道如何从TokenStream 中获取令牌)

doc.add(new Field("title", tokens))

在文档中有Field.tokenStreamValue(),但是当我执行doc.getFieldable(field_name) 时,它只会返回null

我也试过(来自lucene - Fieldable.tokenStreamValue() 的第三条评论):

TokenSources.getTokenStream(reader, doc_id, field_name)

但我明白了

java.lang.IllegalArgumentException: title in doc #630does not have any term position data stored
    at org.apache.lucene.search.highlight.TokenSources.getTokenStream(TokenSources.java:256)

【问题讨论】:

    标签: search lucene full-text-search pylucene


    【解决方案1】:

    TokenSources 类是一个辅助类,用于检索文档的标记以进行高亮显示。有两种方法可以检索给定文档的术语:

    • 重新分析存储的字段,
    • 读取文档的术语向量。

    您想使用 tries to read the document's terms vector 的方法,但由于您在索引时没有启用术语向量而失败。

    因此,您可以在索引时启用术语向量并继续使用此方法(请参阅Field constructorField.TermVector 的文档)或重新分析存储字段的内容。第一种方法可能会提供更好的性能,尤其是对于大型字段,而第二种方法将节省空间(如果您的字段已存储,则无需存储其他信息)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-23
      • 2017-01-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多