1

Given a white space tokenized field containing only numbers, I want to write a query able to match the documents containing:

1) ALL the numbers in a Set A

AND

2) At least one of the numbers in a Set B

This is what I wrote

q=wstf:( 1 AND 2 AND 3 AND 4 ) AND ( 5 OR 6 OR 7 OR 8 )  // (Set A) AND (Set B)

I remember (but I might be wrong) that it is possible to specify the default operator within the expression (I'm NOT talking about the q.op parameter) in order to get something like

q=wstf:(AND 1 2 3 4) AND wstf:(OR 5 6 7 8)

But I cannot find anything like this in the Reference Guide.

EDIT

Please, notice I set the default operator to AND

Any help?

Max
  • 2,508
  • 3
  • 26
  • 44
  • 1
    `q=wstf:(+1 +2 +3 +4) AND wstf:(5 6 7 8)` should do that. – Uwe Allner May 08 '14 at 10:42
  • Hang on a second! What would be the result if I set the default operator to AND ? Would the second part use a OR operator? I think not... – Max May 08 '14 at 11:36
  • As far as I know it is not possible to specify a default operator for combining the elements in a collection (within brackets), just one to combine different query elements (field:value). But I am always keen to learn something new ;) – Uwe Allner May 08 '14 at 11:42
  • I gave it a try and I noticed the default operator affects the results: count(x y) = count(+x +y) = count(x AND y) = 282 -- count(x OR y) = 738. Your suggstion would be good if I didn't change the default operator – Max May 08 '14 at 11:48
  • Then what about `q=wstf:(1 2 3 4 (5 OR 6 OR 7 OR 8))`? – Uwe Allner May 08 '14 at 11:55
  • I think it's the only way out, even if I aimed at avoiding all the boolean operators – Max May 08 '14 at 12:04

1 Answers1

1

You will only be able to leave off the operator you specified as default, in your case AND, and combine the query in one statement:

q=wstf:(1 2 3 4 (5 OR 6 OR 7 OR 8))

That is not as nice and short as you hoped to get, but at least a little bit shorter...

Uwe Allner
  • 3,399
  • 9
  • 35
  • 49