日期:2014-05-18 浏览次数:20741 次
FastVectorHighlighter fvh = new FastVectorHighlighter(false,false);
Analyzer a = new MMSegAnalyzer();
IndexSearcher searcher = new IndexSearcher(IndexReader.open(FileIndexUtil.getDirectory()));
MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_35, new String[]{"title","content"}, a);
Query query = parser.parse(name);
FieldQuery fq = fvh.getFieldQuery(query);
TopDocs tds = searcher.search(query, 20);
for(ScoreDoc sd : tds.scoreDocs) {
String highTitle = fvh.getBestFragment(fq, searcher.getIndexReader(), sd.doc, "title", 100);
System.out.println(highTitle);
System.out.println("-------------------------");
String highContent = fvh.getBestFragment(fq, searcher.getIndexReader(), sd.doc, "content",100);
System.out.println(highContent);
System.out.println("**********************************************************************");
}
searcher.close();
public void testSearcherByFastHighlighter(){
SearchUtil su = new SearchUtil();
su.searcherByFastHighlighter("开");
}