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.
On this page, you'll learn how to create an index, populate it by crawling your site, and retrieving results. Let's do this!
First, you can run this command to define a site that needs to be indexed.
php artisan site-search:create-index
This command will ask for a name for your index, and the URL of your site that should be crawled.
After that you should run this command to start a queued job that crawls your site, and puts the content in a search index:
php artisan site-search:crawl
Finally, you can use the Search class to perform a query on your index.
use Spatie\SiteSearch\Search;
$searchResults = Search::onIndex($indexName)
->query('your query')
->get();
This is how you could render the results in a Blade view
<ul>
[@foreach](https://github.com/foreach)($searchResults->hits as $hit)
<li>
<a href="{{ $hit->url }}">
<div>{{ $hit->url }}</div>
<div>{{ $hit->title() }}</div>
<div>{!! $hit->highlightedSnippet() !!}</div>
</a>
</li>
[@endforeach](https://github.com/endforeach)
</ul>
How can I help you explore Laravel packages today?