This package deal makes it straightforward to make use of native PostgreSQL Full Textual content Search capabilities with Laravel Scout:
// plainto_tsquery()
$posts = AppPost::search('cat rat')
->usingPlainQuery()->get()
// phraseto_tsquery()
$posts = AppPost::search('cat rat')
->usingPhraseQuery()->get()
// to_tsquery()
$posts = AppPost::search('fats & (cat | rat)')
->usingTsQuery()->get()
// websearch_to_tsquery()
// makes use of net search syntax
$posts = AppPost::search('"unhappy cat" or "fats rat" -mouse')
->usingWebSearchQuery()->get()
// DIY utilizing a callback
use ScoutEnginesPostgresTsQueryToTsQuery;
$outcomes = AppPost::search('fats & (cat | rat)', operate ($builder, $config) {
return new ToTsQuery($builder->question, $config);
})->get();
And this is an instance mannequin:
class Put up extends Mannequin
{
use Searchable;
// Configurable search information...
// Convey different information (i.e., tags) to the index doc
public operate toSearchableArray()
{
return [
'title' => $this->title,
'content' => $this->content,
'author' => $this->user->name,
'tags' => $this->tags->pluck('tag')->implode(' '),
];
}
public operate searchableOptions()
{
return [
// Model search config for index settings, rank, etc.
];
}
}
The way in which this integration works is that the parsed doc mannequin information is saved in the identical desk within the searchable
column with the tsvector sort. You possibly can fine-tune how every mannequin works by integrating a searchableOptions()
technique, which lets you:
- Configurable column identify (default is
searchable
) - Rank teams will be assigned to fields within the desk
- Rank weights are configurable for every rank group
- Configurable rating operate to make use of (
ts_rank
orts_rank_cd
) - Rank normailzation
- And extra…
You possibly can study extra about this package deal, get full set up directions, and examine the supply code on GitHub.