Reputation: 1156
i implemented elasticsearch
and laravel scout
in laravel 9.x application
and i also installed matchish/laravel-scout-elasticsearch
repository as driver for scout
but the problem is: When the searched word is not written completely, no result will be found!
Model:
<?php
namespace App\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
use Laravel\Scout\Attributes\SearchUsingFullText;
use Laravel\Scout\Attributes\SearchUsingPrefix;
class Post extends Model
{
use searchable;
protected $fillable = ['title', 'body'];
#[SearchUsingPrefix(['title'])]
#[SearchUsingFullText(['title'])]
public function toSearchableArray()
{
return [
'title' => $this->title,
'body' => $this->body
];
}
}
insert in db and index in elasticsearch:
\App\Models\Link::create([
'title' => 'elasticsearch tutorial',
'body' => 'body...'
]);
trying to search:
$post = \App\Models\Post::search('elasticsear')->get();
dd($post);
the elasticsear
word in incomplete and no result will be found
Upvotes: 0
Views: 496
Reputation: 21
You can try this one https://sigmie.com/docs/v0/laravel-scout
It supports the newest Laravel Scout
Upvotes: 0