contextualcode/ibexa-solr-search-query-boost
Installation
composer require contextualcode/ibexa-solr-search-query-boost
Ensure your project uses eZ Platform (now Ibexa DXP) with Solr as the search engine.
Configuration
Add the service to your config/services.yaml (or equivalent) to enable the boost logic:
services:
Ibexa\Search\SearchService:
decorates: 'ibexa.search.search_service'
arguments: ['@.inner']
First Use Case Boost a specific content type or field in a search query:
use Contextualcode\IbexaSolrSearchQueryBoost\Boost\BoostBuilder;
$searchService = $this->container->get('ibexa.search.search_service');
$searchService->getSearch()
->setQuery($query)
->setBoost(BoostBuilder::create()
->addBoost('content_type_identifier', 'article', 2.0)
->build()
);
Dynamic Boosting
Use the BoostBuilder to dynamically adjust search relevance at runtime:
$boostBuilder = BoostBuilder::create()
->addBoost('field_name', 'priority_value', 1.5)
->addBoost('content_type_identifier', 'news', 3.0)
->build();
Field-Specific Boosting
Target specific fields (e.g., name, body, or custom fields) for granular control:
$boostBuilder->addBoost('custom_field_name', 'high_priority', 2.5);
Combining with eZ Platform Search
Integrate with existing SearchService logic:
$searchResult = $searchService->search($query, $searchCriteria);
$searchCriteria->setBoost($boostBuilder->build());
content_type_identifier.title or tags) during search.content_type_identifier).$this->logger->info('Applied boosts', ['boosts' => $boostBuilder->getBoosts()]);
Field Mismatch
solr.schema.xml to confirm field names.Over-Boosting
> 5.0) can distort search relevance.1.0, 2.0, 3.0) and monitor results.Case Sensitivity
content_type_identifier vs. ContentTypeIdentifier).Performance Impact
boost query in the Solr query parser to validate syntax.ezsearch logging in config/logging.php:
'channels' => [
'ezsearch' => [
'level' => 'debug',
],
],
if (!$boostBuilder->isValid()) {
throw new \RuntimeException('Invalid boost configuration: ' . $boostBuilder->getErrors());
}
Custom Boost Logic
Extend BoostBuilder to support dynamic boosts (e.g., user-specific or time-based):
class DynamicBoostBuilder extends BoostBuilder {
public function addDynamicBoost(callable $callback) {
$this->boosts[] = $callback();
}
}
Solr Query Modifiers
Hook into Solr’s edismax or dismax parameters to combine with boosts:
$searchCriteria->query->setParam('defType', 'edismax');
$searchCriteria->query->setParam('boost', $boostBuilder->getSolrBoostQuery());
Event Subscribers
Automate boosts via eZ Platform events (e.g., ContentUpdateEvent):
public function onContentUpdate(ContentUpdateEvent $event) {
if ($event->getContent()->getContentInfo()->contentTypeId === 'article') {
$boostBuilder->addBoost('content_type_identifier', 'article', 2.0);
}
}
Configuration Overrides
Override boost defaults in config/ibexa/solr_boost.php:
return [
'default_boosts' => [
'content_type_identifier' => [
'article' => 1.5,
'news' => 2.0,
],
],
];
How can I help you explore Laravel packages today?