PHPackages                             toxygene/solarium-specification - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. toxygene/solarium-specification

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

toxygene/solarium-specification
===============================

Specification pattern library for Solarium select queries

0.0.2(8y ago)011PHP

Since Aug 27Pushed 8y ago1 watchersCompare

[ Source](https://github.com/toxygene/solarium-specification)[ Packagist](https://packagist.org/packages/toxygene/solarium-specification)[ RSS](/packages/toxygene-solarium-specification/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

Solarium Specification library
==============================

[](#solarium-specification-library)

Create Solarium queries for the [standard query parser](https://lucene.apache.org/solr/guide/6_6/the-standard-query-parser.html#the-standard-query-parser) using the [Specification pattern](https://en.wikipedia.org/wiki/Specification_pattern).

Example
-------

[](#example)

```
use Solarium\Core\Client\Client;
use Solarium\QueryType\Select\Result\Result;
use SolariumSpecification\ModifyQueryInterface;
use SolariumSpecification\ModifyQuerySpecification\CompositeModifyQuerySpecification;
use SolariumSpecification\ModifyQuerySpecification\SetHandler;
use SolariumSpecification\ModifyQuerySpecification\SetResultClass;
use SolariumSpecification\ModifyQuerySpecificationInterface;
use SolariumSpecification\QueryInterface;
use SolariumSpecification\QuerySpecification\DateTime;
use SolariumSpecification\QuerySpecification\Field;
use SolariumSpecification\QuerySpecification\Operator\AndX;
use SolariumSpecification\QuerySpecification\Operator\OrX;
use SolariumSpecification\QuerySpecificationInterface;
use SolariumSpecification\QuerySpecification\Range;
use SolariumSpecification\QuerySpecification\Term\Phrase;
use SolariumSpecification\QuerySpecification\Term\SingleTerm;

// Only match results with a `last_updated_at` after a supplied DateTime
class UpdatedAfter implements QuerySpecificationInterface
{
    private $updatedAfter;

    public function __construct(DateTimeImmutable $updatedAfter)
    {
        $this->updatedAfter = $updatedAfter;
    }

    public function getQuery(): QueryInterface
    {
        return new Field(
            'last_updated_at',
            new Range((new DateTime($this->updatedAfter))->getQueryString())
        );
    }
}

// Only match results assign to a supplied `category`
class FilterByCategory implements QuerySpecificationInterface
{
    private $category;

    public function __construct(QueryInterface $category)
    {
        $this->category = $category;
    }

    public function getQuery(): QueryInterface
    {
        return new Field(
            'category',
            $this->category
        );
    }
}

// Combine `UpdatedAfter` for the last week and `FilterByCategory` for 'Consumer Electronics'
class RecentlyUpdatedElectronics implements QuerySpecificationInterface
{
    public function getQuery(): QueryInterface
    {
        return new AndX([
            new UpdatedAfter(new DateTimeImmutable('-1 week')),
            new FilterByCategory(new OrX([new Phrase('Consumer Electronics'), new SingleTerm('Electronics')]))
        ]);
    }
}

// Solarium result class
class ProductsResult extends Result
{
}

// Set the result class to `ProductResult`
class ProductResult implements ModifyQuerySpecificationInterface
{
    public function getModifyQuery(): ModifyQueryInterface
    {
        return new SetResultClass(ProductsResult::class);
    }
}

// Set the query handler to `Products`
class ProductHandler implements ModifyQuerySpecificationInterface
{
    public function getModifyQuery(): ModifyQueryInterface
    {
        return new SetHandler('Products');
    }
}

// Combine the ProductResult and ProductHandler modify specifications
class Products implements ModifyQuerySpecificationInterface
{
    public function getModifyQuery(): ModifyQueryInterface
    {
        return new CompositeModifyQuerySpecification([
            new ProductResult(),
            new ProductHandler()
        ]);
    }
}

var_dump((new RecentlyUpdatedElectronics())->getQuery()->getQueryString()); // '(last_updated_at:[2016-07-06T19:36:23Z] AND category:("Consumer Electronics" OR "Electronics"))'

$solariumClient = new Client();
$query = $solariumClient->createSelect();

(new Products())->getModifyQuery()->modify($query);

var_dump($query->getResultClass()); // 'ProductsResult'
var_dump($query->getHandler()); // 'Products'
```

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

3223d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/350210?v=4)[Justin Hendrickson](/maintainers/toxygene)[@toxygene](https://github.com/toxygene)

---

Top Contributors

[![toxygene](https://avatars.githubusercontent.com/u/350210?v=4)](https://github.com/toxygene "toxygene (48 commits)")

---

Tags

phpsolariumsolr

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/toxygene-solarium-specification/health.svg)

```
[![Health](https://phpackages.com/badges/toxygene-solarium-specification/health.svg)](https://phpackages.com/packages/toxygene-solarium-specification)
```

###  Alternatives

[prewk/xml-faker

Create random XML with the help of fzaniotto/Faker.

101.9k3](/packages/prewk-xml-faker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
