日期:2014-05-20 浏览次数:20773 次
doc.add(new StringField("publish", publish, Field.Store.YES));
try {
FSDirectory fsdir = FSDirectory.open(new File("索引路径"));
IndexReader reader = DirectoryReader.open(fsdir);
fsdir.close();
IndexSearcher searcher = new IndexSearcher(reader);
Query query = new TermQuery(new Term("publish", "微博"));
ScoreDoc[] hits = searcher.search(query, 5000).scoreDocs;
int size = hits.length;
for (int i = 0; i < size; i++) {
Document doc = searcher.doc(hits[i].doc);
System.out.println(doc.get("publish"));
}
} catch (IOException ex) {
ex.printStackTrace(System.err);
}