Fix search

This commit is contained in:
Adam Lavin 2021-04-17 04:49:06 +01:00
parent 6b2ae80414
commit 106dfc14b6
No known key found for this signature in database
GPG key ID: 9C4C68AFA9CA6461

View file

@ -27,6 +27,7 @@ use App\Models\User;
use Elasticsearch\Client; use Elasticsearch\Client;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
class Search class Search
@ -61,6 +62,7 @@ class Search
'query' => [ 'query' => [
'multi_match' => [ 'multi_match' => [
'query' => $query, 'query' => $query,
'type' => 'phrase_prefix',
'fields' => [ 'fields' => [
'title^3', 'title^3',
'artist^2', 'artist^2',
@ -80,6 +82,7 @@ class Search
'query' => [ 'query' => [
'multi_match' => [ 'multi_match' => [
'query' => $query, 'query' => $query,
'type' => 'phrase_prefix',
'fields' => [ 'fields' => [
'title^2', 'title^2',
'artist', 'artist',
@ -97,6 +100,7 @@ class Search
'query' => [ 'query' => [
'multi_match' => [ 'multi_match' => [
'query' => $query, 'query' => $query,
'type' => 'phrase_prefix',
'fields' => [ 'fields' => [
'title^3', 'title^3',
'curator', 'curator',
@ -114,6 +118,7 @@ class Search
'query' => [ 'query' => [
'multi_match' => [ 'multi_match' => [
'query' => $query, 'query' => $query,
'type' => 'phrase_prefix',
'fields' => [ 'fields' => [
'display_name', 'display_name',
'tracks', 'tracks',
@ -126,10 +131,10 @@ class Search
], ],
]); ]);
$tracks = $this->transformTracks($results['responses'][0]['hits']['hits']); $tracks = $this->transformTracks(Arr::get($results, 'responses.0.hits.hits', []));
$albums = $this->transformAlbums($results['responses'][1]['hits']['hits']); $albums = $this->transformAlbums(Arr::get($results, 'responses.1.hits.hits', []));
$playlists = $this->transformPlaylist($results['responses'][2]['hits']['hits']); $playlists = $this->transformPlaylist(Arr::get($results, 'responses.2.hits.hits', []));
$users = $this->transformUsers($results['responses'][3]['hits']['hits']); $users = $this->transformUsers(Arr::get($results, 'responses.3.hits.hits', []));
return [ return [
'tracks' => $tracks, 'tracks' => $tracks,