【问题标题】:Scout Laravel Algolia search too queriesScout Laravel Algolia search too 查询
【发布时间】:2022-01-14 06:17:11
【问题描述】:

我正在使用 Laravel scout 和 Algolia 搜索。

我有这种雄辩的关系:

public function doctors()
{
    return $this->belongsTo(Doctor::class, 'doctor_id');
}

在这里我通过 Algolia 搜索得到结果:

  $doctors = DoctorInfo::search($this->search)
                                ->with([
                                'typoTolerance' => true,
  ])
  ->paginate(10);

我收到很多单个查询:

select * from `doctors` where `doctors`.`id` = 131 limit 1
select * from `doctors` where `doctors`.`id` = 141 limit 1
select * from `doctors` where `doctors`.`id` = 191 limit 1
....

我怎样才能使用“whereIn”而不是“where”来获得一个有说服力的关系?

谢谢大家!

【问题讨论】:

    标签: laravel search eloquent algolia laravel-scout


    【解决方案1】:

    这样解决了。

    $doctors = DoctorInfo::search($this->search)
                                    ->with([
                                    'typoTolerance' => true,
      ])
       ->query(function ($builder) {
                $builder->with('doctors');
      })
      ->paginate(10);
    

    我的查询现在是独一无二的:

    select * from `doctors` where `doctors`.`id` in (12, 88, 107, 108, 111, 131, 168, 170, 175, 181)
    

    谢谢大家。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-18
      • 2017-09-03
      • 2017-04-30
      • 1970-01-01
      • 2017-10-19
      • 1970-01-01
      • 2020-01-02
      • 1970-01-01
      相关资源
      最近更新 更多