Using the database driver | 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  Using the database driver

 Version   v1      

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

  Using the database driver    
- [ 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 the database driver
=========================

###  On this page 

1. [ How it works ](#content-how-it-works)
2. [ Using a different database connection ](#content-using-a-different-database-connection)
3. [ Differences from the Meilisearch driver ](#content-differences-from-the-meilisearch-driver)

The database driver is the default driver. It stores search documents in your application's database and uses the database's native full-text search capabilities. SQLite FTS5, MySQL and MariaDB FULLTEXT, and PostgreSQL text search are supported.

How it works
--------------------------------------------------------------------------------------------

All documents are stored in `site_search_documents`. Each document has an `index_name`, allowing multiple search indexes to coexist in the same table.

Full-text search infrastructure is created automatically when a physical index is created. The table migration is database-agnostic. The database account needs permission to create the full-text indexes and, for SQLite, the virtual table and triggers.

### Database-specific behavior

SQLite uses FTS5 virtual tables with Porter stemming and Unicode support. BM25 ranking weights matches in entries and descriptions higher than URL matches. SQLite generates highlighted snippets with FTS5.

MySQL and MariaDB use FULLTEXT indexes with boolean mode search. Highlighting is done in Go after the query. These engines do not provide English stemming. Stop words and minimum word lengths follow your server's FULLTEXT configuration. InnoDB full-text search sees committed documents, so commit writes before searching from another connection.

PostgreSQL uses weighted English text-search vectors and a GIN expression index. `ts_rank` ranks results and `ts_headline` highlights them.

### Search features

All supported databases provide prefix matching, relevance ranking and highlighted snippets with matching terms wrapped in `<em>` tags. SQLite and PostgreSQL also provide English stemming.

The database driver consolidates the entries for a URL within each update batch. The resulting document keeps the first nonempty anchor. See [Retrieving results](../basic-usage/retrieving-results#deep-linking-to-sections).

Extra properties are stored and returned, but the database's full-text index searches the standard text fields, not arbitrary JSON properties.

Using a different database connection
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

By default, the driver uses your application's default database connection. Set `database.connection` in a saved configuration's `Extra` to select a named Laravel connection:

```
{"database": {"connection": "search"}}
```

Create the document table on that connection before indexing. The package's automatic migrations run on the default connection. This lets you store search data separately from application data.

Differences from the Meilisearch driver
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

- No external search service is required.
- Synonyms and custom ranking rules are not supported.
- Indexing is synchronous.
- All entries for one URL in an update batch become one document.

 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)
