How to do query with the "LIKE%" mechanic on facets

Hi all,
I’m trying to write a piece of code for hierarchical facets, and I need to get facet values with searchForFacetValues function.
How I can fill the facetQuery option if i want that my results starts with a given string?

In other words, i need the corresponding of LIKE ‘string%’


Hi Sara,

thanks for your question.
The searchForFacetValues should behave like a regular search meaning that you don’t need to provide the exact facetQuery and can just pass a prefix for it.
Just note that you first need to declare the facetName in the attributesForFacetting list (see documentation).

Hope that helps!

Hi Marc, thanks for your answer.

My main problem is that i need to get all facets starting, for example, with "DOC > ", and if i pass "DOC > " as facetQuery, it returns all facets starting with "DOC > ", followed by all facets starting with "DOCG > ".
For this reason i want to emulate the behavior of sql’s LIKE%