The addFilter function for building Solr queries gives us the ability to use it as an exclude filter ($exclude = TRUE).

Is it possible to exclude a addFilterSubQuery as a whole? eg. fq=-(myfield:value1 OR myfield:value2)

You'd think: why not just exclude one by one, thus fq=(-myfield:value1 OR -myfield:value2), but that doesn't always work so it seems: http://stackoverflow.com/questions/1343794/searching-for-date-range-or-n... (tested & I can confirm)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rp7’s picture

Oh btw, I solved the linked issue within Drupal, by not using a FilterSubQuery, but by just adding a normal fq Filter and somewhat abuse it:

      $query->addFilter('(-myfield', '(value1 AND (myfield:[* TO *])))', TRUE);
pwolanin’s picture

Well, I can see where that might be a useful feature. I guess we'd need to add another property to the subquery object class and/or take in another param to the constructor.

pwolanin’s picture

Category: support » feature
geertvd’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
2.34 KB

I needed this feature so wrote a patch to add this.

Nick_vh’s picture

Status: Needs review » Needs work
+++ b/tests/solr_base_subquery.test
@@ -105,5 +105,14 @@ class DrupalSolrFilterSubQueryTests extends DrupalUnitTestCase {
+    $this->assertEqual($params[0], '-(label:bar AND label:baz)', '-(label:bar AND label:baz)');

Can you add a better explanation what to expect? Something along the likes of "Expect the exclusion of the bar and baz label".

Also, when talking to you, you explained you wanted to exclude empty fields. Is that a useful example to add here also?

geertvd’s picture

The use case I was talking about is explained here http://stackoverflow.com/questions/634765/using-or-and-not-in-solr-query/
I'll add that to the test later and add some more comments explaining the reasoning.

Unless there is a better way to do this kind of query off course.

geertvd’s picture

Status: Needs work » Needs review
FileSize
1.05 KB
2.82 KB

Added the logic explained in http://stackoverflow.com/questions/634765/using-or-and-not-in-solr-query/ and changed my assert message.

  • Nick_vh committed 0efe4ac on 7.x-1.x authored by geertvd
    Issue #1543156 by geertvd: Exclude SolrFilterSubQuery as a whole
    
Nick_vh’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.