0

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

4

2 回答 2

0

我从未与 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");
于 2011-03-10T11:41:00.583 回答
0

您不能在客户端使用 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约翰内斯

于 2013-03-08T16:59:56.033 回答