2

All:

I want to ask one beginner question about solr query:

right now, there are Several situations I want to search:

[1] Search all documents with "fund" AND without "report"
[2] Search all documents with "fund" OR without "report"

Could any one tell me how to write these queries? I tried:

fund OR -report
fund AND -report

but both queries return same results

Thanks

Kuan
  • 11,149
  • 23
  • 93
  • 201

1 Answers1

4

I am not sure why this doesn't work as is, but if you use the logical negation of #2, and negate that, then it does work, e.g:

-(-fund AND report)

The results for #1 (fund AND -report) are correct.

From this thread, it seems that Solr has difficulty interpreting queries containing OR where one of the criteria is negative, but works well with purely negative queries.

FYI, you can also use NOT in place of - if that makes things easier to understand:

NOT(NOT fund AND report)
Community
  • 1
  • 1
David Faber
  • 12,277
  • 2
  • 29
  • 40
  • Could you help me with a related question: http://stackoverflow.com/questions/27827347/plus-sign-in-solr-query-is-not-correctly-treated – Kuan Jan 07 '15 at 19:48
  • Just answered. Please accept this answer if it works for you. Thanks! – David Faber Jan 07 '15 at 19:51