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 Search Laravel Package

ezsystems/ezplatform-search

Elasticsearch search integration for eZ Platform (eZ Publish) via the eZ Platform Search component. Provides indexing and query support to power site search, content discovery, and filtering in eZ Platform projects using an Elasticsearch backend.

View on GitHub
Deep Wiki
Context7

Getting Started

First Steps

  1. Installation Add the package via Composer:

    composer require ezsystems/ezplatform-search
    

    Publish the configuration (if needed):

    php artisan vendor:publish --provider="EzSystems\EzPlatformSearch\EzPlatformSearchServiceProvider"
    
  2. Basic Setup Register the search service in your config/services.php:

    'ezplatform-search' => [
        'default' => env('SEARCH_CONNECTION', 'default'),
        'connections' => [
            'default' => [
                'driver' => 'ezplatform',
                'options' => [
                    'repository' => 'ezpublish.api.repository',
                ],
            ],
        ],
    ],
    
  3. First Query Inject the search service into a controller or command:

    use EzSystems\EzPlatformSearch\SearchService;
    
    public function __construct(SearchService $searchService) {
        $this->searchService = $searchService;
    }
    
    public function searchContent() {
        $search = $this->searchService->createSearch();
        $result = $search->find('content', ['query' => 'marketing']);
        return $result->getResults();
    }
    
  4. Key Documentation

    • EzPlatformSearch API Docs (if available)
    • Check vendor/ezsystems/ezplatform-search/src/ for core classes like SearchService, Search, and Query.

Implementation Patterns

Common Workflows

  1. Searching Content Use SearchService to create a Search instance and execute queries:

    $search = $searchService->createSearch();
    $query = new Query\Query();
    $query->query = new Query\Criteria\Query('marketing');
    $query->filter = new Query\Criteria\Filter\ContentTypeFilter('marketing_page');
    
    $result = $search->find('content', $query);
    $hits = $result->getResults();
    
  2. Pagination Limit and paginate results:

    $query->limit = 10;
    $query->offset = 20;
    
  3. Sorting Sort by relevance or custom fields:

    $query->sort = [
        new Query\Criteria\Sort\FieldSort('content', 'modified', 'desc'),
    ];
    
  4. Highlighting Enable snippet highlighting:

    $query->highlight = new Query\Criteria\Highlight();
    $query->highlight->fields = ['content'];
    
  5. Integration with Eloquent If using a hybrid setup, map results to Eloquent models:

    $results = $result->getResults();
    $mapped = $results->map(fn ($hit) => new MyModel($hit->getContent()));
    

Advanced Patterns

  1. Custom Query Builders Extend Query\Query for reusable logic:

    class MarketingQuery extends Query\Query {
        public function __construct() {
            $this->filter = new Query\Criteria\Filter\ContentTypeFilter('marketing_page');
            $this->sort = [new Query\Criteria\Sort\FieldSort('content', 'modified', 'desc')];
        }
    }
    
  2. Event-Driven Search Listen for search events (e.g., SearchEvent::POST_SEARCH):

    event(new SearchEvent($query, $result));
    
  3. Caching Results Cache frequent queries (e.g., using Laravel Cache):

    $cacheKey = 'search:marketing';
    $results = Cache::remember($cacheKey, now()->addHours(1), function () use ($search) {
        return $search->find('content', $query)->getResults();
    });
    
  4. Search in API Resources Return search results in API responses:

    return new SearchResource($result->getResults());
    

Gotchas and Tips

Pitfalls

  1. Deprecation Warnings

    • The package is older (last release 2023-05-31). Check for deprecated methods like:
      // Deprecated in newer versions
      $search->search($query);
      // Use instead:
      $search->find('content', $query);
      
  2. Criteria vs. Query Confusion

    • Query\Criteria is used for filtering/sorting, while Query\Query wraps the entire search request.
    • Mixing them incorrectly may throw InvalidArgumentException.
  3. Performance with Large Datasets

    • Avoid unbounded queries (e.g., no limit/offset). Use:
      $query->limit = 100; // Always set a limit
      
  4. Content Not Found

    • If results are empty, verify:
      • The ContentType exists in the repository.
      • The query or filter is correctly configured.
      • The SearchService is bound to the right repository.
  5. Case Sensitivity

    • Search is case-sensitive by default. Use Query\Criteria\Query::setCaseSensitive(false) if needed.

Debugging Tips

  1. Log Queries Enable debug mode in config:

    'debug' => env('APP_DEBUG', false),
    

    Log raw queries for troubleshooting:

    \Log::debug('Search Query:', $query->toArray());
    
  2. Check Repository Binding Ensure the repository option in config points to a valid EzPublish repository:

    'options' => [
        'repository' => 'ezpublish.api.repository', // Must match your DI container
    ],
    
  3. Validate Criteria Use Query\Criteria\Validator to check syntax:

    $validator = new Query\Criteria\Validator();
    $errors = $validator->validate($query);
    
  4. Test with Simple Queries Start with a broad query (e.g., *) to isolate issues:

    $query->query = new Query\Criteria\Query('*');
    

Extension Points

  1. Custom Drivers Extend the Driver interface to support new backends (e.g., Elasticsearch):

    class ElasticsearchDriver implements DriverInterface {
        // Implement search logic
    }
    
  2. Query Transformers Modify queries before execution:

    $search->addTransformer(function (Query\Query $query) {
        $query->highlight = new Query\Criteria\Highlight();
        return $query;
    });
    
  3. Result Mappers Transform raw results into custom objects:

    $search->addMapper(function (Result\Result $result) {
        return $result->getResults()->map(fn ($hit) => new MyModel($hit));
    });
    
  4. Event Listeners Hook into search lifecycle events:

    // In a service provider
    $this->app->booted(function () {
        event(new SearchEvent($query, $result));
    });
    

Configuration Quirks

  1. Default Connection Ensure SEARCH_CONNECTION in .env matches your config:

    SEARCH_CONNECTION=default
    
  2. Repository Dependency The package requires ezpublish.api.repository. If using Symfony DI:

    # config/services.yaml
    EzSystems\EzPlatformSearch\EzPlatformSearchServiceProvider:
        arguments:
            $repository: '@ezpublish.api.repository'
    
  3. Timeouts Adjust timeout settings in config:

    'options' => [
        'timeout' => 30, // seconds
    ],
    
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.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle