How to improve search on the site?

Friends, tell me. Wrote search. For example, I have an article in the "Lorem ipsum 2". If I enter
the letters from the title in order, then the article is returned, but if for example "Lorem 2" it is no longer refundable. How to make to return?

$('.search-field').on('keyup', function(){
 var words = $(this).val().trim();

$.ajax({

 url: "/search",
 type: "post",
 data: {words: words},
 headers: {
 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},

 success: function(results) {
 $.each(results, function(key,result){
 $('.search-results > div > a').text(result.title)
})
}

 }) 

 })


public function search() 
{
 $words = Request::get('words');
 $results = Articles::where('title', 'LIKE', '%' . $words . '%') -> get();
 return $results;
 }
July 9th 19 at 10:16
3 answers
July 9th 19 at 10:18
Use a specialized solution for full-text search: Elastic, Sphinx
July 9th 19 at 10:20
Make a breakdown of the search terms on whitespace and look for an entry for each item using the AND, OR operator and %...%.
AND or or is you to decide how exactly it will show the results

If there is AND he will find articles with lorem and 2 in the text. (Prisutsvujut both)
If there is OR will find everything from lorem and all of 2 (That is, only one or the other)

UPD

public function search() 
{
 $items = explode(" ",Request::get('words'));

 $Articles = new Articles();

 foreach ($items as $item){
 $Articles->where('title', 'LIKE', '%' . $words . '%')
 // $Articles->orWhere('title', 'LIKE', '%' . $words . '%') are what you want
}

 $results = $Articles -> get();
 return $results;
 }
possible a good example?) - Salma_Jones commented on July 9th 19 at 10:23
: splitting strings explode (www.php.su/explode) or the regular season, then using a foreach generated request - Henderson_Beat commented on July 9th 19 at 10:26
This so-called "prefix search") Cons, if one "scholar" it is unlikely that you will find. - Darby_Hetting commented on July 9th 19 at 10:29
July 9th 19 at 10:22
It is not necessary a bike, a work package:
https://github.com/nicolaslopezj/searchable

Find more questions by tags LaraveljQuery