Hi all,
I’m new to Algolia, and currently struggling to implement Algolia to achieve what I’m trying to do. I’m also unsure if my Model has been set up properly.
I have 2 problems at the moment:
- My model has multiple categories. The categories should be assigned to the model by a many-to-many relationship (max 3 categories per model). I have 3 subcategories per model too but I’ll get to that issue when I figure out the categories bit.
I’ve done something like this (sample category ids):
public function toSearchableArray(): array
{
$array = $this->toArray();
$array = $this->transform($array);
$array['state_id'] = $this->state->id;
$array['region_id'] = $this->region->id;
$array['categories'] = [
1,
2,
3,
];
}
When importing, the records will appear instead with:
category_1: 1,
category_2: 2,
category_3: 3,
I was hoping that it would appear as configured in the array. As I’m doing a keyword + category search like:
$query = Listing::search($keywords)
->whereIn('categories', [1]) // this line won't work for sure, this is what i'm trying to figure out
->get();
When using Eloquent, I implement this by doing
$query->whereHas('categories', function($subquery) use($input_categories) {
$subquery->whereIn('category_id', $input_categories);
});
- You’ll notice a region_id and state_id in the Model too. I’m trying to implement something that’s similar to an orWhere in Eloquent. Similar to:
$query = Listing::search($keywords)
->where('state_id', $state_id)
->orWhere('region_id', $region_id)
->get();
The results should return records that have the selected state ID, or the selected region ID. At the moment, I receive is this error:
Method Algolia\ScoutExtended\Builder::orWhere does not exist.
It looks like there’s no way to do an OR search? Or is there a better way to implement what I’m doing?