algolia / algoliasearch-client-swift

⚑️ A fully-featured and blazing-fast Swift API client to interact with Algolia.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Facet values with certain characters don't work

mschinis opened this issue Β· comments

Describe the bug πŸ›
I am currently using this library to build the requests sent to algolia, and noticed than when a value has a special character like & it is not percent encoded, leading to an incorrect query and the request failing.

If I percent encode it myself, before passing it in the library, the library then, double percent encodes it, leading to 0 results.

Culprit

.map { "\($0.name)=\($0.value?.addingPercentEncoding(withAllowedCharacters: .urlAllowed) ?? "")" }

Expected behavior πŸ’­
The library should percent encode, allowing only alpha numerics instead of url allowed

Hi @mschinis,
Could you give a concrete example of a parameter leading to failure?
I made a test of query with & and the url encoding works as expected.

let query = Query().set(\.query, to: "request with &")
print(query.urlEncodedString) // query=request%20with%20%26

Hi @VladislavFitz,

Sure, the issue I'm having is for facet values. I should have mentioned that I'm also using InstantSearchCore for building these requests like so:

        let queryBuilder = QueryBuilder(
            query: "Ostrich wall lamp",
            disjunctiveFacets: [
                // ..
            ],
            filterGroups: [ 
                FilterGroup.And(
                    filters: [
                        FacetFilter(attribute: "manufacturer", stringValue: "&Quirky")
                    ],
                    name: "manufacturer"
                )
                // ...
            ],
            hierarchicalAttributes: [
                // ..
            ],
            hierachicalFilters: [
                // ..
            ]
        )

Executing the above query, results in the following:

Screenshot 2022-03-22 at 12 50 59

After looking at this further, might be related to how InstantSearchCore is using AlgoliaSearchClient πŸ€”