mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-03-17 19:03:13 -05:00
update: cache 1-2-character quicksearch results
Meilisearch seems to be a bit slow sometimes for 1 character searches (300ms delay) since it tries to count the total count accurately. Normally meilisearch has a maxTotalHits of 1000, but we have it set to the number of torrents plus 1000 so that we can have accurate page counts. This causes some additional lag for the quick search which only returns the top 20 results. Every cache entry uses approximately 12kB from some quick testing, so 2 character is ~30 MB, while 3 characters is ~1.5 GB. Only cache up to 2 characters for now as a result.
This commit is contained in:
@@ -72,6 +72,22 @@ class QuickSearchController extends Controller
|
||||
->setIndexUid(config('scout.prefix').'torrents')
|
||||
->setQuery($searchById ? '' : $query)
|
||||
->setFilter($filters)
|
||||
->setAttributesToRetrieve([
|
||||
'id',
|
||||
'name',
|
||||
'tmdb_movie_id',
|
||||
'tmdb_tv_id',
|
||||
'category.id',
|
||||
'category.name',
|
||||
'category.movie_meta',
|
||||
'category.tv_meta',
|
||||
'tmdb_movie.name',
|
||||
'tmdb_movie.year',
|
||||
'tmdb_movie.poster',
|
||||
'tmdb_tv.name',
|
||||
'tmdb_tv.year',
|
||||
'tmdb_tv.poster',
|
||||
])
|
||||
->setDistinct('imdb')
|
||||
];
|
||||
|
||||
@@ -79,12 +95,24 @@ class QuickSearchController extends Controller
|
||||
if (!$searchById) {
|
||||
$searchQueries[] = (new SearchQuery())
|
||||
->setIndexUid(config('scout.prefix').'people')
|
||||
->setQuery($query);
|
||||
//->setFederationOptions((new FederationOptions())->setWeight(0.9));
|
||||
->setQuery($query)
|
||||
->setAttributesToRetrieve([
|
||||
'id',
|
||||
'name',
|
||||
'birthday',
|
||||
'still',
|
||||
]);
|
||||
}
|
||||
|
||||
// Perform multi-search with MultiSearchFederation
|
||||
$multiSearchResults = $client->multiSearch($searchQueries, ((new MultiSearchFederation()))->setLimit(20));
|
||||
|
||||
$searchQuery = fn () => $client->multiSearch($searchQueries, ((new MultiSearchFederation()))->setLimit(20));
|
||||
|
||||
if (preg_match("/^[a-zA-Z0-9-_ .'@:\\[\\]+&\\/,!#()?\"]{1,2}$/", $query)) {
|
||||
$multiSearchResults = cache()->remember('quick-search:'.strtolower($query), 3600 * 24, $searchQuery);
|
||||
} else {
|
||||
$multiSearchResults = $searchQuery();
|
||||
}
|
||||
|
||||
$results = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user