spatie/laravel-site-search
Crawl and index your Laravel site for fast full-text search—like a private Google. Highly customizable crawling and indexing, with concurrent requests. Uses SQLite FTS5 by default (no external services), or Meilisearch for advanced features.
By default, only the page title, URL, description, and some content are added to the search index. However, you can add any extra property you want.
You do this by using a custom indexer and override the extra method.
class YourIndexer extends Spatie\SiteSearch\Indexers\DefaultIndexer
{
public function extra() : array{
return [
'authorName' => $this->functionThatExtractsAuthorName()
]
}
public function functionThatExtractsAuthorName()
{
// add logic here to extract the username using
// the `$response` property that's set on this class
}
}
The extra properties will be available on a search result hit.
$searchResults = Search::onIndex('my-index')->query('your query')->get();
$firstHit = $searchResults->hits->first();
$firstHit->authorName; // returns the author name
All extra properties are searchable by default. When using the Meilisearch driver, you can customize the index settings to control which attributes are searchable.
How can I help you explore Laravel packages today?