Customizing Meilisearch settings | 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)  Advanced-usage  Customizing Meilisearch settings

 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)

- [ 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                                                                                                                                                                                                                                    `

Customizing Meilisearch settings
================================

###  On this page

1. [ Using an alternative URL ](#content-using-an-alternative-url)

When using Meilisearch, sane defaults are used to connect and create an index. These defaults can be customized.

Most customizations can be done by adding values to the `extra` field of a row of the `site_search_configs` table. This field must be either `null` or contain valid JSON.

Using an alternative URL
--------------------------------------------------------------------------------------------------------------------------------

When using the Meilisearch driver, we'll try to connect to `http://localhost:7700` by default.

You can customize this by adding a `meilisearch.url` JSON value to the `extra` attribute in the `site_search_configs` table. Here's how that would look like:

```
{"meilisearch":{"url":"https:\/\/your-custom-domain-and-port.com:1234"}}
```

### Modifying index settings

A Meilisearch index has [various interesting settings](https://www.meilisearch.com/docs/learn/configuration/settings) that allow you [which fields are searchable](https://www.meilisearch.com/docs/reference/api/settings#searchable-attributes), [specify ranking rules](https://www.meilisearch.com/docs/reference/api/settings#ranking-rules), and even [add synonyms](https://www.meilisearch.com/docs/learn/configuration/synonyms).

Every time a site is crawled, a new index is created. You can customize the settings that are used for this index in two ways.

The first way would be by adding a `meilisearch.indexSettings` JSON value to the `extra` attribute in the `site_search_configs`. In `meilisearch.indexSettings` you can put any of [the list settings that Meilisearch provides](https://www.meilisearch.com/docs/learn/configuration/settings).

Here's how that value you would put in `extra` if you only want results based on the `url` and `description` fields in the index.

```
{
    "meilisearch": {
        "indexSettings": {
            "searchableAttributes": [
                "url",
                "description"
            ]
        }
    }
}
```

Here's another example where we are going to add a synonym for the word "computer". You can read more about [how synonyms can be configured](https://www.meilisearch.com/docs/learn/configuration/synonyms) in the Meilisearch docs.

```
{
   "meilisearch":{
      "indexSettings":{
         "synonyms":{
            "Macintosh":[
               "computer"
            ]
         }
      }
   }
}
```

The second way to customize index settings would be by leveraging the `Spatie\SiteSearch\Events\NewIndexCreatedEvent`. This event is fired whenever a new index is created. It has two properties:

- the name of the created Meilisearch object
- an instance of `Spatie\SiteSearch\Models\SiteSearchConfig`

You can use these properties to make an API call of your own to Meilisearch to customize [any of the available settings](https://www.meilisearch.com/docs/learn/configuration/settings).
