Querying multiple terms in multiple fields

Using Algolia PHP Client version = 1.17.0

I was wondering if there was a way of doing an Algolia search using multiple terms for multiple queries. (Like in Elasticsearch/Solr)

{"field1": "hello", "field2": "world"}

The fields would be analyzed and indexed for search to match the given terms (Not a facet/filter).

Currently, the API sets the query and filters in params. Can’t figure out a way if this could be done.

Thanks.

Hi there,

Thanks for reaching out!
I am not familiar with how ES/Solr are handling this, but from what I understand, it looks like a combination of multipleQueries and restrictSearchableAttributes would do the trick.

The idea would be to craft a first query with restrictSearchableAttributes set to field1 and a second one with restructSearchableAttributes set to field2.
You would then be able to perform simultaneously the 2 queries by sending them with multipleQueries.

Let me know what you think!

@leo.ercolanelli Thanks for telling me about the multiQueries feature. It’s docs aren’t too comprehensive though.

Managed to get it working somehow.

Thanks.

I am sorry to hear reading the documentation wasn’t as straightforward as it should have been. Do you have any feedback to share on how we could improve it? What were you missing?

@leo.ercolanelli

First, I was trying it like this:

$queries = array()

$args = array( 'filters' => implode(' AND ', $filters), 'length' => 10, 'offset' => 0 );

$args1 = $args;

$args['restrictSearchableAttributes'] = 'field';
$args1['restrictSearchableAttributes'] = 'field1';

$queries[] = array('indexName' => 'my_index', 'query' => $q, $args); $queries[] = array('indexName' => 'my_index', 'query' => $q1, $args);

Then I had to look into the buildQuery function 1 to see how a normal query is processed (adding the $q to the $args in the 'query' key).

Maybe it was straightforward and I was unable to infer from the docs (I’m still an Algolia newbie).

Thanks for your help.