Installation and setup | 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)  Installation and setup

 Version   v1      

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

  Installation and setup    
- [ 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)

 Installation and setup
======================

###  On this page 

1. [ Register the package ](#content-register-the-package)
2. [ Run migrations ](#content-run-migrations)
3. [ Configure the package ](#content-configure-the-package)
4. [ Configure queued crawls ](#content-configure-queued-crawls)
5. [ Search driver ](#content-search-driver)

You can install this package inside the Laravel Go application whose content needs to be indexed, or inside a dedicated Laravel Go application.

Add the module:

```
go get github.com/spatie/laravel-site-search-go@v0.1.0
```

Register the package
--------------------------------------------------------------------------------------------------------------------

Add the package explicitly in `bootstrap/app.go`. Installing the Go module alone does not activate it.

```
import (
    sitesearch "github.com/spatie/laravel-site-search-go"
    laravel "go.laravel.com"
)

func Options() laravel.Options {
    return laravel.Options{
        Packages: []laravel.Package{sitesearch.New()},
    }
}
```

Keep your application's other options and database drivers in place.

Run migrations
--------------------------------------------------------------------------------------------------

The package registers the migrations automatically. Run them with:

```
laravel migrate
```

Applications managing their own schema can set `cfg.WithoutMigrations = true`. The package exposes `migrations.All` for applications that register migrations separately. A separate database connection for documents needs the document table on that connection too.

Configure the package
-----------------------------------------------------------------------------------------------------------------------

Configuration is Go code, not a published PHP configuration file. Pass callbacks to `New`:

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

`SITE_SEARCH_DRIVER` sets the default driver in the application's environment. Code callbacks run afterward. The service belongs to the application, so separate applications do not share in-memory indexes.

Use `cfg.Store` for custom configuration persistence, `cfg.Indexer` for custom HTML extraction and `cfg.Drivers` for custom search engines. Use `cfg.Profiles` to register [search profiles](basic-usage/using-a-search-profile). See [custom models and jobs](advanced-usage/creating-multiple-search-indexes#custom-models-and-jobs) for the model and worker replacement contracts.

Laravel Go v0.1.0 does not replace the first service returned by `ServicesOf` when you register another instance of the same type. Use these explicit configuration points instead.

Configure queued crawls
-----------------------------------------------------------------------------------------------------------------------------

The crawl command dispatches one job per enabled site. Set up your application's queue connection and run a worker:

```
laravel queue:work
```

For the database queue, register a migration with `Run: queue.CreateTables` from `go.laravel.com/queue`, then run `laravel migrate`. Queue tables belong to your application and are not created by this package. You can instead use `laravel site-search:crawl --sync` without a worker.

The default crawl timeout is five minutes. Change `cfg.CrawlTimeout` to allow longer crawls. Configure the queue's retry interval to exceed that timeout, and use a shared cache store when workers run in different processes. The package takes a per-configuration crawl lock. It prevents overlapping execution, but unlike PHP's unique jobs, it does not deduplicate jobs waiting in the queue.

To refresh indexes automatically, add this to your application's schedule:

```
s.Command("site-search:crawl").Daily()
```

Run your application's scheduler as described in the Laravel Go scheduling guide. The package does not schedule crawls automatically.

Search driver
-----------------------------------------------------------------------------------------------

The default driver uses your application's database for full-text search. See [Using the database driver](advanced-usage/using-the-database-driver).

For synonyms and custom ranking rules, use [the Meilisearch driver](advanced-usage/using-the-meilisearch-driver).

 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)
