Non exclusive facet filter

Hello, I am looking to set up a non-exclusive facet system.

My records all have a ‘tab’ (string) field

In my search results I have tabs that allow my user to filter his search according to tab.

If no tab is selected, no pb.
But if he selects a tab then the facet that goes up tabs only returns the selected tab.


        $requestOptions = [];
        $requestOptions['facets'] = ['tab'];

        $filters = [];

        if ($search->getTab()) {
            $filters[] = 'tab:' . $search->getTab();
        }

        if ($filters) {
            $requestOptions['filters'] = implode(' AND ', $filters);
        }

        $index->search($queryString, $requestOptions)

I can’t find an elegant solution to do this.

it looks like a facet. But one non-eliminating facet…

For the moment I have to make 2 requests.

  1. One without the filter of the selected tab which returns me in the facet the list of tabs and the count.
  2. One with the filter of the selected tab which returns me the result of the search but in the facet there is only the selected tab (and not the others)

Is it possible to do this in a single query?

Hi @RemyL – I think I’m following what you’re trying to accomplish. The Menu widget is typically the best fit for this type of category faceting where the end-user can only select a single value.

Here’s a live example:
https://instantsearchjs.netlify.app/stories/js/?path=/story/refinements-menu--default

That’s right.
But using the php api from the server.

I was advised to use this: Search multiple indices API Reference | Algolia.