Laravel Site Search is a package by Spatie to create a full-text search index by crawling your site. You can think of it as a private Google search for your sites to crawl and index all your content and provide a highly customizable, indexed search.
🚀Our newest package, laravel-site-search, has been released.— Freek Van der Herten 🔭 (@freekmurze) October 19, 2021
🔎 This one can crawl and index the content of your site. Think of it as a private Google index.
⚙️ Behind the scenes @meilisearch is used!
✍️ Post: https://t.co/4bmhWyk1OZ#laravel pic.twitter.com/G94sdAMUEy
Using this package, you can create an index via the provided artisan command, which will prompt you for the name of the index you'd like to make, the URL of the site, etc.
Once you have your index, you can crawl the site using a queued job with the provided console command. Lastly, you can search against the index—the following are a few examples:
1use Spatie\SiteSearch\Search;23$searchResults = Search::onIndex($indexName)4 ->query('your query')5 ->get();67// Limit results8$searchResults = Search::onIndex('my-index')9 ->query('your query')10 ->limit(20)11 ->get(); // returns the first 20 results1213// Pagination (defaults to 20 results per page)14$searchResults = Search::onIndex('my-index')15 ->query('your query')16 ->paginate(20);
Under the hood, Laravel Site Search is powered by Meilisearch, which provides exceptionally fast search speeds and various customization options like synonyms and custom properties.
You can learn more about this package and view the source code on GitHub. The documentation is an excellent place to start for setup instructions and all the details to start using this fantastic package.