mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
fixes order_by not working when a query is passed via typesense
This commit is contained in:
parent
2b67dc0d26
commit
55229901ab
@ -48,12 +48,18 @@ abstract class SearchRequestHandler implements RequestHandler
|
||||
|
||||
protected function prepareOrderByParam(Collection $requestData): Collection
|
||||
{
|
||||
if ($requestData->has("order_by") && $requestData->get("order_by") instanceof Enum) {
|
||||
$requestData->offsetSet("order_by", $requestData->get("order_by")->label);
|
||||
} else {
|
||||
$requestData->offsetSet("order_by", 'mal_id');
|
||||
if (!$requestData->has('order_by') || !$requestData->get('order_by') instanceof Enum) {
|
||||
$requestData->offsetSet('order_by', 'mal_id');
|
||||
return $requestData;
|
||||
}
|
||||
|
||||
if ($requestData->has('order_by') && $requestData->has('q')) {
|
||||
$requestData->offsetSet("order_by", $requestData->get("order_by")->label);
|
||||
return $requestData;
|
||||
|
||||
}
|
||||
|
||||
$requestData->offsetSet("order_by", 'mal_id');
|
||||
return $requestData;
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +65,11 @@ class TypeSenseScoutSearchService implements ScoutSearchService
|
||||
$options['sort_by'] = "_text_match:desc,$orderByField:" . ($sortDirectionDescending ? "desc" : "asc");
|
||||
}
|
||||
|
||||
// if order_by is a user supplied value make it a priority over _text_match
|
||||
if ($orderByField !== 'members' && !is_null($orderByField)) {
|
||||
$options['sort_by'] = "$orderByField:" . ($sortDirectionDescending ? "desc" : "asc") . ",_text_match:desc";
|
||||
}
|
||||
|
||||
// override overall sorting direction
|
||||
if (is_null($orderByField) && $sortDirectionDescending && array_key_exists("sort_by", $options) && Str::contains($options["sort_by"], "asc")) {
|
||||
$options["sort_by"] = Str::replace("asc", "desc", $options["sort_by"]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user