Katta docId to Document

284 Views Asked by At

How to use FieldCache in Katta, FieldCache expects IndexReader as arguments, then how to get IndexReader from Katta API. And In katta the search method in LuceneClient.java returns Hits. From this I can get List, from that I can able to get each hit's docId, but I need particular field value of the docId in Katta. Please give me some coding example.

2

There are 2 best solutions below

4
On

I've never worked with Katta, I worked with Solr and if I had to get document by its id and I had to use only Lucene classes, I'd use 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");
0
On

you can't use the FieldCache on client side, since the IndexReader is located on the server side! But you can get field-values through the getDetails() method on LuceneClient.

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 Johannes