Reputation: 2437
I'm almost new to lucene and trying to AND some queries and display them.
I've googled for entire web, though could't find the correct solution to this problem. The solutions for boolean query search include BooleanQuery
Lucene class, but this class is deprecated in Lucene 5.3.1 (the one that I'm using)
This is a part of my code:
public static void searchBooleanQuery(String indexDir, Query query1,
Query query2, Query query3, Query query4) throws IOException {
IndexReader rdr = DirectoryReader.open(FSDirectory.open(Paths.get(indexDir)));
IndexSearcher is = new IndexSearcher(rdr);
BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
booleanQuery.add(query1, BooleanClause.Occur.MUST);
booleanQuery.add(query2, BooleanClause.Occur.MUST);
booleanQuery.add(query3, BooleanClause.Occur.MUST);
booleanQuery.add(query4, BooleanClause.Occur.MUST);
}
Update
The problem :
I cannot display Boolean Query
by IndexSearcher
Object as search
method of this class (IndexSearcher) should be passed to by a Query! So, it gives me an error when I'm trying to run the following:
TopDocs hits = is.search(booleanQuery,10);
...
Upvotes: 10
Views: 6476
Reputation: 1307
Your booleanQuery
object is actually an instance of BooleanQuery.Builder
, not BooleanQuery
.
After you're done adding all your queries to the builder, you need to call the build
method.
Ex.
TopDocs hits = is.search(booleanQuery.build(),10);
Upvotes: 10