2
votes

I want to write a Lucene query which is the equivalent of the following SQL

where age = 25
and name in ("tom", "dick", "harry")

The best I've come up with so far is:

(age:25 name:tom) OR
(age:25 name:dick) OR
(age:25 name:harry) 

Is there a more succinct way to write this?

Thanks, Don

3

3 Answers

9
votes
age:25 AND name:(tom OR dick OR harry)

alternatively

+age:25 +name:(tom OR dick OR harry)
4
votes

Does this work?

age:25 AND (name:tom OR name:dick OR name:harry)

I understand this may not be what you're looking for. I didn't know if the purpose of your question was to factor out the age:25 clause or if it was to eliminate the name: prefixes.

If you make name your QueryParser's default field, you could reduce this down to:

age:25 AND (tom OR dick OR harry)
1
votes

It's not much more succinct, but you can try:

(age:25) AND (name:tom OR name:dick OR name:harry)