Have items without the facet be present in facet search


we’re currently using:

  • algoliasearch ^4.8.0
  • react-instantsearch-dom 6.6.0

and would like to solve the following scenarion:

Some items [A, B, C] do not have values for the facet X. Now whenever a search for X is triggered, all three items disappear from the result set. Instead, we want to display them among the rest (preferably in the last positions, but this is not a hard requirement).

We’ve tried with rules, setting a boolean and trying to include that in the search but so far have not managed to solve this.

Is this possible with Algolia? Is there something elemental we’re missing?

Hi @mrehberger,

Algolia requires a value in order to search or filter for a record. Algolia cannot act on null values or missing attributes. We created a guide to help understand how to work with these types of situations:

Hey @ajay.david, thanks for your reply. Sorry, if I was unclear: I am aware of the situation and have read the linked article.

Let me rephrase:

If we set a boolean or tag on items that do not have a value, how can I update the filter / create rules, so these are included when searching for the facet?

Since the search logic is abstracted behind react-instantsearch-dom, we cannot just do an OR query on our own (or we have not found out how yet). As with rules we’ve also been unable to solve this.

Facet is myfacet with possible values 0, 5, 10.

Now I have the following items

name  | myfacet
A     | 0
B     | 5
C     | 10
D     | 5
E     | -
F     | -

We retrieve all possible facet values directly from Algolia and use the HoC connectRefinementList on the facet selection - which afaik creates the behind-the-scenes magic that when in a InstantSearch container, automatically does the search and populate the Hits.

So how can I make it that when a user selects 5, the items that are displayed are [B, D, E, F]?

Hi @mrehberger,

connectRefinementList is correct as it enables you to retain access to the widget parameters and sort/filter/modify the output values. For example, use the transformItems option to display facets when they have no hits (zero results):

The key here is that connectors are how you can customize the widget.

I hope this helps you achieve your desired UI by showing the flexibility and where you might further customize the values that are given to the refinement list widget.