If people select a filter item the next page displayw only this item because in the current results are no others items. But if people want to change this filter they must deselect the active item and then select another item. This is really not user friendly so I'm searching for a more intuitive way.

->Optionally a facet should also displays inactive items from the origin query so people can choose an item.

Facet image

I use search_api and seach_api_db.

I'm searching for while about this issue but I could not find any information. I hope someone can give me some advice.

CommentFileSizeAuthor
facets.png17.14 KBchecker

Comments

cpliakas’s picture

Hi checker.

Thanks for the post and the details around what you are asking for. There are a couple of ways you can do this.

1) Use the "OR" operator and try to get the patch at #1393928-28: Add a per-facet setting that allows only one item to be active at a time to work. This has the adverse side effect of using facets to widen the results.

2) Implement the "negative facet" pattern by configuring the "Minimum facet count" setting to 0 in the facet's display settings form and add some logic in a theme hook override that deactivates active facets and makes the one selected the only active facet. In template.php of your custom theme, override theme_facetapi_link_inactive() with the following code. Note that only the code under the comment "Add functionality requested in #1669600." has been added.


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);
}

Note that the $params = &$variables['options']['query']['f']; is an assumption that you are using the standard url processor plugin. If you are using an alternate url processor plugin such as Facet API Pretty Paths, this hack won't work.

Thanks,
Chris

checker’s picture

Thank you for your answer cpliakas! I tested 2) but it does not work. There are none inactive items after i selected one item. But I set "Minimum facet count" to 0. Could this be a problem with search_api_db?

cpliakas’s picture

checker,

Facet API can only work with the data provided to it by the backend module, so unfortunately if search_api_db doesn't support facets with counts of 0 then this technique won't work and there is nothing you can do on the Facet API layer. If search_api_db can get the data, then I am confident this technique will work. I would recommend pinging that project to see if it is supported.

Thanks,
Chris

checker’s picture

Status: Active » Fixed

Thank you again. I switched to solr and now it is working.

cpliakas’s picture

Excellent! Thanks for posting back.

Chris

yurgon’s picture

Hi,
Why dont work with Database search server ?

cpliakas’s picture

Hi yurgon.

This is probably a better question for the Drupal support forums or a post against the Database Search / Search API Solr issue queue since it doesn't have to do with the topic being discussed.

Thanks,
Chris

yurgon’s picture

I swith to Solr and steel dont work fo me

Status: Fixed » Closed (fixed)

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

angheloko’s picture

Hi,

Suggestion 2 in http://drupal.org/node/1669600#comment-6190924 worked perfectly for me.

Just curious, is there a chance that a similar functionality will be committed? I saw quite a few slightly similar issues/requests (http://drupal.org/node/1446824) and I think that one of the common functionalities that is being looked for at Facet API/Search API integration is how to use it as the site's main source of navigation.

In any case, awesome work! :-)

figureone’s picture

Issue summary: View changes

I've submitted a patch to search_api_db that should make that backend work with this patch.

jamesmorrish’s picture

I also got this working by switching to Solr.

shaneonabike’s picture

Just for those having issues I wanted to point out that you need to install FacetAPI Pretty Paths dev as per https://www.drupal.org/node/1393928#comment-7145054 if you are using that module. I couldn't figure out why this wasn't working properly until I found that :/