mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
fixed an issue with scout pagination and typesense
This commit is contained in:
parent
c42278bce8
commit
5569da4bb2
@ -190,10 +190,10 @@ abstract class SearchQueryBuilder implements SearchQueryBuilderService
|
||||
|
||||
if ($this->isSearchIndexUsed() && $this->isScoutBuilder($results)) {
|
||||
$paginated = $results
|
||||
->take($limit)
|
||||
->paginate(
|
||||
$limit,
|
||||
null,
|
||||
null,
|
||||
"page",
|
||||
$page
|
||||
);
|
||||
} else {
|
||||
|
@ -7,6 +7,16 @@ use Typesense\Documents;
|
||||
|
||||
class TypeSenseScoutSearchService implements ScoutSearchService
|
||||
{
|
||||
private int $maxItemsPerPage;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->maxItemsPerPage = (int) env('MAX_RESULTS_PER_PAGE', 25);
|
||||
if ($this->maxItemsPerPage > 250) {
|
||||
$this->maxItemsPerPage = 250;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a search operation via Laravel Scout on the provided model class.
|
||||
* @param object|string $modelClass
|
||||
@ -22,6 +32,11 @@ class TypeSenseScoutSearchService implements ScoutSearchService
|
||||
// which will make Typesense consider all variations of prefixes and typo corrections of the words
|
||||
// in the query exhaustively, without stopping early when enough results are found.
|
||||
$options['exhaustive_search'] = true;
|
||||
|
||||
if (array_key_exists('per_page', $options) && $options['per_page'] > 250) {
|
||||
$options['per_page'] = min($this->maxItemsPerPage, 250);
|
||||
}
|
||||
|
||||
$modelInstance = new $modelClass;
|
||||
// get the weights of the query_by fields, if they are provided by the model.
|
||||
if ($modelInstance instanceof JikanApiSearchableModel) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user