【问题标题】:Laravel scout algolia geosearchLaravel 侦察员阿尔戈利亚地理搜索
【发布时间】:2017-11-10 14:44:51
【问题描述】:

我正在尝试使用 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();

【问题讨论】:

    标签: php laravel search algolia


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-17
      相关资源
      最近更新 更多