Laravel scout algolia 地理搜索

Laravel scout algolia geosearch

我正在尝试使用 geoSearch 参数向我的 algolia 索引发出请求。在搜索后添加 whereDate 和所有 where 参数之前,我的查询一直有效。

你能告诉我如何正确地执行请求吗?

谢谢

return Event::search('', function ($algolia, $query, $options) use ($lat, $lng, $radius){
            $location = [
              'aroundLatLng' => $lat.','.$lng,
              'aroundRadius' => $radius * 1000,
            ];

            $options = array_merge($options, $location);

            return $algolia->search($query, $options);
        })->whereDate('start_at', \Carbon\Carbon::parse($day))->where('end_at', '>=',
          \Carbon\Carbon::parse($day))->orWhere('start_at', '<=', \Carbon\Carbon::parse($day))->where('end_at',
          '>=', \Carbon\Carbon::parse($day))->orderBy('events.start_at')->orderBy('events.start_at')->get();

我认为最好的方法是在 Algolia 中也添加 where 语句。 Laravel Scout 仅处理简单的 where 子句(仅 = 到数字)。

    return Event::search('', function ($algolia, $query, $options) use ($lat, $lng, $radius){
        $custom = [
          'aroundLatLng' => $lat.','.$lng,
          'aroundRadius' => $radius * 1000,
          'filters' => 'start_at>12 AND end_at<16',
        ];

        $options = array_merge($options, $custom);

        return $algolia->search($query, $options);
    })->get();

您可以在此处找到与过滤器相关的文档:https://www.algolia.com/doc/guides/searching/filtering/