Skip to content

Commit

Permalink
add county scout index
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Oct 8, 2024
1 parent 7999ce9 commit 0721f50
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
9 changes: 0 additions & 9 deletions app/Console/Commands/RebuildScoutCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace App\Console\Commands;

use App\Models\City;
use App\Models\Material;
use App\Models\Point;
use Illuminate\Console\Command;

class RebuildScoutCommand extends Command
Expand All @@ -25,12 +22,6 @@ class RebuildScoutCommand extends Command
*/
protected $description = 'Rebuilds the search index for all searchable models';

protected array $models = [
City::class,
Material::class,
Point::class,
];

/**
* Execute the console command.
*/
Expand Down
35 changes: 35 additions & 0 deletions app/Models/County.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class County extends Model
{
use Searchable;

public $timestamps = false;

protected $fillable = [
Expand All @@ -22,4 +23,38 @@ public function cities(): HasMany
{
return $this->hasMany(City::class);
}

/**
* Get the indexable data array for the model.
*
* @return array<string, mixed>
*/
public function toSearchableArray(): array
{
return [
'id' => (string) $this->id,
'name' => $this->name,
];
}

public static function getTypesenseModelSettings(): array
{
return [
'collection-schema' => [
'fields' => [
[
'name' => 'id',
'type' => 'string',
],
[
'name' => 'name',
'type' => 'string',
],
],
],
'search-parameters' => [
'query_by' => 'name',
],
];
}
}
2 changes: 2 additions & 0 deletions config/scout.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use App\Models\City;
use App\Models\County;
use App\Models\Material;
use App\Models\Point;

Expand Down Expand Up @@ -181,6 +182,7 @@
],
'model-settings' => collect([
City::class,
County::class,
Material::class,
Point::class,
])
Expand Down

0 comments on commit 0721f50

Please sign in to comment.