B
B
BonBon Slick2016-11-08 22:42:51
Laravel
BonBon Slick, 2016-11-08 22:42:51

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

It's a pity there is no vote, then I'll ask like this - what do you use, why? What do you advise?
And then I’ll drink home-made, and then it turns out that it would be better to use Scout from the very beginning, I’ll lose a lot of time, I want to know your recommendations.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stanislav Pochepko, 2016-11-08
@BonBonSlick

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.

A
Andrzej Wielski, 2016-11-08
@wielski

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 )

A
Alexander Alexandrovich, 2016-11-09
@tatu

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 question

Ask a Question

731 491 924 answers to any question