1

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))

remy
  • 1,255
  • 6
  • 20
  • 27

1 Answers1

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))?

Community
  • 1
  • 1
Andrejs
  • 26,885
  • 12
  • 107
  • 96