Php Algolia条件搜索
我的Algolia引擎中有下一个“实体” 我喜欢只搜索那些状态为1的。 我试过这个:Php Algolia条件搜索,php,search,algolia,Php,Search,Algolia,我的Algolia引擎中有下一个“实体” 我喜欢只搜索那些状态为1的。 我试过这个: $searchResult = $this->get('algolia.indexer')->rawSearch(Professional, $data, [ 'hitsPerPage' => 10, 'page' => 1, 'facetFilters' => 'status:1', ]);
$searchResult = $this->get('algolia.indexer')->rawSearch(Professional, $data, [
'hitsPerPage' => 10,
'page' => 1,
'facetFilters' => 'status:1',
]);
似乎im没有正确使用facetFilters,
有什么帮助吗?
谢谢据我所知,您在
状态
属性中有子属性id
。因此,您的记录如下所示:
{
"objectID": "eyJpZCI6OX0=",
...
"status": {
"id": 1
}
}
$searchResult = $this->get('algolia.indexer')->rawSearch(Professional, $data, [
'hitsPerPage' => 10,
'page' => 1,
'facetFilters' => 'status.id:1',
]);
$client = new \AlgoliaSearch\Client('foo', 'bar');
$index = $client->initIndex('index_name');
$res = $index->search('', ['filters' => 'status.id:1']);
对吗
在这种情况下,还需要在facetFilters
中指定子属性。在您的情况下,它将如下所示:
{
"objectID": "eyJpZCI6OX0=",
...
"status": {
"id": 1
}
}
$searchResult = $this->get('algolia.indexer')->rawSearch(Professional, $data, [
'hitsPerPage' => 10,
'page' => 1,
'facetFilters' => 'status.id:1',
]);
$client = new \AlgoliaSearch\Client('foo', 'bar');
$index = $client->initIndex('index_name');
$res = $index->search('', ['filters' => 'status.id:1']);
如果使用,代码将如下所示:
{
"objectID": "eyJpZCI6OX0=",
...
"status": {
"id": 1
}
}
$searchResult = $this->get('algolia.indexer')->rawSearch(Professional, $data, [
'hitsPerPage' => 10,
'page' => 1,
'facetFilters' => 'status.id:1',
]);
$client = new \AlgoliaSearch\Client('foo', 'bar');
$index = $client->initIndex('index_name');
$res = $index->search('', ['filters' => 'status.id:1']);
您还可以逐个参数替换
FaceFilters
参数,这更强大,允许您指定更复杂的条件。您是否将状态设置为attributeforface()?@janpert是的。