Weave Code
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

Ezplatform Solr Search Engine Laravel Package

ezsystems/ezplatform-solr-search-engine

Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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
    
  2. 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
    
  3. 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
    

Implementation Patterns

Core Workflows

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

Integration Tips

  • Symfony Cache: Leverage Symfony’s cache system for query results:
    ezplatform_solr_search_engine:
        cache:
            enabled: true
            provider: 'cache.app'
    
  • Docker Setup: Use docker-compose.yml for local Solr:
    services:
        solr:
            image: solr:8.11
            ports:
                - "8983:8983"
    
  • Testing: Mock Solr responses in PHPUnit:
    $this->getMockBuilder('Solarium\Client')
         ->disableOriginalConstructor()
         ->getMock();
    

Gotchas and Tips

Common Pitfalls

  1. Schema Mismatches

    • Issue: Field names in Solr schema (managed-schema) differ from eZ Platform field identifiers.
    • Fix: Validate mappings via:
      php bin/console ezplatform:search:debug:schema
      
    • Tip: Use ezplatform_solr_search_engine:schema:update to sync schemas.
  2. Timeout Errors

    • Issue: Large datasets may exceed Solr’s default timeout.
    • Fix: Increase timeout in config:
      ezplatform_solr_search_engine:
          clients:
              default:
                  timeout: 60
      
  3. Partial Indexing Failures

    • Issue: Events like ContentUpdateEvent may not trigger if content is not saved via the API.
    • Fix: Use ezplatform:search:reindex:content for manual updates:
      php bin/console ezplatform:search:reindex:content <content-id>
      
  4. Case Sensitivity

    • Issue: Solr queries may be case-sensitive by default.
    • Fix: Configure lowercase matching in managed-schema:
      <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
          <analyzer>
              <tokenizer class="solr.StandardTokenizerFactory"/>
              <filter class="solr.LowerCaseFilterFactory"/>
          </analyzer>
      </fieldType>
      

Debugging Tips

  • Solr Admin UI: Access http://localhost:8983/solr/#/~collections to inspect cores and queries.
  • Log Queries: Enable debug logging in config/packages/dev/ezplatform_solr_search_engine.yaml:
    ezplatform_solr_search_engine:
        debug: true
    
  • Query Profiling: Use Solr’s built-in query profiling:
    $query->setParam('debugQuery', 'true');
    

Extension Points

  1. 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']
    
  2. 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']
    
  3. 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;
    });
    
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware