Skip to content

Commit

Permalink
Merge pull request #4243 from HDInnovations/Quicksearch-by-ID
Browse files Browse the repository at this point in the history
  • Loading branch information
HDVinnie authored Oct 19, 2024
2 parents b4fde63 + c63c279 commit da290de
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions app/Http/Controllers/API/QuickSearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,39 @@ public function index(Request $request): \Illuminate\Http\JsonResponse
];

// Check if the query is an IMDb or TMDB ID
$searchById = false;

if (preg_match('/^(\d+)$/', $query, $matches)) {
$filters[] = 'tmdb = '.$matches[1];
$searchById = true;
}

if (preg_match('/tt0*(?=(\d{7,}))/', $query, $matches)) {
$filters[] = 'imdb = '.$matches[1];
$searchById = true;
}

$client = new Client(config('scout.meilisearch.host'), config('scout.meilisearch.key'));

// Perform multi-search
$multiSearchResults = $client->multiSearch([
// Prepare the search queries
$searchQueries = [
(new SearchQuery())
->setIndexUid('torrents')
->setQuery($query)
->setQuery($searchById ? '' : $query)
->setFilter($filters)
->setDistinct('imdb'),
(new SearchQuery())
->setDistinct('imdb')
];

// Add the people search query only if it's not an ID search
if (!$searchById) {
$searchQueries[] = (new SearchQuery())
->setIndexUid('people')
->setQuery($query)
->setFederationOptions((new FederationOptions())->setWeight(0.9)),
], ((new MultiSearchFederation()))->setLimit(20));
->setQuery($query);
//->setFederationOptions((new FederationOptions())->setWeight(0.9));
}

// Perform multi-search with MultiSearchFederation
$multiSearchResults = $client->multiSearch($searchQueries, ((new MultiSearchFederation()))->setLimit(20));

$results = [];

Expand Down

0 comments on commit da290de

Please sign in to comment.