We're having problems implementing search facets with views search api blocks - and I'd like to get a definitive answer... is it possible?

What we've tried:

  1. Create a Search API view, with a block, then adding that block via the blocks page or via context module... no dice... the facet blocks dont show, or show with empty text (if set)
  2. Adding the same Search API views block via display suite... perfect dice... the facet blocks show and filter properly.

Not sure why the facets won't show for a block, but will show for a block added via a display suite field.

Can anyone shed some light on how we could accomplish this as a lot of our site is built with Views search api blocks and context module, and facets are key to getting the glue to stick.



cpliakas’s picture

Hi jptaranto.

Just a guess, but it sounds like a chicken and egg problem here. It is important to understand that in order to get the facet data for facet blocks to display, a search query has to be executed prior to the facet blocks being collected by the system. The way you have your site configured, you are essentially executing a query inside another block at its render time. Therefore the system probably thinks that no facet data is available at the time the facet blocks are being collected.

Not knowing the internals of Display Suite, it does some altering of the display logic so we may have a case where blocks are double processed which may be why that scenario works. Therefore when DS does it's block rendering, the query would have been executed during the first pass. Again this is just a guess, and you will have to do some debugging to find out.

I would recommend checking out the facetapi_check_block_visibility() function. You can throw some debug code in there to see exactly why a facet block isn't displaying. You can also throw some code at the beginning of the FacetapiAdapter::addActiveFilters() method to see when the facets are processed in relation to when the other block are attempting to render the facets.

jptaranto’s picture

After a little experimenting we've discovered facets will show when added via context, instead of the blocks interface. Cool.

Thanks for you're help.

cpliakas’s picture

Status: Active » Fixed

Great. Thanks for reporting back.

jptaranto’s picture

Woe strikes again...

I've just discovered that while adding facets via context works swell for views blocks also added via context, it doesn't work so well for views pages.

The facets will only show for a view page if they are added via the blocks module and not context.

Of course adding them via blocks neuters any facets I've added via context.

This is pretty tricky.

Status: Fixed » Closed (fixed)

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

nonzod’s picture

If the search view block and facets block are added via context into different regions I can see only view block.
If I put view block and facets block in the same region (via context) i can see facets and view...

I need the blocks into separate regions, there is any solution to this?

cpliakas’s picture

Facet API can only display facets when there is facet data to display, so a query has to be executed. If you are relying on a query that is executed in another block then you will get unreliable results because the block system itself isn't designed to interact with other blocks. Would love to hear possible workarounds from people who need this functionality. Let's make sure to continue these discussions in the threads below so conversations aren't fragmented:

#1417456: Facets on non-search Search API pages broken by facetapi_block_list_alter removing the block (Facet API)
#1402642: Facet API blocks not showing on "non search" pages (Search API)

jptaranto’s picture

I eventually got it working by updating to the latest version of Facet API (previously I was using a DEV version).

However all my search api views blocks and my facet blocks are being added via the context module, into separate regions.

giorgio79’s picture

@jptaranto: I am trying this context workaround but the facet blocks only show if they are in the same region with the views block or in a region that comes after the one with the views block...Arrrgghh

miiimooo’s picture

@chris: I'm beginning to think that the execution order is determined by page.tpl.php. If you have a theme that does

  1. sidebar_first
  2. content
  3. sidebar_second

I have to have the facets in sidebar_second (if the view is a block in content).
That's at least what it looks like.
The counter-intuitive thing (but maybe you know why) is that if there is a page view in main_content (instead of a block) then the facets can be in sidebar_first.
A very silly workaround (I immediately came up with) was to declare a hidden region and execute the block twice.
May be worth asking in core somewhere about block execution order and how it could be enforced to allow for facets everywhere.

UPDATE: I did some testing and it's not page.tpl.php that determines block execution order. What works is changing the order in the .info file and putting the sidebar_first after content.

cpliakas’s picture


Thanks for the heads up and the details. Very informative. I think this is why I am opposed to the searches being executed in a block, because you really have to understand what is going on in order to get facets and there is nothing I can do to get around this. I guess the tradeoff is that with Apache Solr Search Integration you get consistency but lose some flexibility, whereas with Search API you gain the flexibility with this architecture but loose some consistency and run into situations like this.


liquidcms’s picture

lol. yup.. this solved it for me.. i have been trying all day to get facet blocks placed on my panel panes; and sure enough... if i move them to a region which is "after" the region where the search results are displayed... the facets show up.