Hi All,

I'm getting a result in my facet that I want to hide. I don't understand why it is showing up at all since it should be empty. The facet returns taxonomy terms and a node that has no term will return a number. See my steps below:

1. Setup taxonomy
2. Nodes are assigned 0 or more of those taxonomy
3. Do a search and look at facets

RESULT: under that taxonomy facet any of the items which are not assigned to that taxonomy come up as a number.
EXPECT: don't show that option within the facet if a specific term isn't displayed OR specifically hide that term if it wants to show up in the facet.

Thanks!
Corey

Comments

cpliakas’s picture

Hi Corey.

The behavior you expect is the correct behavior given the defaults. However, Facet API can only work with the data that is passed to it by the backend module, and I can't seem to replicate this behavior using Apache Solr Search Integration. Therefore I would be curious to see what data is returned by Search API Solr, as I can see form your other post that that is the combo you are using.

Thanks for the post and the details,
Chris

cpliakas’s picture

Just to add to this, also make sure that the "Minimum facet count" is set to something higher than 0 in the facet's configuration settings. It ill be in the bottom right hand corner when you clock on the facet's "configure display" link.

coreycondardo’s picture

I have it set to 1 as expected. The problem is many results are coming through with that result so setting it to 1 will still show it.

coreycondardo’s picture

This somehow resolved itself. It happened when a solid reindex was complete.

--Corey

cpliakas’s picture

Status: Active » Closed (fixed)

Hm, weird! I'm glad it is working as expected, at least.

Thanks for posting back,
Chris

myselfhimself’s picture

Component: Custom Search Blocks » Code
Status: Closed (fixed) » Active

Hello : )

As for me, I have a type facet with a base page item in it. The Minimum facet count for that facet is 1.
I am using Search API with the Search API Solr backend.

As a visitor, when I click to filter out any content type item in the list (but for 'base page'), I see two items : the content type checkbox I just clicked AND a 'base page' unchecked checkbox. The latter has a facetapi-zero-results class.

I sought ways to hide the 'base page' item when it matches 0 results:
- it is not possible to hide it in bare CSS is empty because I need to hide the A (having class facetapi-zero-result), the INPUT checkbox and their parent LI altogether,
- hiding in JS with eg. a jQuery parent selector, but I do not like that option,
- in PHP, using facetapi_bonus, I'm implementing the hook_facet_items_alter :

/**
 * Implements hook_facet_items_alter.
 *
 * Hides base page content type facet items. 
 * @see facetapi_bonus module.
*/
function mymodule_search_facet_items_alter(&$build, &$settings) {
  // If current facet is for content types.
  if ($settings->facet == 'type') {
    // If base page facet item is empty, hide it.
    if (empty($build['page']['#count'])) {
      unset($build['page']);
    }
  }
}

The latter solution does work... I just wish having Minimum facet count = 1 were enough.

Thanks for the great Search API module anyway !!! : ))