PHPackages                             lmc/cqrs-solr - 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. [API Development](/categories/api)
4. /
5. lmc/cqrs-solr

ActiveLibrary[API Development](/categories/api)

lmc/cqrs-solr
=============

A library containing base implementations to help with Solr Queries and Commands

3.1.0(2y ago)111.2k↑33.3%1[2 PRs](https://github.com/lmc-eu/cqrs-solr/pulls)1MITPHPPHP ^8.2CI passing

Since May 13Pushed 11mo ago11 watchersCompare

[ Source](https://github.com/lmc-eu/cqrs-solr)[ Packagist](https://packagist.org/packages/lmc/cqrs-solr)[ RSS](/packages/lmc-cqrs-solr/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (10)Versions (12)Used By (1)

LMC CQRS Solr extension
=======================

[](#lmc-cqrs-solr-extension)

[![cqrs-types](https://camo.githubusercontent.com/d2e4a1ae4631bc4819c80a7abc5aa314a298c371e9ab906ccf0eecdd16e00aaa/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f637172732d74797065732d707572706c652e737667)](https://github.com/lmc-eu/cqrs-types)[![Latest Stable Version](https://camo.githubusercontent.com/7ee522da927e043219b7c6a4ad2f18349a44b972a9d401cc5c4e329bb0b2bb78/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6d632f637172732d736f6c722e737667)](https://packagist.org/packages/lmc/cqrs-solr)[![Tests and linting](https://github.com/lmc-eu/cqrs-solr/actions/workflows/tests.yaml/badge.svg)](https://github.com/lmc-eu/cqrs-solr/actions/workflows/tests.yaml)[![Coverage Status](https://camo.githubusercontent.com/22f909775e197a7152b076777623ecf6b6787a1b2fc01de9c7614b54d454180e/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6c6d632d65752f637172732d736f6c722f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/lmc-eu/cqrs-solr?branch=main)

> A library containing base implementations to help with Solr Queries and Commands. This library is an extension for [CQRS/Bundle](https://github.com/lmc-eu/cqrs-bundle) and adds support for `Solarium` requests.

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- Queries
    - [Query](#query)
    - [Query Handlers](#query-handlers)
- Commands
    - [Send Command Handlers](#send-command-handlers)
    - [Command](#command)
- [Response Decoders](#response-decoders)
- [Profiler Formatters](#profiler-formatters)
- [Value Objects](#value-objects)
- [Query Builder](#query-builder)

Installation
------------

[](#installation)

```
composer require lmc/cqrs-solr
```

**NOTE**: It also requires [Solarium](https://github.com/solariumphp/solarium) and [Solarium bundle](https://github.com/nelmio/NelmioSolariumBundle), which are directly required by this library.

Query
-----

[](#query)

Query is a request which fetch a data without changing anything. [See more here](https://github.com/lmc-eu/cqrs-types#query-interface)

It is allowed and recommended to use a `InjectSolrClientInterface` with a Solr queries, so you don't need to worry about a `Solarium Client`, you will simply get it automatically.

### AbstractSolrQuery

[](#abstractsolrquery)

A base Solr Query, it abstracts and predefine some of a most used features with this kind of a Query.

It implements a `ProfileableInterface` and `CacheableInterface` features.

MethodTypeDescription`getRequestType`**final**It declares a request type of a query to be a `SolrRequest``createRequest`abstractIt declares a base `QueryInterface` method to return a `SolrRequest` type.`getRequestUrl`*base*It's a predefined method which creates a request and build a solarium request to return a final url.`getCacheTime`*base*It returns a default value for a cache time of 30 minutes.`getCacheKey`*base*It creates a `CacheKey` out of an `Solr endpoint`, a static class name (*your implementation class name*) and a `md5` representation of a final `url`, which should create a unique enough cache key for most queries.`getProfilerId`*base*It's a predefined creating of profiler id for a Solr query. It creates a profiler id based on a final `url`.`getProfilerData`*base*If you overwrite this method, you can specify additional profiler data. Default is `null` (*no data*).`getEndpoint`*base*It returns a `Solr endpoint` for your Query.`__toString`*base*It's a predefined casting a Query into string, it returns a string representation of a final `url`.### AbstractSolrSelectQuery

[](#abstractsolrselectquery)

A base Solr **Select** Query, it abstracts and predefine some of a most used features with this kind of a Query.

It extends a base `AbstractSolrQuery` and predefine some abstract methods. It also adds `InjectSolrClientInterface` feature, since it needs a `Solarium Client` to create a `Select Request`.

MethodTypeDescription`setOffset`*base*It simply sets an offset (*where should select start*) for a Solr select request.`setLimit`*base*It simply sets a limit (*number of rows*) for a Solr select request.`createRequest`**final**It creates a `SolrRequest` with a prepared `Solarium Select`.`prepareSelect`abstractIt requires you prepare a Solr select request. What do you actually wants to select - set of fields and other select properties.### BuilderPrototypeQuery

[](#builderprototypequery)

This is a special type of a `SolrSelectQuery` it also extends an `AbstractSolrSelectQuery` and implement `prepareSelect` method with a usage of [QueryBuilder applicators](#query-builder).

It is a Query, which `QueryBuilder` creates for you.

Query Handlers
--------------

[](#query-handlers)

It is responsible for handling a specific Query request and passing a result into `OnSuccess` callback. [See more here](https://github.com/lmc-eu/cqrs-types#query-handler-interface).

### Solr Query Handler

[](#solr-query-handler)

This handler supports `Lmc\Cqrs\Solr\ValueObject\SolrRequest` (see [SolrRequest](#solrrequest)) and handles it into `Solarium\Core\Query\Result\ResultInterface`.

It also prepares a Query implementing a `InjectSolrClientInterface` by injecting a `Solarium Client` into a Query so it is not required for you to inject a `Solarium Client` into a query by yourself.

---

Value Objects
-------------

[](#value-objects)

### SolrField

[](#solrfield)

It is a representation of any data passed by user to Solr (eg. in query or a list of fields returned by Solr)

### SolrRequest

[](#solrrequest)

It is a simple Value object containing an `Abstract Solarium Query` and optionally a `Solr endpoint`.

---

Query Builder
-------------

[](#query-builder)

> Query builder is an abstraction above a Solarium Select Query set up.

The idea is that you have just a data, used in select, stored in an entity. The entity stands for what you want to select and how. And according to interfaces, that this entity implements, the data is passed into a Select Query.

Query Builder builds a [BuilderPrototypeQuery](#builderprototypequery) which is an instance of `QueryInterface` and is useable in [CQRS/QueryFetcher](https://github.com/lmc-eu/cqrs-types#query-fetcher-interface) with all supported features.

### Example

[](#example)

Imagine you need to select 30 `Persons` with fields `Name` and `Age` by `search input`, stored in a Solr, you would have something like:

```
$searchInput = $_GET['search'];

$selectPersons = $client->createSelect();
$selectPersons->getEDisMax()->setQueryFields('name^100 age^50');
$selectPersons->setQuery($searchInput);
$selectPersons->setNumberOfRows(30);

$result = $client->execute($selectPersons);
```

With direct Solarium usage you need to create a Select Query yourself and remember all setters and stuff.

Now Query Builder offers a predefined applicators, which knows how the Select query is built and just need a data for the select query.

Example above using a Query Builder would look something like:

```
class PersonSearch implements FulltextInterface
{
    private string $searchInput;

    public function __construct(string $searchInput)
    {
        $this->searchInput = $searchInput;
    }

    public function getKeywords(): array
    {
        return explode(' ', $this->searchInput);
    }

    public function getNumberOfRows(): int
    {
        return 30;
    }

    public function getQueryFields(): array
    {
        return [
            'name^100',
            new SolrField('age', '', 0, 50),     // you can also use a SolrField value object, so you don't need to remember how is a prioritized value built
        ];
    }

    public function isEDisMaxEnabled(): bool
    {
        return true;
    }

    public function useEDisMaxGlobally(): bool
    {
        return true;
    }

    // Note: there are more methods, you need to implement, but we want to keep this example simple as possible. If you don't need other functionality, simply return null or empty variant from a method.
}

$searchInput = $_GET['search'];

$selectPersonsEntity = new PersonSearch($searchInput);
$selectPersonsQuery = $queryBuilder->buildQuery($selectPersonsEntity);

$result = $queryFetcher->fetchAndReturn($selectPersonsQuery);
```

### Entity Interface

[](#entity-interface)

It is a definition interface for a specific feature set you want a query to have.

**Note**: It is not a complete set of Solr/Solarium Select features, it is just our most used features.

- `EntityInterface`
    - A base interface for all features, which adds a `getFields` and `getNumberOfRows` base methods. |
- `FacetsInterface`
- `FilterInterface`
- `FiltersInterface`
- `FulltextBigramInterface`
- `FulltextBoostInterface`
- `FulltextInterface`
- `GroupingFacetInterface`
- `GroupingInterface`
- `ParameterizedInterface`
- `SortInterface`
- `StatsInterface`

### Applicators

[](#applicators)

Applicator is a service which can apply a specific set of data into a Solarium select query based on implemented Interface. It must implement a `ApplicatorInterface`.

You can implement your own applicator if you want to mix features or simply use a feature, which does not have an applicator yet.

#### ApplicatorInterface

[](#applicatorinterface)

It is an interface, which all applicators must implement. It specifies which Entity is current applicator supporting and it can apply its data into Solarium request. It should be able to skip setting a value, if it is empty.

#### Applicator Factory

[](#applicator-factory)

It is a service with all defined applicators, its purpose is to return all applicators supporting a given Entity. It is used inside a `QueryBuilder` to get a list of applicators, which needs to be applied on Select Query.

#### List of all applicators

[](#list-of-all-applicators)

- `EntityApplicator`
- `FacetsApplicator`
- `FilterApplicator`
- `FiltersApplicator`
- `FulltextApplicator`
- `FulltextBigramApplicator`
- `FulltextBoostApplicator`
- `GroupingApplicator`
- `GroupingFacetApplicator`
- `ParameterizedApplicator`
- `SortApplicator`
- `StatsApplicator`

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity71

Established project with proven stability

 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 ~171 days

Recently: every ~235 days

Total

7

Last Release

803d ago

Major Versions

1.3.0 → 2.0.02022-03-30

2.0.0 → 3.0.02022-04-27

PHP version history (3 changes)1.0.0PHP ^7.4

3.0.0PHP ^8.1

3.1.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/2bdf0b9957c08a48e70a52fce74fc4f1add30b12d442450d5e2b48854fc98b21?d=identicon)[MortalFlesh](/maintainers/MortalFlesh)

---

Top Contributors

[![MortalFlesh](https://avatars.githubusercontent.com/u/6317184?v=4)](https://github.com/MortalFlesh "MortalFlesh (24 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/lmc-cqrs-solr/health.svg)

```
[![Health](https://phpackages.com/badges/lmc-cqrs-solr/health.svg)](https://phpackages.com/packages/lmc-cqrs-solr)
```

###  Alternatives

[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)[hubspot/api-client

Hubspot API client

23914.2M16](/packages/hubspot-api-client)[botman/driver-telegram

Telegram driver for BotMan

92437.3k6](/packages/botman-driver-telegram)

PHPackages © 2026

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