7

I have a faceted search working that uses searchapi, facetapi, and entityapi. I was not the one who developed this, but I have some experience with Drupal. As of now the navigation uses links for selection and looks like below (first level of bullet points aren't links). When mixing is selected sound design and composition disappear as expected.

What the client wants is for all items to still stay visible and selectable as the user drills down (even if it returns nothing). Only one item per category will be selectable at a time, but the user should be able to do it without having to 'go back'.
Any advice is greatly appreciated.

  • What We Do_
    • Mixing (18)
    • Sound Design(11)
    • Composition (6)
  • Who We Are_
    • Joe Schmoe (17)
    • Jeff Bleck (14)
    • David Berry (4)
  • Affiliated Composers_
    • Jim Carey (3)
    • Tony Maroni (2)
8

Under admin/config/search/search_api click “edit” on your search index and select “Facets”. Then for all facets that need the described behavior for their items, follow these steps:

  1. Click “configure display”.
  2. In the “Global settings” section, change the “Minimum facet count” to 0 (zero). Arguably this input field should rather be called “Minimum facet item count” …
  3. “Save configuration”.

Now all non-matching facet items should remain in your facet list (with a zero count). As you have already mentioned, clicking such a facet item will return no search results anymore.

  • Hmm, on my installation the list just keeps shrinking (not to say only 1 item is left) when clicking on an item... – Michiel Jul 16 '13 at 13:14
  • @Michiel Hmm, that’s odd. I have just tried that again on my site and it works without a problem. Even when I change the “Minimum facet count” of two different facets to 0 it works: when selecting an item of the first facet, the items of the second facet are updated but they never disappear. Rather all facet items that would have disappeared previously do now have a “(0)” marker at the end. – Chriki Jul 16 '13 at 15:26
  • Thanks for your reply! On my installation only 1 item remains if I click that item... Any idea what could be the cause of this strange behavior? – Michiel Jul 16 '13 at 16:05
  • @Michiel I’m afraid, I have no idea :-( – Chriki Jul 16 '13 at 16:38
  • 1
    Yes, sorry for being confusing in my first comment. Actually the behvior you are looking for works for me (i.e., keeping all facet items visible at all times). I just wanted to point out that the desired behavior does also work for me across multiple facets. – Chriki Jul 17 '13 at 7:43
1

I think the solution in this comment is the solution to your problem. In your template.php, overwrite the theme_facetapi_link_inactive-function:

function theme_facetapi_link_inactive($variables) {
  // Builds accessible markup.
  $accessible_vars = array(
    'text' => $variables['text'],
    'active' => FALSE,
  );
  $accessible_markup = theme('facetapi_accessible_markup', $accessible_vars);

  // Sanitizes the link text if necessary.
  $sanitize = empty($variables['options']['html']);
  $variables['text'] = ($sanitize) ? check_plain($variables['text']) : $variables['text'];

  // Adds count to link if one was passed.
  if (isset($variables['count'])) {
    $variables['text'] .= ' ' . theme('facetapi_count', $variables);
  }

  // Add functionality requested in #1669600.
  if (!$variables['count'] && isset($variables['options']['query']['f'])) {
    // We should be getting this from the url processor plugin, however we are
    // making an assumption since this is in our custom theme.
    $params = &$variables['options']['query']['f'];

    // Capture the filter associated with this link and find the field alias.
    $filter = end($params);
    $field_alias = substr($filter, 0, strpos($filter, ':')) . ':';

    // Iterate over params and strip out items that are using the same field
    // alias as this filter. Do not strip out this filter.
    foreach ($params as $key => $param) {
      if (0 === strpos($param, $field_alias) && $param != $filter) {
        unset($params[$key]);
      }
    }
  }

  // Resets link text, sets to options to HTML since we already sanitized the
  // link text and are providing additional markup for accessibility.
  $variables['text'] .= $accessible_markup;
  $variables['options']['html'] = TRUE;
  return theme_link($variables);
}
0

Here is my work arround for this problem, no coding required!

  • create a view based on your search index
  • add a facets block to the view and configure it to use the facet field you want, if you have a taxonomy tree, you can use the all parents term field to only show the toplevel.
  • configure the block so it is displayed on your site

now you have also the other facet blocks everwhere because the search is activated, if you want you can hide the created block with css.

grts

frederic wbase

  • I don't know why but in my case, when I select a field to use with the facet block, it displays only a few facets. Ive set the view to display all items, and theres no limit also in the facet configuration – Math666 Jun 23 '15 at 12:29
0

To ensure that all items remain visible and selectable, make sure that the Global Settings search is set to "OR". From the admin menu, go to Configuration > Search API > [name of index] "edit" link > Facets (tab) > [name of facet] "configure display" link > Under "Global Settings", select Operator "OR". (Keep "Minimum Facet Count" at 1)

To ensure that all facet blocks remain visible, make sure that on each facet block's configuration page that facets are shown on the specified pages. Go to Structure > Blocks > [name of facet block] "configure" link. For example:

services
services/*

Users are able to drill down. Without going back, users would just need to deselect a facet item. The option " Limit to one active item" currently does not work well when configured, based on my experiences.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.