algolia / algoliasearch-client-android

Algolia Search API Client for Android
MIT License
99 stars 29 forks source link

Problem with filters #532

Closed RafaRuiz closed 6 years ago

RafaRuiz commented 6 years ago

First of all I have to say that the language I'm using is Kotlin.

I'm trying to get rid of legacy code and convert all query.faceFilters = to query.filters = (set functions).

What I was using (and it was working) in this issue was: query.facetFilters = JSONArray("[\"$filteringCategoryFacet:$categoryFilter\"]")

but since it's deprecated, it worked with: query.filters = "$filteringCategoryFacet:$categoryFilter"

Case working:

val filteringCategoryFacet = "category.lvl1"
val categoryFilter = "Womens"

so I would be inserting: query.filters = "category.lvl1:Womens"

Case not working

val filteringCategoryFacet = "category.lvl2"
val categoryFilter = "Womens>Tailoring"

so I would be inserting query.filters = "category.lvl2:Womens>Tailoring"

which results in the error: com.algolia.search.saas.AlgoliaException: filters: Unexpected token > expected end of filter at col 20

I tried to replace > by %3E. It didn't throw an error but it didn't give me any result, as query.faceFilters was giving some.

What is wrong with it?

RafaRuiz commented 6 years ago

Solved quoting categoryFilter:

        query.filters = "$filteringCategoryFacet:\"$categoryFilter\""

Beware.

PLNech commented 6 years ago

Hi @RafaRuiz, thanks for your report! Glad to see you could resolve it directly, hopefully this will be helpful to anyone else experiencing the same.