I want to search two queries at the same time, such as “macbook pro” and “iphone”, and the default field to search is “title”, so the query is :(title: macbook pro title:iphone). I want to use “and” operation within each query, e.g. (+title:macbook +title:pro), and “or” operation between querys,i.e.
((+title:macbook +title:pro) (title:iphone)). However, after using QueryParser to parse this query(title: macbook pro title:iphone), the result will be :(title: macbook title:pro title:iphone), if I set the default operator of parser is QueryParser.AND_OPERATOR, then the query will be (+title:macbook +title:pro +title:iphone). Neither is I need. What can I do to get the right query?((+title:macbook +title:pro) (title:iphone))
I want to search two queries at the same time, such as macbook pro
Share
You can’t achive this using QueryParser parameters but you can construct your query programmatically using BooleanQuery in Lucene API
Similar question:
How to create nested boolean query with lucene API (a AND (b OR c))?