Laravel Elastic Search
As suggested by many friends here 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 https://medium.com/@samogorm/basic-search-functionality-with-elasticsearch-laravel-scout-6ac182c99cbf
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 in 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="{{ url('/press/'.$article->slug) }}"><img src="{{ url('http://assets.hobohweb.com/uploads/press/'.$article->image) }}" class="img-fluid" alt=""></a>
</div>
<div class="box-body">
<a href="{{ url('/press/'.$article->slug) }}"><h6 class="h-2x">{{ $article->title }}</h6></a>
{{ Carbon\Carbon::parse($article->created_at)->diffForHumans() }} on <a href="{{ url($article->source_url) }}" class="text-primary">{{ $article->source }}</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?
Please or to participate in this conversation.