While testing https://www.drupal.org/node/2611812 I encountered a strange issue with facet block display.
I have created a search server with an index and a view as well as a facet related to displaying a list of dates. I then added a view with a page display and inserted my facet block to the first sidebar without any display conditions.
Everything works as excepted when visiting the page for the first time as when selecting a facet, but when I remove the facet again using the widget, the entire block disappears. After clearing cache the block returns, and if I refresh the page is vanishes again. I tested using several different selection, but every time I revisit a selection I have visited before the block is hidden.
| Comment | File | Size | Author |
|---|---|---|---|
| Screen Shot 2016-09-30 at 12.45.50.png | 271.73 KB | jespermb | |
| Screen Shot 2016-09-30 at 12.45.39.png | 285.96 KB | jespermb |
Comments
Comment #2
strykaizerThanks for reporting. We are just noticing the same, investigating right now...
Comment #3
strykaizerQuick fix: turn off your views caching for your search api view.
We need to provide a patch so other users wont run into this.
Comment #4
strykaizerPatch in #2809469: Set search api caching as default for new search api views for new views.
Fix for existing views, see #3
Comment #5
duaelfrI can confirm this is going to be solved by the related issue and can be manually solved by selecting the "Search API specific" cache engine for your view (or no cache at all if you like to live dangerously ^^).
Comment #6
trickfun commentedSorry but after a lot of time this issue is not fixed. i have the same behaviour.
Only selecting none cache, facet works fine.
drupal 9.3.8
facet and seache api deve version
Thank you
Comment #7
trickfun commentedAny news here?
facet works only with no cache.
thank you
Comment #8
richarddavies commentedI can also confirm this behavior with Drupal 9.3.16, Search API 1.23, and Facets 2.0.2. My view is using Search API (tag-based) caching. Upon the first page load of the view (or after clearing all caches) the facets display as expected. After refreshing the page the facets disappear. Setting the view caching to 'none' seems to fix it, but according to the comments above it should work now with Search API caching.
Comment #9
bob.hinrichs commentedSame problem, confirmed.
Comment #10
mkalkbrennerFacets now support caching with the latest dev versions of facets and search_api.
Comment #11
szeidlerI can confirm #10. With both modules on the recent dev versions it works.
Note: When using https://www.drupal.org/project/facets_block it appears to be failing with the same bug like reported here.
Comment #12
mkalkbrennerWe just wait for the upcoming Search API release to be able to release Facets 2.0.3.
Comment #13
wouter.h commentedI just did an implementation where there was a need to have proper caching.
I upgraded search api to 8.x-1.24, upgraded facets to 2.0.4 in a drupal 9.3.15 installation.
For views without facets, the "Search API (time-based)" caching works perfectly. Unfortunately on views with facets the facets disappear when reloading the page.
I tested the implementation against the latest development versions with the same results.
Comment #14
mkalkbrennerUntil the release of Facets 2.0.4, facets never supported views caching. It is also still mentioned in our README.txt:
The caching support introduced by Facets 2.0.4 is still very young and now we ran into issues:
#3295570: Search API views caching is broken with facets 2.0.4
#3295564: Views caching is broken with facets 2.0.4
#3296006: In case of an exception thrown by the backend, Search API Cache plugins always cache an empty result
Without these patches the cache metadata stored within a views config is totally random because views asks facets for their metadata during saving while facets asks views build theirs.
Please test these patches. It is very important that you re-save your views after applying them! And clear your caches.
BTW People who just upgraded the module and didn't reconfigure their views to use caching should not be affected by the issue.
Comment #15
mkalkbrennerComment #16
mkalkbrennerOur processor base class declare a max-age of "0".
But due to the latest changes in Search API and Facets we should consider to set it to CACHE_PERMANENT.
Comment #17
richarddavies commentedI've updated to Drupal 9.4.5, search_api 1.25, search_api_solr 4.2.8, and facets 2.0.5. I'm still having issues with disappearing facets after re-enabling Search API (tag-based) caching on a view. The facets still disappear whenever I refresh the page. Clearing the cache restores the facets, but they disappear after another page reload.
Update: Most of my search API views with facets do appear to be working correctly, but I have one problematic view where the facets always disappear after a page refresh.
Update #2: After much experimentation, I've discovered that it is the `Use hierarchy` facet setting that is causing the facet to disappear. It's a taxonomy facet and when caching is enabled and use hierarchy is checked, the facet disappears after a page refresh. If unchecked, the facet no longer disappears.
Comment #18
hitchshockI can confirm that patches from #14 don't help. The issue is still reproducible.
Comment #19
mkalkbrennerI maintain a big site with lots of facets, including some hierarchical ones based on taxonomy. We use time based and tag based caching there and both work very well.
But I trust you that you run into issues with your setups. But I assume that it might not be a general issue but edge cases caused by configuration detail or custom code.
So we need much more details. Ideally you debug the cache metadata throughout the initial request and the first request aterwards.
And be aware that not all sub-modules and custom or contrib modules might be compatible yet, For example: #3264284: Facets summary should be cacheable, in case facets are using cacheable source.
Comment #20
richarddavies commentedCan you please elaborate on how to "debug the cache metadata"?
Comment #21
bryandenijsI ran into the same problem, but after some debugging I figured out that is was caused by the
metatag_viewsmodule (part of the Metatags module). I will try to explain why:Normally, when getting the view cache, the method
\Drupal\search_api\Plugin\views\cache\SearchApiCachePluginTrait::cacheGetis used. When the cache hits and has results, this method will also call the$this->getQueryHelper()->addResults($results);. This stores the results in the QueryHelper and those results are later used to build the.But the metatag_views module overrides this cacheGet method it with its own
\Drupal\metatag_views\MetatagViewsCacheWrapper::cacheGet. This method does basically the same as theSearchApiCachePluginTrait::cacheGet, except that it is doing something extra for the metatags. The important thing is that is misses the call to theaddResults. Therefore, when the facets are being build, the results are not added.I got around this problem by uninstalling the metatag_views since I was barely using it. I don't really know what the solution is if you cannot or don't want to uninstall the module.
Comment #22
hitchshock@bryandenijs You are right, the
metatag_viewsmodule breaks facets for me too. But in my case, unfortunately, I need that module and can't uninstall it.metatagmodule already has a ticket for the same issue: #3261473: Views cache wrapper overrides other modules cache logicThat patch helped me.
Comment #23
mkalkbrennerThanks for sharing that information!
So I mark this support request as fixed.