hamaka / silverstripe-typesense
Full-page Typesense search for Silverstripe CMS, with an instant-search overlay. Built on elliotsawyer/silverstripe-typesense.
Package info
github.com/hamaka/silverstripe-typesense
Type:silverstripe-vendormodule
pkg:composer/hamaka/silverstripe-typesense
Requires
- php: ^8.0
- ext-dom: *
- ext-libxml: *
- elliotsawyer/silverstripe-typesense: ^0.0.7
- masterminds/html5: ^2.9
- silverstripe/framework: ^5.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Full-page Typesense search for Silverstripe CMS 5. The module indexes each page as a visitor sees it, so content from elements, blocks and templates is searchable too, not only the Content field. It also ships an instant-search overlay that shows results while you type.
It is built on top of elliotsawyer/silverstripe-typesense, which provides the Typesense client, the collection models and the CMS admin.
How this differs from elliotsawyer/silverstripe-typesense
| elliotsawyer/silverstripe-typesense | This module | |
|---|---|---|
| What gets indexed | Database fields you configure per collection | The rendered page as plain text (FullPage), plus Title and URL |
| Keeping the index up to date | Sync task / queued jobs | Automatic upsert on publish, delete on unpublish or when Show in search is off, plus its own sync task |
| Frontend | None | Instant-search overlay (InstantSearch.js), ?q= in the URL with back-button support, GA4 / Tag Manager / Matomo events |
| Local development | — | _local collection suffix so local and production indexes don't mix |
The admin for collections, fields and synonyms is still the one from Elliot Sawyer's module. This module turns his sync task off and replaces it with TypesenseSyncTaskHmk.
Requirements
- PHP 8.0+
- Silverstripe CMS 5
- A running Typesense server
- jQuery and the Bootstrap
d-noneutility class on the frontend (used by the overlay, see Frontend search)
Installation
composer require hamaka/silverstripe-typesense
Then run vendor/bin/sake dev/build flush=1.
Quick start
-
Add the environment variables to your
.env:TYPESENSE_API_KEY="your-admin-api-key" TYPESENSE_SERVER="https://typesense.example.com:443" TYPESENSE_SEARCH_KEY="your-search-only-api-key"
-
Define a collection: copy
_config/typesense.yml.exampletoapp/_config/typesense.ymland give it a unique name. -
Build the index:
vendor/bin/sake dev/tasks/TypesenseSyncTaskHmk
-
Add the overlay to your template and load the script:
<% include TypesenseSearchOverlay %> <button class="js-search-open">Search</button> <script src="$resourceURL('hamaka/silverstripe-typesense:client/dist/javascript/bundle.js')"></script> <script> document.addEventListener('DOMContentLoaded', () => { new TypesenseInstantSearch({ indexName: 'your-collection' }); }); </script>
From then on, every publish updates the index.
Documentation
- How it works: how pages are rendered and turned into searchable text
- Configuration: environment variables, collections, DOM clean-up
- Frontend search: the overlay, JavaScript usage, analytics, known limitations
- Development: building the JavaScript bundle, releases
Changelog
See Releases for the changes in each version.
Credits and license
This module is released under the MIT license.
It depends on elliotsawyer/silverstripe-typesense by Elliot Sawyer, licensed under LGPL-3.0 with attribution. src/Tasks/TypesenseSyncTask.php is derived from that module's sync task and keeps its original copyright header.
