Installation and setup | laravel-site-search | Spatie        

 SPATIE  

  Laravel Site Search 
======================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-site-search](https://spatie.be/docs/laravel-site-search/v1)  Installation and setup

 Version   v3   v1      

 Other versions for crawler [v3](https://spatie.be/docs/laravel-site-search/v3) [v1](https://spatie.be/docs/laravel-site-search/v1) 

  Installation and setup    
- [ Introduction ](https://spatie.be/docs/laravel-site-search/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-site-search/v1/support-us)
- [ Installation and setup ](https://spatie.be/docs/laravel-site-search/v1/installation-setup)
- [ About us ](https://spatie.be/docs/laravel-site-search/v1/about-us)
- [ Questions and issues ](https://spatie.be/docs/laravel-site-search/v1/questions-issues)
- [ Requirements ](https://spatie.be/docs/laravel-site-search/v1/requirements)
- [ Changelog ](https://spatie.be/docs/laravel-site-search/v1/changelog)

Basic usage
-----------

- [ High level overview ](https://spatie.be/docs/laravel-site-search/v1/basic-usage/high-level-overview)
- [ Indexing your first site ](https://spatie.be/docs/laravel-site-search/v1/basic-usage/indexing-your-first-site)
- [ Retrieving results ](https://spatie.be/docs/laravel-site-search/v1/basic-usage/retrieving-results)
- [ Preventing content from being indexed ](https://spatie.be/docs/laravel-site-search/v1/basic-usage/preventing-content-from-being-indexed)
- [ Using a search profile ](https://spatie.be/docs/laravel-site-search/v1/basic-usage/using-a-search-profile)
- [ Authenticating requests ](https://spatie.be/docs/laravel-site-search/v1/basic-usage/authenticating-requests)
- [ Listing indexes ](https://spatie.be/docs/laravel-site-search/v1/basic-usage/listing-indexes)

Advanced usage
--------------

- [ Creating multiple search indexes ](https://spatie.be/docs/laravel-site-search/v1/advanced-usage/creating-multiple-search-indexes)
- [ Using a custom indexer ](https://spatie.be/docs/laravel-site-search/v1/advanced-usage/using-a-custom-indexer)
- [ Indexing extra properties ](https://spatie.be/docs/laravel-site-search/v1/advanced-usage/indexing-extra-properties)
- [ Customizing Meilisearch settings ](https://spatie.be/docs/laravel-site-search/v1/advanced-usage/customizing-meilisearch-settings)
- [ Available events ](https://spatie.be/docs/laravel-site-search/v1/advanced-usage/available-events)

      You are viewing the documentation for **an older version** of this package. You can check the version you are using with the following command:

 `                                    composer show spatie/laravel-site-search                                                                                                                                                                                                                                    ` 

Installation and setup
======================

###  On this page 

1. [ Require via composer ](#content-require-via-composer)
2. [ Publish migrations ](#content-publish-migrations)
3. [ Schedule the crawl command ](#content-schedule-the-crawl-command)
4. [ Publish the config file ](#content-publish-the-config-file)
5. [ Install the Meilisearch client ](#content-install-the-meilisearch-client)
6. [ Install Meilisearch ](#content-install-meilisearch)
7. [ Authenticating requests to Meilisearch ](#content-authenticating-requests-to-meilisearch)

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:^1.0.0"
```

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.

```
// in app/Console/Kernel.php
use Spatie\SiteSearch\Commands\CrawlCommand;

protected function schedule(Schedule $schedule)
{
    // other commands
    // ...

    $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 [
    /*
     * When crawling your site, we will not add any content to the search index
     * that is on these URLs.
     *
     * All links on these URLs will still be followed and crawled.
     *
     * You may use `*` as a wildcard.
     */
    'ignore_content_on_urls' => [
        //
    ],

    /*
     * When indexing your site, we will not add any content to the search index
     * that is selected by these CSS selectors.
     *
     * All links inside such content will still be crawled, so it's safe
     * it's safe to add a selector for your menu structure.
     */
    'ignore_content_by_css_selector' => [
        '[data-no-index]',
        'nav',
    ],

    /*
     * When crawling your site, we will not add any content to the search index
     * for responses that have any of these headers.
     */
    'do_not_index_content_headers' => [
        'site-search-do-not-index',
    ],

    /*
     * When crawling your site, we will not follow any of these links.
     *
     * You may use `*` as a wildcard.
     */
    'do_not_crawl_urls' => [
        //
    ],

    /*
     * A search profile is a class that is responsible for determining which
     * pages should be crawled, whether they should be indexed, and which
     * indexer should be used.
     *
     * This profile will be used when none is specified in the `profile_class` attribute
     * of a `SiteSearchIndex` model.
     */
    'default_profile' => Spatie\SiteSearch\Profiles\DefaultSearchProfile::class,

    /*
     * An indexer is a class that is responsible for converting the content of a page
     * to a structure that will be added to the search index.
     *
     * This indexer will be used when none is specified in the `profile_class` attribute
     * of a `SiteSearchIndex` model.
     */
    'default_indexer' => Spatie\SiteSearch\Indexers\DefaultIndexer::class,

    /*
     * A driver is responsible for writing all scraped content
     * to a search index.
     */
    'default_driver' =>  Spatie\SiteSearch\Drivers\MeiliSearchDriver::class,
];
```

Install the Meilisearch client
--------------------------------------------------------------------------------------------------------------------------------------------------

Next, you should require the Meilisearch PHP client:

```
composer require meilisearch/meilisearch-php
```

Install Meilisearch
-----------------------------------------------------------------------------------------------------------------

This package uses Meilisearch under the hood to provide blazing fast search results. Head over to [the Meilisearch docs](https://docs.meilisearch.com/learn/getting_started/installation.html#download-and-launch) to learn how to install it on your system.

Here are the steps for installing it on a Forge provisioned server. You must first download the stable release:

```
curl -L https://install.meilisearch.com | sh
```

Next, you must change the ownership and modify permission:

```
chmod 755 meilisearch 
chown root:root meilisearch
```

After that, move the binary to a system-wide available path:

```
sudo mv meilisearch /usr/bin/
```

Finally, you can run the binary and make sure it keeps running. In the Forge Dashboard, click on "Daemons" under "Server Details". Fill out the following for a new daemon:

- Command: `meilisearch --master-key=SOME_MASTER_KEY --env=production --http-addr 0.0.0.0:7700 --db-path ./home/forge/meilifiles`
- User: `forge`
- Directory: leave blank
- Processes: `1`

These instructions were take from [this gist](https://gist.github.com/josecanhelp/126d627ef125538943f33253d16fc882) by Jose Soto.

Authenticating requests to Meilisearch
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

To avoid unauthorized persons making request to Meilisearch, either block Meilisearch's default port (7700) in your firewall, or make sure all requests [use authentication](/docs/laravel-site-search/v1/basic-usage/authenticating-requests).

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
