Answer the question
In order to leave comments, you need to log in
Is Scout needed in laravel 5.3 or will we manage with a self-made search?
- ElasticSearch
- Scout
- Homemade
Homemade like:
public function search(Request $request){
$search_data = $request->input('searcher');
if (isset($search_data) && !empty($search_data) )
{
$products = DB::table('products');
$results = $products->where('product_name', 'LIKE', '%'. $search_data .'%')
->orWhere('product_id', 'LIKE', '%'. $search_data .'%')
->orWhere('description', 'LIKE', '%'. $search_data .'%')
->get();
return view('products/search')->with('results', $results);
}
}
Answer the question
In order to leave comments, you need to log in
And again you missed. Scout is just a provider providing a common API for interacting with various search engines. For search engines (Elasticsearch, Sphinx, etc.), you need to find a driver for Scout. For popular ones, I think they have already written. If not, then you can implement it yourself. Then you specify the driver itself and the connection parameters to the search engine itself in the configuration. And then use the built-in SCout methods to implement the search.
DB provider example, Email. queues in the same Laravel
PS Depending on what you need from the search, choose one. For a simple project, a self-propelled gun is fine, just make it a little smarter.
Scout is a common provider for interacting with other services. You can attach the same Elastic, Sphinx, TNT, etc. to it.
If the project is small - forget it. Better use the same Eloquence Searchable ( Tyk )
As stated above, Scout is just a provider that defines how search works (whether it's erlastic/lucene/sphinx or a third party service).
Based on your example, I don't think you really need to use an additional search engine.
Pay attention to how you can implement your method:
//Лучше создать отдельный Request для поиска и передавал именно его,
//где searcher являлся обязательным
public function search(Request $request)
{
//Для проверки сущестования есть специальный метод
if ($request->has('searcher')) {
$results = $product->whereRaw(
"MATCH(product_name,product_id,description) AGAINST(? IN BOOLEAN MODE)",
[$request->searcher]
//В mysql есть стандартный механизм полнотекстового поиска
//Думаю имеет смысл использовать именно его (Не забываем про индексы)
)->get();
return view('products/search')->with('results', $results);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question