简体   繁体   中英

Scout Laravel Algolia search too queries

I'm using Laravel scout with Algolia search.

I have this eloquent relation:

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

Here I get results by Algolia search:

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

I get a lot of single queries:

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
....

How can I get an eloquent relation using "whereIn" instead "where"?

thanks to all!

Solved in this way.

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

My query is unique now like this:

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

Thanks for all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM