I have added a block with the Views display style "Facet block", but how do I change which facet widget it uses? I am using the search_api_range module, but it seems the widget, or any facet widget styles are not available to be used by the "Facet block" Views display.

Comments

rooby’s picture

You should be able to do it.
I have a search api view with facet blocks that use the select widget.

In you view's facet block settings make sure "Hide block" is set to "Yes", then instead of putting the views facet block on your search page put the facetapi facet block.

Then you change the facet api facet settings for the widget and it should work as expected.

webavant’s picture

When I set "hide block" to "yes", the block no longer displays on other pages besides the view page.

webavant’s picture

It seems I have to put the hidden views facet block into the same region with the regular facet api blocks. Is that intended?

rooby’s picture

I can't say I have tried to do that with the facet blocks on non-search pages.

I see you have seen #1417456-19: Facets on non-search Search API pages broken by facetapi_block_list_alter removing the block, which explains the issues surrounding that.

So either this has to be fixed. Or #1235026-27: Show facet blocks everywhere including non search pages has to be fixed. Or both.

webavant’s picture

I struggled for a very long time with it. The current behavior is that the views facet blocks lose the widget style unless you set "hide block" to "yes" and put it in a region with regular facet API blocks. I also installed this patch, so I'm not sure it behaves the same way prior to that patch.

alexweber’s picture

Running into this myself. I don't think the problem is that it doesn't have a widget style display option per-se, but rather that it doesn't respect the widget style option defined in the facet's configuration. (The views block doesn't allow you to change any of the other facet settings anyway)

In display_facet_block.inc:

    $facets = array();
    $prefix = rawurlencode($facet_field) . ':';
    foreach ($terms as $term) {
      $name = $filter = $filters[$term['filter']];
      if (isset($map[$filter])) {
        $name = $map[$filter];
      }
      $query['f'][0] = $prefix . $filter;

      // Initializes variables passed to theme hook.
      $variables = array(
        'text' => $name,
        'path' => $base_path,
        'count' => $term['count'],
        'options' => array(
          'attributes' => array('class' => 'facetapi-inactive'),
          'html' => FALSE,
          'query' => $query,
        ),
      );

      // Themes the link, adds row to facets.
      $facets[] = array(
        'class' => array('leaf'),
        'data' => theme('facetapi_link_inactive', $variables),
      );
    }

    if (!$facets) {
      return NULL;
    }

    $info['content']['facets'] = array(
      '#theme'  => 'item_list',
      '#items'  => $facets,
    );

Notice how it explicitly just renders the facets as links. Still trying to figure out what's the best way to fix this... Any ideas?

PS - Also confirming that, it might take some tweaking of the "Display for searches" facet setting but the solution in #5 works :)

drunken monkey’s picture

Category: feature » support

I'm not sure I understand all the problems mentioned in this issue. However, maybe this handbook page can throw some light on some of your problems.

First off, the Views "Facets Block" display is meant as a very crude way to display facets on non-search pages. I couldn't figure out how to flexibly include any of the settings/functionality available for Facet API settings – so I didn't attempt to duplicate these but just provided a way to use Facet API facets with this block, circumventing the problem (though leading to some others).

The problem some of you are seeing might be that the Views block (with the Facets block display view) is rendered after the Facet API facet blocks. Thus, the Facet API facet blocks don't see any search and conclude that there are no facets to be displayed. See also the FAQs for this problem. Just move the Views block around until you find a place where it is rendered before all facet blocks, and it should be fine.

I hope this could help.

(If anyone knows how to include Facet API facets into a Views block, I'd be glad to add that, too, though. As said, it's just that I couldn't figure out how this could be done.)

ressa’s picture

Thanks for adding that to the handbook just yesterday, when I needed it today :-)

My problem was that my "Facets block" wasn't put before the other Facet API blocks ("Facet API: Search service: ..."). As soon as the "Facets block" was above them, even in the same region, all the search facets were displayed on non-search pages.

So, to repeat for others, the "Facets block" can be used as a trigger for all of the facets from your search page to appear on any other non-search page, like this:

  1. Add a "Facets block" in your View, where you already have for example a Page with Filter criteria: Search: Fulltext search (exposed) and Path: /adv-search
  2. Under Block settings, set Block name to "Facets block" and the Search page path in your new "Facets block" to point to your search page, which in this example is "adv-search" (note the missing slash in front)
  3. Set the Facet field to "Title" or another field, otherwise nothing will happen
  4. Go to Structure > Blocks and put the "Facets block" right before your other "Facet API: Search service: ..." blocks. Verify that it works by going to the front page for example, and refresh

Now, since the "Facets block" is only used as a trigger for the other facets, you want to hide it: Set the Views "Facets block" Block settings > Hide block to "Yes", so that a search will be triggered but not shown, exposing the facets.

If you want to show the facets only on the front page, go to Structure > Blocks > Facets block > configure > Show block on specific pages > Only the listed pages and enter <front>, like you would any other block.

nasia123’s picture

I am having a small issues with this...
I have created a non search page and the facets are displaying according to the instructions provided here.
But when I click on a filter I get to the search page which I have provide in the view settings but no search is performed, while the path is like this
my-search-page?f[0]=type%3my-keyword

I am missing some other setting?

drunken monkey’s picture

Did you maybe set the keywords field ("Search: Fulltext search") or some other exposed filter to "Required"? Is a search executed when you go to the same page without the ?f[0]=type%3my-keyword suffix?

nasia123’s picture

yes I had the exposed filter set to required.
thanks for the help!

drunken monkey’s picture

Issue summary: View changes
Status: Active » Fixed

No problem.

Status: Fixed » Closed (fixed)

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