This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
ElasticQuery is a PHP library that converts Elasticsearch query DSL into typed PHP objects. Instead of building queries as arrays, developers can use strongly-typed classes that mirror the Elasticsearch documentation.
# Install/update dependencies
make composer
# Run static analysis (PHPStan level 7)
make phpstan
# Run code style checks (Slevomat coding standard)
make cs
# Auto-fix code style issues
make cbf
# Run tests (Nette Tester)
make tests
# Run a single test file
vendor/bin/tester -s -p php --colors 1 -C tests/SpameriTests/ElasticQuery/Path/To/Test.phptElasticQuery (src/ElasticQuery.php) - Main entry point for building queries. Composes:
QueryCollection- Boolean query with must/should/mustNot collectionsFilterCollection- Filter context queriesAggregationCollection- Aggregation definitionsOptions- Pagination, sorting, scroll settingsHighlight- Search result highlightingFunctionScore- Custom scoring functions
All query/aggregation objects implement toArray() to serialize to Elasticsearch-compatible format.
Leaf queries implement LeafQueryInterface:
ElasticMatch,MatchPhrase,MultiMatch,PhrasePrefix- Full-text queriesTerm,Terms,Range,Exists,WildCard- Term-level queriesNested,GeoDistance,Fuzzy- Specialized queries
Collection queries (MustCollection, ShouldCollection, MustNotCollection) also implement LeafQueryInterface, enabling nested boolean logic.
LeafAggregationCollectionwraps aggregation definitions with nested sub-aggregations- Metric aggregations:
Min,Max,Avg,TopHits - Bucket aggregations:
Term,Range,Histogram,Nested,Filter
ResultMapper converts Elasticsearch array responses to typed objects:
ResultSearch- Standard search results with hits and aggregationsResultSingle- Single document retrievalResultBulk- Bulk operation resultsResultVersion- Cluster version info
Classes for defining Elasticsearch index mappings:
- Analyzers: Standard, custom dictionary analyzers for multiple languages
- Filters: Stemming, synonyms, stop words, edge n-grams
- Tokenizers: Pattern, whitespace, etc.
Settings- Index settings configuration
Document wraps index name, body, and optional ID for Elasticsearch client calls.
Options- Pagination (size, from), scroll support, min_score, version inclusionSort- Field sorting with ASC/DESC and missing value handlingGeoDistanceSort- Geo-spatial sorting by distance from a pointSortCollection- Manages multiple sort criteria
Custom scoring with multiple score functions:
FieldValueFactor- Score based on numeric field values with modifiers (log, sqrt, etc.)Weight- Constant weight multiplier when filter matchesRandomScore- Randomized scoring with optional seed for consistency
Score modes: multiply, sum, avg, first, max, min
- PHP 8.2+ with strict types
- Fully qualified class names in annotations
- Fully qualified global functions and constants
- Tab indentation (no spaces)
- Trailing commas in arrays, function calls, and declarations
- Constructor property promotion where applicable
- No Yoda comparisons
- Strict equality operators only (
===,!==)