0

I have in my Algolia engine the next "entity"

Professional
objectID: "eyJpZCI6OX0="
...
status: id: 1

And I like to make a search just with the ones that have status = 1. I've tried this:

$searchResult = $this->get('algolia.indexer')->rawSearch(Professional, $data, [
            'hitsPerPage' => 10,
            'page' => 1,
             'facetFilters' => 'status:1',
      ]);

Seems that im nos using facetFilters correctly, any help? Thanks

Sergio González
  • 142
  • 2
  • 12

1 Answers1

1

From what I can see you have sub-attribute id inside the status attribute. So your record looks something like this:

{
  "objectID": "eyJpZCI6OX0=",
  ...
  "status": {
    "id": 1
  }
}

Correct?

In this case you need to specify the sub-attribute in your facetFilters as well. In your case it would look like this:

$searchResult = $this->get('algolia.indexer')->rawSearch(Professional, $data, [
    'hitsPerPage' => 10,
    'page' => 1,
    'facetFilters' => 'status.id:1',
]);

If you use Algolia PHP API client, the code would look like this:

$client = new \AlgoliaSearch\Client('foo', 'bar');
$index = $client->initIndex('index_name');

$res = $index->search('', ['filters' => 'status.id:1']);

You can also replace facetFilters parameter by filters parameter, which is more powerful and allows you to specify more complex conditions.

Jan Petr
  • 685
  • 5
  • 11