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;
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);
}
}