Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ibexa Solr Search Query Boost Laravel Package

contextualcode/ibexa-solr-search-query-boost

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require contextualcode/ibexa-solr-search-query-boost
    

    Ensure your project uses eZ Platform (now Ibexa DXP) with Solr as the search engine.

  2. 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']
    
  3. 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()
        );
    

Implementation Patterns

Usage Patterns

  1. 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();
    
  2. 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);
    
  3. Combining with eZ Platform Search Integrate with existing SearchService logic:

    $searchResult = $searchService->search($query, $searchCriteria);
    $searchCriteria->setBoost($boostBuilder->build());
    

Workflows

  • Content Prioritization: Boost high-value content types (e.g., "Featured Articles") by content_type_identifier.
  • Field Weighting: Amplify relevance of critical fields (e.g., title or tags) during search.
  • A/B Testing: Temporarily adjust boost factors to test search performance.

Integration Tips

  • Solr Schema Alignment: Ensure your Solr schema includes the fields you plan to boost (e.g., content_type_identifier).
  • Caching: Cache boost configurations if they are static (e.g., per-content-type boosts).
  • Logging: Log boost adjustments for debugging:
    $this->logger->info('Applied boosts', ['boosts' => $boostBuilder->getBoosts()]);
    

Gotchas and Tips

Pitfalls

  1. Field Mismatch

    • Issue: Boosting a field that doesn’t exist in Solr or isn’t indexed in eZ Platform.
    • Fix: Verify Solr schema and eZ Platform field mappings. Use solr.schema.xml to confirm field names.
  2. Over-Boosting

    • Issue: Excessive boost factors (e.g., > 5.0) can distort search relevance.
    • Fix: Test incrementally (e.g., 1.0, 2.0, 3.0) and monitor results.
  3. Case Sensitivity

    • Issue: Solr field names in boosts must match the schema exactly (e.g., content_type_identifier vs. ContentTypeIdentifier).
    • Fix: Use lowercase or exact schema names.
  4. Performance Impact

    • Issue: Complex boost queries may slow down searches.
    • Fix: Limit boosts to 3–5 critical fields/values.

Debugging

  • Solr Admin UI: Check the boost query in the Solr query parser to validate syntax.
  • eZ Platform Logs: Enable ezsearch logging in config/logging.php:
    'channels' => [
        'ezsearch' => [
            'level' => 'debug',
        ],
    ],
    
  • Boost Validation:
    if (!$boostBuilder->isValid()) {
        throw new \RuntimeException('Invalid boost configuration: ' . $boostBuilder->getErrors());
    }
    

Extension Points

  1. 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();
        }
    }
    
  2. 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());
    
  3. 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);
        }
    }
    
  4. Configuration Overrides Override boost defaults in config/ibexa/solr_boost.php:

    return [
        'default_boosts' => [
            'content_type_identifier' => [
                'article' => 1.5,
                'news' => 2.0,
            ],
        ],
    ];
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels
wazza/laravel-db-encryption
hokny/laravel-generator
vonsogt/backup
jengo/queues
jeremykenedy/laravel-observability
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums