lucene3.0 中BooleanQuery 的使用
private static void search(String str) throws Exception {
IndexReader reader = IndexReader.open(FSDirectory.open(new File(
INDEX_DIR)), true); // only searching,
// so read-only=true
Searcher searcher = new IndexSearcher(reader);
Analyzer analyzer = new IKAnalyzer();
String field = "contents";
QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, field,
Query query = null;
str = getKeyWord(str);
query = parser.parse(str);
BooleanQuery q = new BooleanQuery();
q.add(query, BooleanClause.Occur.MUST);
QueryParser parser2 = new QueryParser(Version.LUCENE_CURRENT, "keyword", analyzer);
Query q2 = parser2.parse(str);
q.add(q2, BooleanClause.Occur.SHOULD);
searcher.search(q, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
欢迎转载,请注明出处:亲亲宝宝