Problem/Motivation

If a facet display is set to Exclude ("Make the search exclude selected facets, instead of restricting it to them.") and the operator is set to "AND" then the active (selected) filter link loose the query strings and redirect to an empty search page.

http://dev.local/en/product-search?search_api_views_fulltext=querystring
vs.
http://dev.local/en/product-search

Proposed resolution

I chased down the cause to this section:
search_api/contrib/search_api_facetapi/plugins/facetapi/query_type_term.inc: line ~183

// Always include the active facet items.
foreach ($this->adapter->getActiveItems($this->facet) as $filter)  {
      $build[$filter['value']]['#count'] = 0;
}

If the count is set to zero then in the widget_links.inc the #query part is skipped.

facetapi/plugins/facetapi/widget_links.inc: line ~119

      // Adds the facetapi-zero-results class to items that have no results.
      if (!$item['#count']) {
        $variables['options']['attributes']['class'][] = 'facetapi-zero-results';
      }
      // If count more than 0.
      else {
        
.......

        // Add an ID to identify this link.
        $variables['options']['attributes']['id'] = drupal_html_id('facetapi-link');
        $variables['options'] += array(
          'html' => $item['#html'],
          'query' => $item['#query'],
        );
      }

I don't understand the whole code, so i don't know what is the right solution for this. For my case i changed like below. Now my active facets links has the query string to.

// Always include the active facet items.
foreach ($this->adapter->getActiveItems($this->facet) as $filter)  {
-      $build[$filter['value']]['#count'] = 0;
+      $build[$filter['value']]['#count'] = 1;
}

David

Comments

zsuffad created an issue. See original summary.

Zsuffa Dávid’s picture

Issue summary: View changes
Zsuffa Dávid’s picture

Issue summary: View changes
drunken monkey’s picture

Project: Search API » Facet API
Version: 7.x-1.27 » 7.x-2.x-dev
Component: General code » Code
Status: Active » Needs review
StatusFileSize
new2.89 KB

Thanks a lot for reporting this problem!

The line you propose changing was added in #2629136: Incorrect active facet count returned for pretty good reasons, so I’d be hesitant to change this to fix some other problem.

In my opinion, this looks more like a bug in Facet API itself than in its Search API integration. The code you cite from widget_links.inc looks to me like the last block (starting with “Add an ID to identify this link.”) is only in the else block by accident.
Moving this block to after the else block seems to fix the bug, too.

Patch attached, please test/review!

joseph.olstad’s picture

patch 4 does not apply to HEAD of either 7.x-1.x , nor 7.x-2.x


╭─◀ ☕ j envy-4700u ▶ ~/drupal.org/facetapi ▶ 📂4  21 🔗0 ▶ 🔀 7.x-1.x ▶
╰❯ $ patch -p1 --dry-run < 3218431-4--missing_query_strings.patch 
checking file plugins/facetapi/widget_links.inc
Hunk #1 FAILED at 120.
1 out of 1 hunk FAILED

 ╭─◀ ☕ j envy-4700u ▶ ~/drupal.org/facetapi ▶ 📂4  21 🔗0 ▶ 🔀 7.x-2.x ▶
 ╰❯ $ patch -p1 --dry-run < 3218431-4--missing_query_strings.patch 
checking file plugins/facetapi/widget_links.inc
Hunk #1 FAILED at 120.
1 out of 1 hunk FAILED

joseph.olstad’s picture

Status: Needs review » Postponed (maintainer needs more info)

The code in question was updated in recent releases.

Please try your test case with a current release of facetapi, this may have already been fixed.

drunken monkey’s picture

Oops, sorry for not noticing that. (Guess I’m not used to Facet API module actually getting new commits …)
Yes, cannot reproduce this anymore on latest 7.x-2.x release. Let’s see whether zsuffad reports back, otherwise we can probably close.

Zsuffa Dávid’s picture

Tested with release 7.x-1.9 everything is working fine now without the patches.
Thank you.

joseph.olstad’s picture

Status: Postponed (maintainer needs more info) » Fixed

fixed in 7.x-1.9

Status: Fixed » Closed (fixed)

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