Lucene 4.x – Searcher
IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(“index”)));
IndexSearcher searcher = new IndexSearcher(reader);
QueryParser qp = new QueryParser(Version.LUCENE_46, “title”, new StandardAnalyzer(Version.LUCENE_46));
qp.setDefaultOperator(Operator.AND);
Query q = qp.parse(“tori”);
QueryParser qp2 = new QueryParser(Version.LUCENE_46, “ptype”, new StandardAnalyzer(Version.LUCENE_46));
qp2.setDefaultOperator(Operator.AND);
Query q2 = qp2.parse(“cd”);
BooleanQuery bq = new BooleanQuery();
bq.add(q, Occur.SHOULD);
bq.add(q2,Occur.SHOULD);
System.out.println(bq);
TopDocs td = searcher.search(bq, 10);
ScoreDoc[] sds = td.scoreDocs;
for(ScoreDoc sd:sds){
Document doc = searcher.doc(sd.doc);
System.out.println(doc.get(“upc”)+”, “+doc.get(“title”)+” ==> “+doc.get(“ptype”));
}