Configuring Index so each product belongs to multiple facets

Hi there,

I’m new to algolia and trying to set up my index in a way to allow each product to belong to multiple facets. In our case, we want to be able to have a faceted search by color, but each product should actually have 2+ colors associated with it. I wasn’t able to find anything similar in the forums, so maybe I’m thinking about this the wrong way and need to be using a different tool.

Hi there,

You can specify multiple facets values for a the same facet (color in your case). You only need to use an array.
Have you checked this documentation: https://www.algolia.com/doc/guides/searching/faceting/?language=scala#declaring-attributes-for-faceting?

Best,

Thanks. I’ll try that.

I did see that documentation, but from what I can tell, it doesn’t mention the case where a single record will have 2+ values for the same facetable property.

@rcs this didn’t work. It seems that the faceting tool expects a single attribute with a single value for each item. All of my records currently have colors: ["color1", "color2"].

My faceting widget is

instantSearch.widgets.refinementList({
    container: '#refinement-list',
    attributeName: 'colors'
})

Nothing is rendered. I have added colors as a faceted attribute in the dashboard.

However, I have another (outdated) attribute of the form options: {color: "color1"}.
Using the following “works” in that it displays and processes faceting, but only for a single color (all records with the above format only have a single color associated).

instantSearch.widgets.refinementList({
   container: '#refinement-list',
   attributeName: 'options.color'
})

So as it stands, it seems impossible to have records with an attribute containing more than one option, and to use that attribute as the basis for a faceted search.

Maybe focusing on the desired outcome instead of the implementation would help. I want:

  • a product has two colors associated with it (ideally under a single attribute)
  • if the user chose to facet search for blue the product shows up, AND if the user facets for red, the product also shows up.

Khaled

Overnight, the problem has solved itself. The code listed above is the same, but the facets are displaying and working correctly now. I have no idea why.