]> _ Git - pmi.git/commitdiff
#2940
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 21 Aug 2019 18:54:41 +0000 (20:54 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 21 Aug 2019 18:54:41 +0000 (20:54 +0200)
app/Http/Controllers/AjaxController.php

index a1923811dd66055f4eff525723a2ac54ea62809a..17bffa6e92446d77f52d8537c8c3910fd6842eea 100644 (file)
@@ -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);
     }
 }