我DONOT明白你正在嘗試做的,有在那裏沒有交集
如果u的意思是問我如何做Lucene索引複合搜索(AND),見下文
TermQuery tq1= new TermQuery(new Term("VALUE4", FIELD2));
TermQuery tq2= new TermQuery(new Term("VALUE5", FIELD3));
// BooleanClauses Enum SHOULD says Use this operator for clauses that should appear in the matching documents.
BooleanQuery bq = new BooleanQuery();
bq.add(tq1,BooleanClause.Occur.SHOULD);
bq.add(tq2,BooleanClause.Occur.SHOULD);
IndexSearcher searcher = new IndexSearcher(index, true);
TopScoreDocCollector collector = TopScoreDocCollector.create(10, true);
//Iterate Collector hits
//process HitCollector or whatever terms, results,etc
編輯:
//Parser meant for using all the fields used for search
MultiFieldQueryParser multiQueryParser = new MultiFieldQueryParser(
searchFields, ANALYZER_NAME);
multiQueryParser.setDefaultOperator(QueryParser.AND_OPERATOR);
//You need to build something like this
Query query1 = new TermQuery(HEADER,"HEADER_01");
Query query2 = new TermQuery(XYZ_FIELD,"XYZ");
Query query3 = new TermQuery(HEADER,"HEADER_02");
Query query4 = new TermQuery(XYZ_FIELD,"ABC");
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(query1, BooleanClause.Occur.MUST);
booleanQuery.add(query2, BooleanClause.Occur.MUST);
booleanQuery.add(query3, BooleanClause.Occur.MUST);
booleanQuery.add(query4, BooleanClause.Occur.MUST);
//Search the index
Lucene核心是在Java中,所以你可以相應地標記它 – Narayan 2011-03-21 14:09:53