From e20381fda9232ed97e1a92d2a93b9c4dabef7511 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 21 Aug 2019 20:54:41 +0200 Subject: [PATCH] #2940 --- app/Http/Controllers/AjaxController.php | 36 ++----------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php index a192381..17bffa6 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/AjaxController.php @@ -8,6 +8,7 @@ use App\Models\Page; use App\Models\Product; use Cubist\Backpack\app\Http\Controllers\CubistFrontController; use Cubist\Backpack\app\Magic\PageData; +use Cubist\Backpack\app\Magic\Search; use Illuminate\Http\Request; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Validator; @@ -176,39 +177,6 @@ class AjaxController extends CubistFrontController public function search(Request $request) { - $limit = $request->limit ?? 50; - $index = config('cubist.internal_search_index'); - - // Set weight of each field - $fields = ['short_title' => 4, 'long_title' => 1, 'keywords' => 5, 'description' => 1, 'main' => 2]; - - $queryfields = []; - foreach ($fields as $field => $weight) { - $queryfields[] = $field . '^' . $weight; - $queryfields[] = $field . '.stemmed' . '^' . $weight; - } - - $res = \Elasticsearch::search(['index' => $index, - 'body' => [ - //'explain' => true, - 'from' => 0, - 'size' => $limit, - 'query' => [ - 'multi_match' => [ - 'query' => $request->q, - 'fields' => $queryfields, - ] - ] - ] - ]); - - $hits = []; - foreach ($res['hits']['hits'] as $hit) { - $hits[] = ['url' => $hit['_id'], - 'title' => $hit['_source']['short_title'] - ]; - } - - return $hits; + return Search::query($request->q, $request->limit ?? null); } } -- 2.39.5