Search code examples
sqlsolr

Solr equivalent of trivial SQL filter


Is there a Solr equivalent for WHERE 1 = 0 in SQL? Would fq=-id:[* TO *] suffice to force an empty result set to be returned (and fq=*:* to filter nothing)?

I looked extensively at the Apache Solr documentation, especially the function query section, but wasn’t able to find a definitive answer.


Solution

  • One possibility is to use two opposite filter queries:

    fq=field:value&fq=-field:value

    First filter will only select documents having value and second filter will keep none of them.