PostgreSQL Full Text Search for Laravel Scout

A passionate full-stack developer from @ePlus.DEV
Search for a command to run...

A passionate full-stack developer from @ePlus.DEV
No comments yet. Be the first to comment.
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling.
Building CLI applications can be a lot of fun. We don't have to worry about the UI, and we can write beautiful PHP code that doesn't need any build steps. When building CLI applications in PHP, we aren't as spoilt for choice as in building web applic...
Một bản tin giúp Developer cập nhật nhanh AI, Cloud, Open Source và những công nghệ đáng chú ý trong ngày. 📌 Executive Summary OpenAI công bố mười kết quả mới cho các bài toán lâu năm trong toán h

Một bản tin giúp Developer cập nhật nhanh AI, Cloud, Open Source và những công nghệ đáng chú ý trong ngày. 📌 Executive Summary GitHub thử nghiệm policy theo enterprise team, cho phép cấp thêm mode

Một bản tin giúp Developer cập nhật nhanh AI, Cloud, Open Source và những công nghệ đáng chú ý trong ngày. 📌 Executive Summary OpenAI giảm mạnh giá GPT-5.6 Luna và Terra, đồng thời chuyển Priority

Một bản tin giúp Developer cập nhật nhanh AI, Cloud, Open Source và những công nghệ đáng chú ý trong ngày. 📌 Executive Summary GitHub Copilot code review đã hỗ trợ chính thức Agent Skills và MCP s

Overview Vibe coding is an emerging software development practice that uses artificial intelligence (AI) to generate functional code from natural language prompts, accelerating development, and making

This package makes it easy to use native PostgreSQL Full Text Search capabilities with Laravel Scout:
// plainto_tsquery()
$posts = App\Post::search('cat rat')
->usingPlainQuery()->get()
// phraseto_tsquery()
$posts = App\Post::search('cat rat')
->usingPhraseQuery()->get()
// to_tsquery()
$posts = App\Post::search('fat & (cat | rat)')
->usingTsQuery()->get()
// websearch_to_tsquery()
// uses web search syntax
$posts = App\Post::search('"sad cat" or "fat rat" -mouse')
->usingWebSearchQuery()->get()
// DIY using a callback
use ScoutEngines\Postgres\TsQuery\ToTsQuery;
$results = App\Post::search('fat & (cat | rat)', function ($builder, $config) {
return new ToTsQuery($builder->query, $config);
})->get();
And here's an example model:
class Post extends Model
{
use Searchable;
// Configurable search data...
// Bring other data (i.e., tags) to the index document
public function toSearchableArray()
{
return [
'title' => $this->title,
'content' => $this->content,
'author' => $this->user->name,
'tags' => $this->tags->pluck('tag')->implode(' '),
];
}
public function searchableOptions()
{
return [
// Model search config for index settings, rank, etc.
];
}
}
The way this integration works is that the parsed document model data is stored in the same table in the searchable column with the tsvector type. You can fine-tune how each model works by integrating a searchableOptions() method, which allows you to:
Configurable column name (default is searchable)
Rank groups can be assigned to fields in the table
Rank weights are configurable for each rank group
Configurable ranking function to use (ts_rank or ts_rank_cd)
Rank normalization
And more...
You can learn more about this package, get full installation instructions, and view the source code on GitHub.
Source: