2011-03-10 40 views
0

如何在Katta中使用FieldCache,FieldCache需要IndexReader作爲參數,然後如何從Katta API獲取IndexReader。在katta中,LuceneClient.java中的搜索方法返回Hits。 從這我可以得到列表,從我可以得到每個命中的docId,但我需要在Katta docId的特定字段值。請給我一些編碼示例。Katta docId到文檔

回答

0

我從來沒有與凱塔的工作,我曾與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"); 
+0

感謝你回答mbonaci,但實際上在我的問題本身我提到我不能找到它...... – Nageswaran 2011-03-10 12:41:03

+0

我想,通過這樣說:_I能能以獲得每個命中的docId,但是我需要docId_的特定字段值,如果您有docId,則不知道如何獲取字段值。順便說一句,我不想​​粗魯,但我注意到你以錯誤的方式使用_can_和_able_。你要麼說你不能做某件事,或者不能做某件事。這兩個人不會很好:) – 2011-03-10 12:57:13

+0

是不是Katta類似於Lucandra?我的意思是在Katta也必須有某種目錄抽象。 – 2011-03-10 13:10:54

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 約翰內斯