【发布时间】:2014-04-04 11:25:57
【问题描述】:
你好,我正在研究 java,我正在使用 lucene 进行索引。 我在那里存储数据,但如何检查 lucene 数据包含哪些内容?
我尝试用这个来检查 lucene 上的数据。 public static void main(String[] args) 抛出异常 {
File indexDir = new File("/path/to/solr/data/index/");
int hits = 100;
SimpleSearcher searcher = new SimpleSearcher();
searcher.searchIndex(indexDir, args[0], hits);
}
private void searchIndex(File indexDir, String queryStr, int maxHits)
throws Exception {
Directory directory = FSDirectory.open(indexDir);
IndexSearcher searcher = new IndexSearcher(directory);
QueryParser parser = new QueryParser(Version.LUCENE_35,
"title", new SimpleAnalyzer());
Query query = parser.parse(queryStr);
TopDocs topDocs = searcher.search(query, maxHits);
ScoreDoc[] hits = topDocs.scoreDocs;
for (int i = 0; i < hits.length; i++) {
int docId = hits[i].doc;
Document d = searcher.doc(docId);
List<Fieldable> fields = d.getFields();
System.out.println( (i+1) + ". ==========================================================");
for ( Fieldable field : fields ) {
if (field.isStored()) {
System.out.println(" >> " + field.name() + " - " + d.get(field.name()));
}
}
}
System.out.println("Found " + hits.length);
}
有什么工具可以下载吗?
【问题讨论】: