mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
- added user animelist/mangalist endpoints back - fixed issues with the container image - improved club model factory - fixed ordering while searching when search engine is disabled (mongodb based search)
37 lines
1021 B
PHP
37 lines
1021 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Jenssegers\Mongodb\Query\Builder as MongoBuilder;
|
|
|
|
final class MongoSearchService extends SearchServiceBase
|
|
{
|
|
public function search(string $searchTerms, ?string $orderByFields = null, bool $sortDirectionDescending = false): \Laravel\Scout\Builder|\Illuminate\Database\Eloquent\Builder
|
|
{
|
|
/**
|
|
* @var MongoBuilder $query
|
|
*/
|
|
$query = $this->query();
|
|
|
|
/** @noinspection PhpParamsInspection */
|
|
$builder = $query->whereRaw([
|
|
'$text' => [
|
|
'$search' => $searchTerms
|
|
],
|
|
], [
|
|
'textMatchScore' => [
|
|
'$meta' => 'textScore'
|
|
]
|
|
])->orderBy('textMatchScore', 'desc');
|
|
|
|
if ($orderByFields !== null) {
|
|
$order = explode(",", $orderByFields);
|
|
foreach ($order as $o) {
|
|
$builder = $builder->orderBy($o, $sortDirectionDescending ? 'desc' : 'asc');
|
|
}
|
|
}
|
|
|
|
return $builder;
|
|
}
|
|
}
|