Available events | 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)  Advanced-usage  Available events

 Version   v1      

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

  Available events    
- [ 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)

 Available events
================

###  On this page 

1. [ IndexingStarted ](#content-indexingstarted)
2. [ IndexingEnded ](#content-indexingended)
3. [ NewIndexCreated ](#content-newindexcreated)
4. [ IndexedURL ](#content-indexedurl)
5. [ FailedToCrawlURL ](#content-failedtocrawlurl)
6. [ CrawlFinished ](#content-crawlfinished)

You can listen for these events to add extra functionality. Every event has a `Site` field with the configuration snapshot for that crawl.

Register listeners in your application's `laravel.Options.Listeners`:

```
Listeners: []laravel.Listener{
    laravel.Listen(func(ctx context.Context, e sitesearch.IndexedURL) error {
        log.InfoContext(ctx, "Indexed page", "url", e.URL)
        return nil
    }),
},
```

This example imports `context`, `log/slog` as `log`, `go.laravel.com` as `laravel`, and the Site Search package as `sitesearch`.

IndexingStarted
-----------------------------------------------------------------------------------------------------

Fired when indexing starts, before a replacement index is created. It contains `Site`.

IndexingEnded
-----------------------------------------------------------------------------------------------

Fired after successful promotion and deletion of the previous index. It contains the updated `Site`. A listener failure at this point is returned, but does not undo promotion.

NewIndexCreated
-----------------------------------------------------------------------------------------------------

Fired right before crawling, after creating the replacement index. It contains `Site` and `IndexName`, the new physical index name.

IndexedURL
--------------------------------------------------------------------------------------

Fired after a response has been indexed. It contains `URL`, `Response` and `Progress`. `Response` is a Crawler Go response, including the original URL, headers, body and discovery URL. `URL` is the indexed page's normalized or customized URL.

FailedToCrawlURL
--------------------------------------------------------------------------------------------------------

Fired when fetching a page fails. It contains `Failure` and `Progress`. `Failure` includes the URL, discovery URL, response status and error.

CrawlFinished
-----------------------------------------------------------------------------------------------

Fired when the crawler finishes. It contains `Reason` and `Progress`. Reasons include `completed`, `crawl_limit_reached`, `time_limit_reached` and `interrupted`. Progress includes URLs crawled, failed, found and pending.

The finish reason and counters are saved with the configuration after a successful crawl. A failed replacement saves `interrupted` instead. Crawl completion happens before index finalization and promotion, so this event alone does not mean the new index is active.

Listeners are synchronous. Errors before promotion stop indexing and preserve the previous index. Crawl observers and counters belong to that crawl, not to global event listeners shared by other sites.

 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)
