optionalFilters seems not to work

I’t trying to get a dealer list, sort by location.
The way to do that is using optionalFilters in the searchForFacetValues, but seems not to work.
I’m doing this query:

this.searchCarIndex.searchForFacetValues({
    facetName: 'dealer.name',
    facetQuery: '',
    filters: '(dealer.featured:1 OR dealer.featured:true) AND region.name:"Region 1"',
    optionalFilters: ['location.name:Some Location'],
    hitsPerPage: 100,
    maxFacetHits: 100,
})

I’m sure there are dealers with the location.name = Some Location, and should appear first, but don’t.

I try like this too:
optionalFilters: ['location.name:"Some Location"'],
optionalFilters: 'location.name:"Some Location"',
optionalFilters: 'location.name:Some Location',

and nothing.
The plan is Started, so it should have available the optionals filters.
What can I do?
Thanks.

Hi @sassaroli,

Did you set the ‘attributesForFaceting’ to locaction.name?

If so, would it be possible to create a codesandbox.io to demonstrate this issue?

We have some starter templates to get you started.

I look forward to your reply!

Thanks for the reply. Yes, I set the attributesForFaceting

Also, I try to use the location.name as a filter, and it works.
I will try to replicate in codesandbox.

Thanks for those details @sassaroli!

I look forward to the codesandbox.

Also, make sure that you still have ‘filters’ in your ranking and sorting configuration. They are there by default, but if you have removed them, the optionalFilters will not work.

Ok, thanks again.
Yes, the filters is in my ranking criteria.
Here is the sandbox, you can check in the console, the output of the searchForFacetValues

The result remain order by count.
And should appears first:

  • Murray GM Abbotsford
  • Magnuson Ford
  • Open Road Toyota Abbotsford
  • MSA Ford

Hi @sassaroli,

I will need to see your data and configuration.

Can you send a message to support@algolia.com.

Please include all the information you’ve included here and a link to the codesandbox.

Thanks in advance!

Hi @cindy.cullen, I already sent the email.
Thanks.

Algolia support confirm that optionalFilters doesn’t work with searchForFacetValues :disappointed_relieved:

“I have just checked with our Search API team. The searchForFacetValues method accepts this parameter without throwing an error, but it does not actually boost the said facets.”

So, we need to find another way to do this.

Thanks.

Hi all,

Yes indeed, I can confirm like @sassaroli just said that, for now, searchForFacetValues can only be sorted by count or in alphabetical order, and adding optionalFilters will have no effect on this method.

The docs will be updated shortly to reflect this, and the product team is aware of this feature request.

Sorry for the inconvenience!