signify-nz / silverstripe-solr-search
Search a SilverStripe site with Solr
Package info
github.com/signify-nz/silverstripe-solr-search
Type:silverstripe-vendormodule
pkg:composer/signify-nz/silverstripe-solr-search
Requires
- php: >=7.3
- ext-json: *
- guzzlehttp/guzzle: ^6.3|^7
- http-interop/http-factory-guzzle: ^1
- minimalcode/search: ^1.0
- php-http/discovery: ^1.14
- php-http/guzzle7-adapter: ^1.0.0
- silverstripe/framework: ^4|^5
- solarium/solarium: ^6.0
- symbiote/silverstripe-queuedjobs: ^4|^5
- symfony/event-dispatcher: ^5.4|^6
Requires (Dev)
Replaces
This package is not auto-updated.
Last update: 2026-07-02 02:16:26 UTC
README
Advanced, Solr-powered search for SilverStripe 4 and 5, built on Solarium. Define what to index in PHP, configure connections in YAML, and query Solr with a fluent API.
Based on firesphere/solr-search. This is the
signify-nzmaintained fork.
Features
- Code-defined indexes — declare indexed classes and fields in a PHP index class.
- Rich field types — full-text, filter, facet, sort, stored and copy fields.
- Faceting, boosting, fuzzy search, elevation and advanced filters/excludes.
- Spellcheck & suggestions for "did you mean" experiences.
- View-permission aware — results are filtered by each member's
canViewrights. ShowInSearchhandled automatically — hidden pages/files are removed from the core.- Queued indexing via
silverstripe/queuedjobs, indexing live content only. - Subsites, Fluent, Elemental and Fulltext-Search compatibility submodule support.
- Pluggable config stores — file-based or HTTP POST to a remote Solr.
- Works with Solr 4 (backward compatible), 8 (default) and 9.
Requirements
- PHP 7.3+
- SilverStripe Framework 4 or 5
- symbiote/silverstripe-queuedjobs
- A running Solr instance (4 / 8 / 9) reachable from the application
- Solarium (installed automatically via Composer)
Installation
composer require signify-nz/silverstripe-solr-search
See docs/01-Installation.md for details.
Quick start
1. Configure the Solr connection
Connection details are set in YAML. Defaults assume a Solr instance on
localhost:8983, so this step can be skipped for local development.
# app/_config/search.yml Firesphere\SolrSearch\Services\SolrCoreService: config: endpoint: myhostname: host: solr.example.com port: 8983 timeout: 10 store: path: '.solr'
See docs/03-Set-up-and-Configuration.md for authentication, config stores and all available options.
2. Define an index
Create an index extending Firesphere\SolrSearch\Indexes\BaseIndex. The
init() method declares what is indexed; getIndexName() names the Solr core.
use Firesphere\SolrSearch\Indexes\BaseIndex; use SilverStripe\Assets\File; use SilverStripe\CMS\Model\SiteTree; class MyIndex extends BaseIndex { public function init() { $this->addClass(SiteTree::class); $this->addClass(File::class); $this->addFulltextField('Title'); $this->addFulltextField('Content'); $this->addFilterField('ClassName'); } public function getIndexName() { return 'mysite-search'; } }
3. Configure the core and index your content
# Push the generated schema/config to Solr and (re)create the core vendor/bin/sake dev/tasks/SolrConfigureTask # Queue a job to index your content vendor/bin/sake dev/tasks/SolrIndexTask
Make sure the queued-jobs runner is processing jobs (and restart long-running workers after deploying code changes, so they pick up the new classes).
4. Run a search
use Firesphere\SolrSearch\Indexes\BaseIndex; use Firesphere\SolrSearch\Queries\BaseQuery; use SilverStripe\Core\Injector\Injector; class SearchPageController extends PageController { public function getResults() { $term = $this->getRequest()->getVar('Search'); if (!$term) { return null; } /** @var BaseIndex $index */ $index = Injector::inst()->get(MyIndex::class); $query = Injector::inst()->get(BaseQuery::class); $query->addTerm($term); $query->setStart((int) $this->getRequest()->getVar('start')); return $index->doSearch($query); // returns a SearchResult } }
5. Render the results
<% with $Results %> <% if $TotalItems %> <p>$TotalItems results</p> <% loop $PaginatedMatches %> <h3><a href="$Link">$Title</a></h3> <p>$Excerpt</p> <% end_loop %> <% include Pagination %> <% else %> <p>No results found.</p> <% end_if %> <% end_with %>
A fuller example (facets, sorting, spellcheck) is in docs/04-Searching.md.
Tasks
| Task | Purpose |
|---|---|
SolrConfigureTask |
Generate and upload the core configuration/schema to Solr. |
SolrIndexTask |
Queue a job to (re)index content into existing cores. |
FullSolrIndexTask |
Queue a full reindex of all indexes and classes. |
ClearDirtyClassesTask |
Re-process records that previously failed to index (see Dirty classes). |
ClearErrorsTask |
Clear recorded indexing errors. |
Indexing reads from the live stage, so only published content is added to the search index. A standard
SolrIndexTaskadds/updates documents but does not clear the core, so after changing index definitions runSolrConfigureTask(or a clearing reindex) to drop stale documents.
Key concepts
ShowInSearchis managed by the module. Setting it to0/false removes the page or file from the core viaonAfterPublish/onAfterWriteor the next index run — do not add it as a custom indexed field, as that causes unexpected behaviour. See docs/03-Set-up-and-Configuration.md.- View permissions — each document stores a view-status field so results are
filtered to what the current member may
canView. See docs/11-View-Permissions.md. - Dirty classes — records that fail to push to Solr are tracked so they can be retried rather than silently lost. See docs/12-Dirty-classes.md.
- Config stores —
FileConfigStore(local path) orPostConfigStore(HTTP POST to a remote Solr). See docs/06-Advanced-Options/06-Stores.md.
Documentation
Full documentation lives in the docs folder:
- Installation · Solr · Setup & configuration
- Searching · Spellcheck · Customisation
- Advanced options: Faceting, Boosting, Fuzzy search, Elevation, Filters / Excludes, Stores
- CMS usage · Debugging · Suggestions · View permissions · Dirty classes · Subsites
- Submodules: Fulltext Search compatibility, Fluent, Member-based permissions, Elemental
Please read the documentation before raising questions — most are answered there.
Solr version support
| Solr version | Status |
|---|---|
| 4 | Backward compatible |
| 8 | Default / recommended |
| 9 | Supported |
Solarium
This module is built on Solarium; its documentation is a useful reference for lower-level query behaviour.
Contributing
Contributions are welcome — please raise an issue and, ideally, an accompanying pull request. See the code of conduct and contributing guide.
Security
Please report security issues responsibly as described in our security policy.
License
Disclaimer
If this module breaks your website, you get to keep all the pieces.