As suggested by many friends on laracasts, im using laravel scout with elasticsearch. I know there is another option algolia, but i prefer to use elasticsearch.
I have followed this tutorial
And have elasticsearch running on localhost:9200 and installed elasticsearch driver and configured index as scout and host as localhost:9200
When i run php artisan scout:import “App\Models\Press” it said 1 records added as i have only record in my model
I have the following code in my Controller
public function press (Request $request)
{
if($request->has('search')){
$articles = Press::search($request->input('search'))->get();
} else {
$articles = [];
}
return view('pages.press.index', compact('articles'));
}
and view
<form id="elasticScout" action="/press" method="get">
<div class="mysearchbar">
<input name="search" placeholder="Search...">
</div>
</form>
@forelse ($articles as $article)
<div class="col-md-4">
<div class="box border">
<div class="box-header">
<a href=""><img src="" class="img-fluid" alt=""></a>
</div>
<div class="box-body">
<a href=""><h6 class="h-2x"></h6></a>
on <a href="" class="text-primary"></a>
</div>
</div>
</div>
@empty
Please enter your search
@endforelse
Search works fine. But im confused if this search is from elastic search or normal query. I do not find any difference.
How can i check if the search is from elasticsearch?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire