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
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3218431-4--missing_query_strings.patch | 2.89 KB | drunken monkey |
Comments
Comment #2
Zsuffa Dávid commentedComment #3
Zsuffa Dávid commentedComment #4
drunken monkeyThanks 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.inclooks to me like the last block (starting with “Add an ID to identify this link.”) is only in theelseblock by accident.Moving this block to after the
elseblock seems to fix the bug, too.Patch attached, please test/review!
Comment #5
joseph.olstadpatch 4 does not apply to HEAD of either 7.x-1.x , nor 7.x-2.x
Comment #6
joseph.olstadThe 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.
Comment #7
drunken monkeyOops, 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.
Comment #8
Zsuffa Dávid commentedTested with release 7.x-1.9 everything is working fine now without the patches.
Thank you.
Comment #9
joseph.olstadfixed in 7.x-1.9