ezsystems/ezplatform-solr-search-engine
Installation Add the package via Composer:
composer require ezsystems/ezplatform-solr-search-engine
Ensure ezplatform-solr-search-engine is enabled in config/packages/ezplatform.yaml:
ezplatform:
search:
engine: ezplatform_solr_search_engine
Solr Configuration
Define Solr connection in config/packages/ezplatform_solr_search_engine.yaml:
ezplatform_solr_search_engine:
clients:
default:
host: 'http://solr:8983/solr'
core: 'ezplatform'
timeout: 30
First Use Case Trigger a full reindex via CLI:
php bin/console ezplatform:search:reindex
Verify Solr core data via:
php bin/console ezplatform:search:debug
Search Queries
Use the SearchService to execute queries:
$searchService = $this->container->get('ezpublish.api.service.search');
$query = new SearchService\Query\Query();
$query->query = new SearchService\Query\Criteria\Query('content');
$result = $searchService->findQuery($query);
Custom Field Mappings
Extend Solr field mappings in config/packages/ezplatform_solr_search_engine.yaml:
ezplatform_solr_search_engine:
field_mappings:
content:
identifier: 'id'
name: 'name'
custom_field: 'custom_field_name'
Event-Driven Indexing
Listen to ContentUpdateEvent to trigger partial updates:
use EzSystems\EzPlatformSolrSearchEngine\Event\ContentUpdateEvent;
$eventDispatcher->addListener(
ContentUpdateEvent::NAME,
[$this, 'onContentUpdate']
);
public function onContentUpdate(ContentUpdateEvent $event) {
$this->solrIndexer->indexContent($event->getContent());
}
Pagination & Sorting Configure Solr-specific parameters:
$query->query->offset = 0;
$query->query->limit = 20;
$query->query->sortClauses = [
new SearchService\Query\Criteria\SortClause\FieldSortClause('name', 'asc')
];
ezplatform_solr_search_engine:
cache:
enabled: true
provider: 'cache.app'
docker-compose.yml for local Solr:
services:
solr:
image: solr:8.11
ports:
- "8983:8983"
$this->getMockBuilder('Solarium\Client')
->disableOriginalConstructor()
->getMock();
Schema Mismatches
managed-schema) differ from eZ Platform field identifiers.php bin/console ezplatform:search:debug:schema
ezplatform_solr_search_engine:schema:update to sync schemas.Timeout Errors
ezplatform_solr_search_engine:
clients:
default:
timeout: 60
Partial Indexing Failures
ContentUpdateEvent may not trigger if content is not saved via the API.ezplatform:search:reindex:content for manual updates:
php bin/console ezplatform:search:reindex:content <content-id>
Case Sensitivity
managed-schema:
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
http://localhost:8983/solr/#/~collections to inspect cores and queries.config/packages/dev/ezplatform_solr_search_engine.yaml:
ezplatform_solr_search_engine:
debug: true
$query->setParam('debugQuery', 'true');
Custom Indexers
Implement EzSystems\EzPlatformSolrSearchEngine\Indexer\IndexerInterface for custom content types:
class CustomIndexer implements IndexerInterface {
public function indexContent(Content $content) {
// Custom logic
}
}
Register in services:
services:
App\Indexer\CustomIndexer:
tags: ['ezplatform.solr.indexer']
Solr Client Extensions Override the default Solr client via dependency injection:
services:
ezplatform_solr_search_engine.client.default:
class: App\Solr\CustomClient
arguments: ['@ezplatform_solr_search_engine.client.default']
Post-Processing Results
Use SearchResultTransformer to modify results:
$result->setTransformer(function (SearchResult $result) {
foreach ($result->getSearchHits() as $hit) {
$hit->value['custom_field'] = 'processed';
}
return $result;
});
How can I help you explore Laravel packages today?