parse_filters() gets called in certain scenarios - I ran into it when adding an alias - that can cause issues.
Here's the scenario:
1. We set a handful of fixed filters to ensure that our query only returns certain results.
2. We set an alias.
3. We lose all our filters.

We have certain filters coming from the url, and others being manually set. So long as we do everything at the right time, things basically work. Ideally, we could add an alias at any point (prepare_query, modify_query, manually) and all of our manually set filters wouldn't disappear.

I'm not sure the attached patch is the perfect patch, but it allows non-querystring filters to persist. I've chosen to push non-querystring filters to the back of the pack.

Comments

pwolanin’s picture

Status: Active » Needs work

can of worms.

for example, if I remove a filter which came from the URL, and then add an alias, that filter would come back

I think this patch is not really the right approach.

pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new3.34 KB

this is totally untested, but I think it's a workable approach.

csevb10’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +drupal.org redesign, +drupal.org redesign solr, +drupal.org redesign sprint 2

Tested. It functions as expected. It seems like we're hacking around things to some degree, so the solution isn't one with which I'm wholly enamored, but the previous sticky situations around clearing and adding alias has been cleaned up. If a better solution comes up later, at least we managed to fix bugs surrounding alias now, and we can simply refactor later.

pwolanin’s picture

needs some more code comments, but committed to 6.x-1.x for immediate use in the redesign.

dww’s picture

FYI: now deployed on d.o and working fine:

http://drupal.org/search/apachesolr_search/signup

pwolanin’s picture

Committed this patch to all the active branches.

pwolanin’s picture

Status: Reviewed & tested by the community » Active

back to active for code comments.

jpmckinney’s picture

Title: parse_filters() causes any manually added filters to be lost » Add inline docs: parse_filters() causes any manually added filters to be lost
Category: bug » task

No longer a bug.

jpmckinney’s picture

Title: Add inline docs: parse_filters() causes any manually added filters to be lost » parse_filters() causes any manually added filters to be lost
Category: task » bug
Status: Active » Needs review

Shouldn't we remove the filter from fields_removed if we add it back with add_filter?

jpmckinney’s picture

Port my patch to 6.x-2.x and 7.x if patch goes in.

jpmckinney’s picture

StatusFileSize
new1.16 KB
pwolanin’s picture

Which version is that patch for? Or it's just cleanup for 6.x-1.x?

jpmckinney’s picture

It's a fix for all versions, starting with 6.x-1.x

pwolanin’s picture

Logic looks fine to me - looks like as much comment changes as anything.

afaikt, the only meaningful change is this, right?

+    // Remove from the record of removed filters.
+    $this->unset_filter($this->fields_removed, $name, $value);
jpmckinney’s picture

Yes, that's it. I fixed comments so that the two functions are comparable.

jpmckinney’s picture

Status: Needs review » Fixed

Fixed in 6.1, 6.2 and 7.1.

scor’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Fixed » Needs work
+++ Solr_Base_Query.php
@@ -178,8 +178,12 @@ class Solr_Base_Query implements Drupal_Solr_Query_Interface {
   public function add_filter($field, $value, $exclude = FALSE, $callbacks = array()) {
     $filter = array('#exclude' => $exclude, '#name' => $field, '#value' => trim($value), '#callbacks' => $callbacks);
-    $this->fields[] = $filter;
+    // Record the addition.
     $this->fields_added[] = $filter;
+    // Add to the public list of filters.
+    $this->fields[] = $filter;
+    // Remove from the record of removed filters.
+    $this->unset_filter($this->fields_removed, $name, $value);
   }

$name is undefined in this function. This is causing notices # Notice: Undefined variable: name in SolrBaseQuery->add_filter() (line 191 of /sites/all/modules/apachesolr/Solr_Base_Query.php).

jpmckinney’s picture

Status: Needs work » Fixed
StatusFileSize
new763 bytes

Right. Fixed.

Status: Fixed » Closed (fixed)
Issue tags: -drupal.org redesign, -drupal.org redesign solr, -drupal.org redesign sprint 2

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