You can install this package inside a Laravel app of which the content needs to be indexed. You could also install this package inside a standalone Laravel app that is dedicated to crawling multiple other sites.
Here are the steps that you need to perform to install the package.
##Require via composer
laravel-site-search can be installed via Composer:
composer require spatie/laravel-site-search
##Publish migrations
Next, you should publish the migrations and run them:
php artisan vendor:publish --tag="site-search-migrations"
php artisan migrate
##Schedule the crawl command
This package contains a command that will crawl your site(s), and update the indexes.
In most cases, it's best to schedule that command, so you don't need to run it manually.
In the example below, we schedule to run the command every three hours, but you can decide which frequency is best for you.
use Illuminate\Support\Facades\Schedule;
use Spatie\SiteSearch\Commands\CrawlCommand;
Schedule::command(CrawlCommand::class)->everyThreeHours();
##Publish the config file
Optionally, you can publish the config file with this command.
php artisan vendor:publish --tag="site-search-config"
This is the content of the config file:
<?php
return [
'ignore_content_on_urls' => [
],
'ignore_content_by_css_selector' => [
'[data-no-index]',
'nav',
],
'do_not_index_content_headers' => [
'site-search-do-not-index',
],
'do_not_crawl_urls' => [
],
'default_profile' => Spatie\SiteSearch\Profiles\DefaultSearchProfile::class,
'default_indexer' => Spatie\SiteSearch\Indexers\DefaultIndexer::class,
'default_driver' => Spatie\SiteSearch\Drivers\DatabaseDriver::class,
'crawl_site_job' => Spatie\SiteSearch\Jobs\CrawlSiteJob::class,
];
##Search driver
The default driver is the database driver, which uses your application's database for full-text search. It supports SQLite (FTS5), MySQL (FULLTEXT), and PostgreSQL (tsvector) with no external services required. See Using the database driver for more configuration options.
If you need advanced features like synonyms and custom ranking rules, you can use the Meilisearch driver instead.