`#multiple_queries` does not accept a params Hash as documented
vincedevendra opened this issue · 1 comments
Description
The Ruby API documentation for #multiple_queries
shows that the method should accept an array of query objects that look like this:
{
indexName: "indexName",
type: "default", // optional
query: "search query",
params: {
searchParameter1: value1, // one or several search parameters
searchParameter2: value2
}
}
But, when I try to pass such an object, I get back a 400 error: Algolia::AlgoliaHttpError (400: Object forbidden at this position near line:1 column:55)
It seems like what the method is actually expecting is that the params be url form encoded, something like this:
{
indexName: "indexName",
type: "default", // optional
query: "search query",
params: "searchParameter1=value1&searchParameter2=value2"
}
Your tests seem to confirm this
results = @@search_client.multiple_queries([
{ indexName: index_name1, params: to_query_string({ query: '', hitsPerPage: 2 }) },
{ indexName: index_name2, params: to_query_string({ query: '', hitsPerPage: 2 }) }
], { strategy: 'none' })[:results]
It would be far more convenient if the method took a params Hash rather than a form encoded string, especially because that's the format that the InstantSearch.js produces--my use case involves proxying InstantSearch.js generated requests through our Ruby backend to enrich results. I'm not able to just pass the requests
request body array straight into #multiple_queries
, but have to map through it and form encode the params first.
Steps To Reproduce
- Format an array of queries according to the documentation, where the value of the
params
key is a Hash. - Pass that array into
#multiple_queries
. - Observe a 400 error.
Fully agree with you here: accepting a hash is way more convenient. We need to make this change with BC in mind, though. I'll try something next week, unless you have time to create a PR for this 🙂