mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
Merge pull request #437 from jikan-me/hotfix/search2
Fixed bug around non anime/manga search
This commit is contained in:
commit
28ff8a20b0
@ -93,4 +93,9 @@ class Character extends JikanApiSearchableModel
|
||||
'name_kanji'
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitleAttributeName(): string
|
||||
{
|
||||
return 'name';
|
||||
}
|
||||
}
|
||||
|
@ -98,4 +98,9 @@ class Club extends JikanApiSearchableModel
|
||||
{
|
||||
return ['name'];
|
||||
}
|
||||
|
||||
public function getTitleAttributeName(): string
|
||||
{
|
||||
return 'name';
|
||||
}
|
||||
}
|
||||
|
@ -73,4 +73,9 @@ class GenreAnime extends JikanApiSearchableModel
|
||||
'name'
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitleAttributeName(): string
|
||||
{
|
||||
return 'name';
|
||||
}
|
||||
}
|
||||
|
@ -72,4 +72,9 @@ class GenreManga extends JikanApiSearchableModel
|
||||
'name'
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitleAttributeName(): string
|
||||
{
|
||||
return 'name';
|
||||
}
|
||||
}
|
||||
|
@ -88,4 +88,9 @@ abstract class JikanApiSearchableModel extends JikanApiModel implements Typesens
|
||||
}
|
||||
return preg_replace("/[^[:alnum:][:space:]]/u", ' ', $val) ?? "";
|
||||
}
|
||||
|
||||
public function getTitleAttributeName(): string
|
||||
{
|
||||
return 'title';
|
||||
}
|
||||
}
|
||||
|
@ -78,4 +78,9 @@ class Magazine extends JikanApiSearchableModel
|
||||
'name'
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitleAttributeName(): string
|
||||
{
|
||||
return 'name';
|
||||
}
|
||||
}
|
||||
|
@ -104,4 +104,9 @@ class Person extends JikanApiSearchableModel
|
||||
"alternate_names"
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitleAttributeName(): string
|
||||
{
|
||||
return 'name';
|
||||
}
|
||||
}
|
||||
|
@ -77,4 +77,9 @@ class Producers extends JikanApiSearchableModel
|
||||
'titles'
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitleAttributeName(): string
|
||||
{
|
||||
return 'titles';
|
||||
}
|
||||
}
|
||||
|
@ -62,13 +62,15 @@ class TypeSenseScoutSearchService implements ScoutSearchService
|
||||
}
|
||||
|
||||
$modelInstance = $this->repository->createEntity();
|
||||
$modelTitleAttributeName = "title";
|
||||
|
||||
if ($modelInstance instanceof JikanApiSearchableModel) {
|
||||
$options = $this->setQueryByWeights($options, $modelInstance);
|
||||
$options = $this->setSortOrder($options, $modelInstance);
|
||||
$options = $this->overrideSortingOrder($options, $modelInstance, $orderByField, $sortDirectionDescending);
|
||||
$modelTitleAttributeName = $modelInstance->getTitleAttributeName();
|
||||
}
|
||||
$options = $this->adaptToShortQueries($query, $options);
|
||||
$options = $this->adaptToShortQueries($query, $modelTitleAttributeName, $options);
|
||||
|
||||
$results = $documents->search($options);
|
||||
$this->recordSearchTelemetry($query, $results);
|
||||
@ -77,7 +79,7 @@ class TypeSenseScoutSearchService implements ScoutSearchService
|
||||
};
|
||||
}
|
||||
|
||||
private function adaptToShortQueries(string $query, array $options): array
|
||||
private function adaptToShortQueries(string $query, string $modelTitleAttributeName, array $options): array
|
||||
{
|
||||
if (strlen($query) <= 3) {
|
||||
$options['num_typos'] = 0;
|
||||
@ -87,15 +89,19 @@ class TypeSenseScoutSearchService implements ScoutSearchService
|
||||
$options['infix'] = 'off';
|
||||
$options['prioritize_token_position'] = 'true';
|
||||
|
||||
if (Str::startsWith($options["sort_by"], "_text_match")) {
|
||||
$options["sort_by"] = "_text_match:desc,title:asc";
|
||||
if (array_key_exists("sort_by", $options)) {
|
||||
if (Str::startsWith($options["sort_by"], "_text_match")) {
|
||||
$options["sort_by"] = "_text_match:desc," . $modelTitleAttributeName .":asc";
|
||||
} else {
|
||||
// move text_match to the beginning if there is an orderby parameter set.
|
||||
$options["sort_by"] = Str::replace("(buckets:". $this->jikanConfig->textMatchBuckets().")", "", $options["sort_by"]);
|
||||
$parts = collect(explode(",", $options["sort_by"]));
|
||||
$last = $parts->pop();
|
||||
$parts = $parts->prepend($last);
|
||||
$options["sort_by"] = $parts->implode(",");
|
||||
}
|
||||
} else {
|
||||
// move text_match to the beginning if there is an orderby parameter set.
|
||||
$options["sort_by"] = Str::replace("(buckets:". $this->jikanConfig->textMatchBuckets().")", "", $options["sort_by"]);
|
||||
$parts = collect(explode(",", $options["sort_by"]));
|
||||
$last = $parts->pop();
|
||||
$parts = $parts->prepend($last);
|
||||
$options["sort_by"] = $parts->implode(",");
|
||||
$options["sort_by"] = "_text_match:desc," . $modelTitleAttributeName .":asc";
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,7 +128,9 @@ class TypeSenseScoutSearchService implements ScoutSearchService
|
||||
$sortBy .= ',';
|
||||
}
|
||||
$sortBy = rtrim($sortBy, ',');
|
||||
$options['sort_by'] = $sortBy;
|
||||
$options["sort_by"] = $sortBy;
|
||||
} else if (is_null($sortByFields) && !array_key_exists("sort_by", $options)) {
|
||||
$options["sort_by"] = "_text_match:desc";
|
||||
}
|
||||
|
||||
return $options;
|
||||
|
Loading…
x
Reference in New Issue
Block a user