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

 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/v3/introduction)
- [ Support us ](https://spatie.be/docs/laravel-site-search/v3/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-site-search/v3/requirements)
- [ Installation and setup ](https://spatie.be/docs/laravel-site-search/v3/installation-setup)
- [ About us ](https://spatie.be/docs/laravel-site-search/v3/about-us)
- [ Questions and issues ](https://spatie.be/docs/laravel-site-search/v3/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-site-search/v3/changelog)

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

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

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

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

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

###  On this page

1. [ IndexingStartEvent ](#content-indexingstartevent)
2. [ IndexingEndedEvent ](#content-indexingendedevent)
3. [ NewIndexCreatedEvent ](#content-newindexcreatedevent)
4. [ IndexedUrlEvent ](#content-indexedurlevent)
5. [ FailedToCrawlUrlEvent ](#content-failedtocrawlurlevent)
6. [ CrawlFinishedEvent ](#content-crawlfinishedevent)

You can listen for these events to add extra functionality.

IndexingStartEvent
--------------------------------------------------------------------------------------------------------------

This event will be fired when the indexing process starts, right before a search index is created.

It has these properties:

- `siteSearchConfig`: an instance of `SiteSearchConfig` for which the indexing process is starting

IndexingEndedEvent
--------------------------------------------------------------------------------------------------------------

This event will be fired when the indexing process has ended.

It has these properties:

- `siteSearchConfig`: an instance of `SiteSearchConfig` for which the indexing process is starting

NewIndexCreatedEvent
--------------------------------------------------------------------------------------------------------------------

Right before we start crawling a site, a new search index will be created, firing off this event.

It has these properties:

- `newIndexName` the name of the new search index
- `siteSearchConfig`: an instance of `SiteSearchConfig` for which the new event has been created

IndexedUrlEvent
-----------------------------------------------------------------------------------------------------

Will be fired whenever a URL has been successfully crawled and indexed.

It has these properties:

- `url`: a `string` containing the url that was indexed
- `response`: an instance of `CrawlResponse`
- `progress`: an instance of `CrawlProgress` with properties `urlsCrawled`, `urlsFailed`, `urlsFound`, and `urlsPending`
- `foundOnUrl`: an optional `string` containing the url on which the indexed url was found

FailedToCrawlUrlEvent
-----------------------------------------------------------------------------------------------------------------------

Will be fired whenever crawling a page resulted in an error.

It has these properties:

- `url`: a `string` containing the url that was crawled
- `requestException`: the exception itself
- `progress`: an instance of `CrawlProgress` with properties `urlsCrawled`, `urlsFailed`, `urlsFound`, and `urlsPending`
- `foundOnUrl`: an optional `string` containing the url on which the crawled url was found

CrawlFinishedEvent
--------------------------------------------------------------------------------------------------------------

Will be fired when the crawler has finished crawling a site.

It has these properties:

- `finishReason`: an instance of `FinishReason` (an enum with values `Completed`, `CrawlLimitReached`, `TimeLimitReached`, and `Interrupted`)
- `progress`: an instance of `CrawlProgress` with properties `urlsCrawled`, `urlsFailed`, `urlsFound`, and `urlsPending`

The `finishReason` and progress counters (`urls_found`, `urls_failed`) from this event are automatically persisted to the `site_search_configs` table after each crawl.
