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))
Asked
Active
Viewed 127 times
1

remy
- 1,255
- 6
- 20
- 27
-
1What is the problem with "((+title:macbook +title:pro) (title:iphone))"? – jpountz Mar 21 '12 at 08:28
1 Answers
1
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))?