Skip to content

Commit

Permalink
docs and final touch for increased search limit
Browse files Browse the repository at this point in the history
  • Loading branch information
kainiklas committed Apr 18, 2024
1 parent 790cf4e commit dde0905
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,43 @@ class ListMyResources extends ListRecords
}
```

The table defined in the resource needs to be `searchable()` as described in the [Filament table docs](https://filamentphp.com/docs/3.x/tables/advanced#searching-records-with-laravel-scout). Making each column searchable is not required anymore, as the content of what is searchable is defined within scout.
The table defined in the resource needs to be `searchable()` as described in the [Filament table docs](https://filamentphp.com/docs/3.x/tables/advanced#searching-records-with-laravel-scout).
Making each column searchable is not required anymore, as the content of what is searchable is defined within scout.

### Increase the number of search results

Depending on the scout engine you may have limitations on how many search results you get back.
This can be adjusted in two places:

#### 1. Search Limit

Add the following `env` variable to adjust the limit of search results:

```
SCOUT_SEARCH_LIMIT=100
```

`100` is the default value within this pagacke.
For example meilisearch has a default limit of `20`.

#### 2. Index Settings (Example for meilisearch)

Within meilisearch there is a default limit of `1000` total hits which is also the upper bound for the search limit.
That means if you want to have more than `1000` search results, you need to adapt both: the search limit and the index settings.
The index settings can be adjusted within `config\scout.php`:

```php
'index-settings' => [
MyClass::class => [
'pagination' => [
'maxTotalHits' => 10000
],
],
],
```

Then run the following command to sync the settings: `php artisan scout:sync-index-settings`


## Global Search

Expand Down
2 changes: 1 addition & 1 deletion config/kainiklas-filament-scout.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

// config for Kainiklas/FilamentScout
return [
'search_limit' => env('SEARCH_LIMIT', 100),
'scout_search_limit' => env('SCOUT_SEARCH_LIMIT', 100),
];
4 changes: 2 additions & 2 deletions src/Traits/InteractsWithScout.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ protected function applySearchToTableQuery(Builder $query): Builder
return $query;
}

$searchLimit = config('kainiklas-filament-scout.search_limit');
$searchLimit = config('kainiklas-filament-scout.scout_search_limit');
$primaryKeyName = app($this->getModel())->getKeyName();

$keys = $this->getModel()::search($search)
->query(function ($query) use ($primaryKeyName) {
$query->select($primaryKeyName);
})
->paginate($searchLimit, page: 1) // use first page, pagination is done later
->paginate($searchLimit, page: 1) // stick with first page, pagination is done later by filament
->pluck($primaryKeyName);

return $query->whereIn($primaryKeyName, $keys);
Expand Down

0 comments on commit dde0905

Please sign in to comment.