Preventing content from being indexed | 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  Preventing content from being indexed

 Version   v1      

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

  Preventing content from being indexed    
- [ 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)

 Preventing content from being indexed
=====================================

###  On this page 

1. [ Using CSS selectors ](#content-using-css-selectors)
2. [ Using configuration ](#content-using-configuration)
3. [ Using headers ](#content-using-headers)
4. [ Query string handling ](#content-query-string-handling)
5. [ Using a search profile ](#content-using-a-search-profile)

Your site probably displays information that should not be indexed, such as menus or footers. Or maybe entire pages do not need to be indexed.

Using CSS selectors
-----------------------------------------------------------------------------------------------------------------

Set `IgnoreSelectors` in your package configuration callback to specify elements that should not be indexed. By default, `nav` and elements with `data-no-index` are excluded. Links inside those elements are still followed.

```
<nav>This menu is not indexed.</nav>
<h1>This is the H1</h1>
<p>This content is indexed.</p>
<div data-no-index>This will not be indexed.</div>
```

To also exclude footers:

```
sitesearch.New(func(cfg *sitesearch.Config) {
    cfg.IgnoreSelectors = []string{"[data-no-index]", "nav", "footer"}
})
```

An empty non-nil slice disables the default selector exclusions.

Using configuration
-----------------------------------------------------------------------------------------------------------------

`IgnoreContentOnURLs` contains path patterns whose content should not be indexed. Links on these pages are still followed. `DoNotCrawlURLs` excludes matching paths from crawling altogether.

```
cfg.IgnoreContentOnURLs = []string{"/archive/*", "/search"}
cfg.DoNotCrawlURLs = []string{"/private/*"}
```

Patterns match the complete URL path, not the host or query. `*` matches any number of characters, including slashes. `?` matches one character. Other characters are literal.

Using headers
-----------------------------------------------------------------------------------------------

If a response contains a header listed in `DoNotIndexHeaders`, the page will not be indexed. The default is `site-search-do-not-index`. Header names are case-insensitive, and presence is enough, even if the value is `false`. Links are still followed.

Query string handling
-----------------------------------------------------------------------------------------------------------------------

The default profile removes the query string from the URL passed to the indexer. Query-bearing URLs are still crawled and their links are followed. The database driver combines entries with the same normalized URL within one update batch. Repeated query variants can still produce separate documents across batches. Meilisearch and the array driver retain individual text entries. Normalized URLs are not a promise of document deduplication.

To preserve query strings, override `IndexerFor` in a [custom profile](using-a-search-profile) and return your indexer directly instead of using `DefaultProfile.IndexerFor`.

Using a search profile
--------------------------------------------------------------------------------------------------------------------------

A search profile determines what pages get crawled and what content gets indexed. Learn more in [Using a search profile](using-a-search-profile).

 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)
