Using a search profile | laravel-site-search-go | Spatie       

 SPATIE  

laravel-site-search-go
======================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-site-search-go](https://spatie.be/docs/laravel-site-search-go/v1)  Basic-usage  Using a search profile

 Version   v1      

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

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

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

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

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

- [ Creating multiple search indexes ](https://spatie.be/docs/laravel-site-search-go/v1/advanced-usage/creating-multiple-search-indexes)
- [ Using a custom indexer ](https://spatie.be/docs/laravel-site-search-go/v1/advanced-usage/using-a-custom-indexer)
- [ Indexing extra properties ](https://spatie.be/docs/laravel-site-search-go/v1/advanced-usage/indexing-extra-properties)
- [ Available events ](https://spatie.be/docs/laravel-site-search-go/v1/advanced-usage/available-events)
- [ Using the database driver ](https://spatie.be/docs/laravel-site-search-go/v1/advanced-usage/using-the-database-driver)
- [ Using the Meilisearch driver ](https://spatie.be/docs/laravel-site-search-go/v1/advanced-usage/using-the-meilisearch-driver)
- [ Building an admin integration ](https://spatie.be/docs/laravel-site-search-go/v1/advanced-usage/filament-integration)

 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. `DefaultProfile` is used by default. It crawls pages on the same host whose URL starts with the configured crawl URL, indexes only responses with status 200, and skips pages containing a `site-search-do-not-index` header.

By default, crawling respects `robots.txt`. The profile also chooses an indexer for each response. `DefaultIndexer` extracts the title, content and description. See [Using a custom indexer](../advanced-usage/using-a-custom-indexer).

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

Embed `sitesearch.DefaultProfile` to keep its behavior, or implement the complete interface:

```
type Profile interface {
    ShouldCrawl(string) bool
    ShouldIndex(*crawler.Response) bool
    IndexerFor(*crawler.Response) sitesearch.Indexer
    ConfigureCrawler(*crawler.Config)
}
```

For example, use fewer concurrent connections and exclude a path:

```
type BlogProfile struct {
    sitesearch.DefaultProfile
}

func (BlogProfile) ShouldCrawl(url string) bool {
    return !strings.Contains(url, "/archive/")
}

func (BlogProfile) ConfigureCrawler(cfg *crawler.Config) {
    cfg.Concurrency = 2
}
```

Import `github.com/spatie/crawler-go` and the standard `strings` package. Register the factory in your configuration callback:

```
cfg.Profiles["blog"] = func(site sitesearch.SiteSearchConfig) (sitesearch.Profile, error) {
    return BlogProfile{DefaultProfile: sitesearch.DefaultProfile{
        PageIndexer: cfg.Indexer,
        IgnoreContentOnURLs: cfg.IgnoreContentOnURLs,
        DoNotIndexHeaders: cfg.DoNotIndexHeaders,
    }}, nil
}
cfg.DefaultProfile = "blog"
```

You may instead set a configuration's `Profile` field to `blog`. A nonempty field overrides `DefaultProfile`. The factory receives the saved configuration, including its `Extra` map, so different sites can use different settings.

Return nil from `IndexerFor` to skip indexing a response. Returning a nil page from an indexer also skips it. These decisions do not stop link discovery. `ShouldCrawl` and `DoNotCrawlURLs` filter candidate URLs, including the seed URL.

`ConfigureCrawler` runs after the default URL scope is configured. It can change the HTTP client, robots policy, concurrency, limits, observers and crawl profile. Replacing `cfg.Profile` there replaces the default scope and exclusions, so apply your own restrictions. Site Search appends its indexing observer afterward. The overall `CrawlTimeout` still bounds the operation.

 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)
