Laravel侦察员algolia geosearch

时间:2017-11-10 14:44:51

标签: php laravel search algolia

我试图用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();

1 个答案:

答案 0 :(得分:0)

我认为最好的方法是在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/