Search for facet values

I have a working index and operational InstantSearch.js GUI.
I have added, as per the documentation

searchForFacetValues: {
  placeholder: 'Chercher un prénom',
  templates: {
    noResults: '<div class="text">Pas de prénom correspondant.</div>'
  }
},

within the corresponding search.addWidget function.

The search bar appears all right, I can type into the bar, but when I hit return, the first value of the facets list turns on independently of the content of the search bar.

What am I doing wrong?
Thanks
Henri

Hello Henri,

do you mean that if you search something in searchForFacetValues, and you press enter, the first result gets refined? And you’d rather have it refined on whatever the user typed?

Could you make a small fiddle with that behaviour so we can see exactly what you mean?

Thanks!

I have a small fiddle (first time I use this tool/service!!) called Test Algolia (Henri).
Quite rough, no css, missing results, but the facet windows is there and behaves as I observed and as you described (first facet result gets defined rather than the content of the search box).
Can you see it?
Here is the link to “invite a friend”: https://jsfiddle.net/#&togetherjs=SdoHlkk5VF

Cheers,
Henri

1 Like

Hey!

To be able to use searchForFacetValues, you need to add that facet your searchableAttributes like this:

index.setSettings({
  searchableAttributes: [
   // other ones
  "searchable(firstnames)",
]});

You can do this with the dashboard too

By the way, the error in the console says this too:

Unhandled Promise Rejection: AlgoliaSearchError: Cannot search in `firstnames` attribute, you need to add `searchable(firstnames)` to attributesForFaceting.

firstnames is a searchable attribute (with the dashboard)!
On my console, I do not have the error you indicate!
Inserting the lines of code above (with other attributes) fails completely!

SyntaxError: expected expression, got ‘…’
[En savoir plus]

I could not find running examples where index.setSettings is used!

Henri

Hey there,

Not sure if this was clear, but in the dashboard it needs to be searchable(firstnames), not firstnames, so that search for facet values works.

The snippet I shared is something you can do in node.js or any other backend language after you initialised the index. If you don’t already set your settings programmatically, it’s simpler to do it with the dashboard.

Can you send a screenshot of your searchableAttributes if it still doesn’t work?

Have a nice day!

I dont see how to do otherwise ???

:

sorry, it’s Monday, I meant attributesForFaceting

Ca marche, it works!

Thank you
Henri

1 Like

Sorry for the confusion, enjoy integrating Algolia!