klaasie / scout-solr-engine
An Apache Solr driver for laravel scout
Installs: 6 888
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 4
Forks: 2
Open Issues: 3
Requires
- php: ^8.0
- ext-json: *
- laravel/scout: ^9.0|^10.0
- solarium/solarium: ^6.2
Requires (Dev)
- orchestra/testbench: ^6.21|^7.0|^8.0|^9.0
- phpmd/phpmd: ^2.10
- phpunit/phpunit: ^9.3.3|^10.1
- squizlabs/php_codesniffer: ^3.6
This package is auto-updated.
Last update: 2024-10-31 00:23:29 UTC
README
This package provides a basic implementation of the Apache Solr search engine within Laravel Scout.
Installation
composer require klaasie/scout-solr-engine
config
This package provides a config file that can be modified using .env variables.
You can initialize your own config file with:
php artisan vendor:publish --provider="Scout\Solr\ScoutSolrServiceProvider"
scout:index
By default, Solr doesn't allow indexes (cores) to be created without providing the proper folders and files on the file system first.
However, if a default config set is set up in the Solr instance this becomes possible through the API.
The scout:index
command will only work if the Solr instance is properly configured and the config files has the corresponding name for the config set folder.
For more information, see https://solr.apache.org/guide/8_9/config-sets.html#config-sets
Cores (indexes)
Within the config file a core (index) is not provided. The engine will determine which core to connect to using the searchableAs()
method on the model.
Alternatively, if a specific model is on a different Solr instance, another configuration can be provided for this model.
It's important for the configuration key to match the searchableAs()
of the model.
Solarium
This package uses solarium/solarium to handle requests to the solr instance. This app is meant to be a simple implementation of the laravel/scout engine. For complex queries to the solr instance I would recommend initializing your own Solarium client and use that package. Visit https://solarium.readthedocs.io/en/stable/ to view the documentation of the solarium package.
For convenience, any unknown methods used on the engine will be forwarded to the solarium client.
$model = new \App\Models\SearchableModel(); /** @var \Scout\Solr\Engines\SolrEngine $engine */ $engine = app(\Laravel\Scout\EngineManager::class)->engine(); $select = $engine->setCore($model)->createSelect(); $select->setQuery('*:*'); $result = $engine->select($select, $engine->getEndpointFromConfig($model->searchableAs())); // getEndpointFromConfig() is only necessary when your model does not use the default solr instance.
Events
The Solr Engine dispatches several events allowing you to hook into specific points in the engine.
Example
This repository provides an example laravel app showcasing the functionality of this package.
Please refer to the README.md of the example app for information on how to get it started.