tags:

views:

117

answers:

3

Hi,

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

+4  A: 

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)
Adam Paynter
+1  A: 

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

(age:25) AND (name:tom OR name:dick OR name:harry)
sutlermb
+2  A: 

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

alternatively

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

KenE