【问题标题】:Katta docId to DocumentKatta docId 到文档
【发布时间】:2011-03-10 06:59:32
【问题描述】:

如何在 Katta 中使用 FieldCache,FieldCache 需要 IndexReader 作为参数,然后如何从 Katta API 获取 IndexReader。而在 katta 中,LuceneClient.java 中的搜索方法返回 Hits。 从这里我可以得到列表,从中我可以得到每个命中的 docId,但我需要 Katta 中 docId 的特定字段值。请给我一些编码示例。

【问题讨论】:

    标签: lucene katta


    【解决方案1】:

    我从未使用过 Katta,我使用过 Solr,如果我必须通过其 id 获取文档并且我必须只使用 Lucene 类,我会使用 org.apache.lucene.search.IndexSearcher

    // when you figure out how to get IndexReader using Katta API, you'll be able to get the searcher
    IndexSearcher searcher = new IndexSearcher(indexReader);
    org.apache.lucene.document.Document doc = searcher.doc(docId);
    String yourFieldValue = doc.get("yourFieldName");
    

    【讨论】:

    • 感谢您回答 mbonaci,但实际上在我的问题本身中我提到我无法找到它...
    • 我想,通过这样说:我可以获取每个命中的 docId,但我需要 docId 的特定字段值你不知道如何获取字段如果您有 docId,则为值。顺便说一句,我不想​​粗鲁,但我注意到您以错误的方式使用 canable。你要么说你不能做某事,要么不能做某事。这两个不好相处:)
    • 卡塔不是和卢坎德拉很像吗?我的意思是 Katta 中也必须有某种目录抽象。
    • 我不确定这是否会有所帮助,但这是Katta thread in Solr。当然还有这个Solr Wiki Katta link
    【解决方案2】:

    您不能在客户端使用 FieldCache,因为 IndexReader 位于服务器端! 但是您可以通过 LuceneClient 上的 getDetails() 方法获取字段值。

    final Hits hits = client.search(query, new String[] { INDEX_NAME }, 10);
    for (final Hit hit : hits.getHits()) {
      final MapWritable details = client.getDetails(hit, new String[] { "path" });
      details.get(new Text("path"));
    

    HTH 约翰内斯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-22
      • 1970-01-01
      • 2022-01-22
      • 2012-12-31
      • 1970-01-01
      • 2011-11-28
      • 1970-01-01
      相关资源
      最近更新 更多