Using a search profile | 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)  Basic-usage  Using a search profile

 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                                                                                                                                                                                                                                    `

Using a search profile
======================

###  On this page

1. [ Creating your own search profile ](#content-creating-your-own-search-profile)

A search profile determines which pages get crawled and what content gets indexed. In the `site-search` config file, you'll in the `default_profile` key that the `Spatie\SiteSearch\Profiles\DefaultSearchProfile::class` is being use by default.

This default profile will instruct the indexing process:

- to crawl each page of your site
- to only index any page that had `200` as the status code of its response
- to not index a page if the response had a header `site-search-do-not-index`

By default, the crawling process will respect the `robots.txt` of your site.

A search profile is also responsible for determining which indexer will be used for a certain page. An indexer is responsible for determining the title, content, description, ... of a page. By default, `Spatie\SiteSearch\Indexers\DefaultIndexer` will get used. To know more about indexers and how to customize them, head over to [the section on indexers](/docs/laravel-site-search/v1/advanced-usage/using-a-custom-indexer).

Creating your own search profile
--------------------------------------------------------------------------------------------------------------------------------------------------------

If you want to customize the crawling and indexing behavior, you could opt to extend `Spatie\SiteSearch\Profiles\DefaultSearchProfile` or create your own class that implements the `Spatie\SiteSearch\Profiles\SearchProfile` interface. This is how that interface looks like.

```
namespace Spatie\SiteSearch\Profiles;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;
use Spatie\SiteSearch\Indexers\Indexer;

interface SearchProfile
{
    public function shouldCrawl(UriInterface $url, ResponseInterface $response): bool;
    public function shouldIndex(UriInterface $url, ResponseInterface $response): bool;
    public function useIndexer(UriInterface $url, ResponseInterface $response): ?Indexer;
    public function configureCrawler(Crawler $crawler): void;
}
```
