PHPackages                             sammaye/yii2-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. [Search &amp; Filtering](/categories/search)
4. /
5. sammaye/yii2-solr

ActiveYii2-extension[Search &amp; Filtering](/categories/search)

sammaye/yii2-solr
=================

Solr plugin for the Yii2 framework built ontop of Solarium

2.0.0(5y ago)1063.3k↓62.5%19BSD-3-ClausePHP

Since Feb 3Pushed 3y ago8 watchersCompare

[ Source](https://github.com/Sammaye/yii2-solr)[ Packagist](https://packagist.org/packages/sammaye/yii2-solr)[ RSS](/packages/sammaye-yii2-solr/feed)WikiDiscussions master Synced yesterday

READMEChangelog (5)Dependencies (1)Versions (6)Used By (0)

yii2-solr
=========

[](#yii2-solr)

A Yii2 Solr Extension built on top of Solarium.

Essentially this is a Yii2 plugin for Solarium and it is dirt simple to use, all it does is abstract certain parts of Solarium into Yii2.

There are only two files you need to pay attention to in this repository:

- Client - The Solr client, representing the connection
- SolrDataProvider - The data provider you can use with all your widgets etc.

Normal querying of Solr is very simple with this extension and I will in fact point you towards the [Solarium Documentation](https://solarium.readthedocs.io/en/5.2.0/).

The only part Yii2 really has is in providing the Solarium client class as a application component, to show an example:

```
$query = Yii::$app->solr->createSelect();
$query->setQuery('edismax&qf=title^20.0 OR description^0.3');
$result = Yii::$app->solr->select($query);
var_dump($result->getNumFound());
```

That is what it takes to query Solarium. As you notice the only part of the Solarium documentation you need to replace is where they use `$client` and instead you should use `Yii::$app->solr` (or whatever you have called the Solr application component in your configuration).

To setup the application you merely add it to your configuration. As an example:

```
	'solr' => [
		'class' => 'sammaye\solr\Client',
		'options' => [
			'endpoint' => [
				'solr1' => [
					'host' => '10.208.225.66',
					'port' => '8983',
					'path' => '/',
					'collection' => 'myColl
				]
			]
		]
	],
```

The `options` part of the configuration is a one-to-one match to Solariums own constructor and options.

Using the data provider for widgets is just as easy, as another example:

```
$query = Yii::$app->solr->createSelect();
$query->setQuery('(alt_subject_mpath:' . $model->path . ' OR alt_subject_mpath:' . $model->path . '.*) AND live:1');

new SolrDataProvider([
    'query' => $query,
    // an example class which assigns variables to the model(s)
    // and returns the model(s)
    'modelClass' => 'SolrResult',
    'sort' => [
        'attributes' => [
            'title',
            'sales',
            'score'
        ]
    ]
]);
```

As you will notice the Solarium query object can go straight into the data providers `query` property. Just like in Yii1 you need to provide a `modelClass` since this extension is not connected to active record directly.

The reasoning for not implementing a `QueryInterface` and making the query hook into an active record is because in many cases the Solr index represents many active records all at once as such I wanted to make it free form and give the user the ability to produce a specific Solr model that can return any active record they see fit while the data provider just feeds the multiple classes into a widget.

So now the basics are understood, you will see there are two others files:

- Solr - A helper that I used in my application and I just added in case it would be useful to others
- SolrDocumentInterface - An interface that defines a single function to be used within Solr models

The `Solr` class is just a helper that you don't really need if you don't want it so I will move onto the `SolrDocumentInterface`. The interface class just defines a single function `populateFromSolr` which takes one argument: the Solarium document object (from a loop). It returns a single Yii2 model. The `populateFromSolr` function is called every iteration of the data providers `prepareModels()` function and only ever takes a single document.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% 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 ~447 days

Total

5

Last Release

2011d ago

Major Versions

1.2.5 → 2.0.02020-12-30

### Community

Maintainers

![](https://www.gravatar.com/avatar/7357836d822160350576f98b85244f4d5f960be303a2fcaa15a330187966cbd4?d=identicon)[Sammaye](/maintainers/Sammaye)

---

Top Contributors

[![Sammaye](https://avatars.githubusercontent.com/u/323996?v=4)](https://github.com/Sammaye "Sammaye (14 commits)")[![B0rner](https://avatars.githubusercontent.com/u/5814570?v=4)](https://github.com/B0rner "B0rner (3 commits)")[![blacksesion](https://avatars.githubusercontent.com/u/16170470?v=4)](https://github.com/blacksesion "blacksesion (2 commits)")[![cebe](https://avatars.githubusercontent.com/u/189796?v=4)](https://github.com/cebe "cebe (1 commits)")[![tarleb](https://avatars.githubusercontent.com/u/507994?v=4)](https://github.com/tarleb "tarleb (1 commits)")

---

Tags

solryii2extensionyii2-extensionsolariumsammaye

### Embed Badge

![Health badge](/badges/sammaye-yii2-solr/health.svg)

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

###  Alternatives

[nelmio/solarium-bundle

Integration with solarium solr client.

1503.2M16](/packages/nelmio-solarium-bundle)[apache-solr-for-typo3/solr

Apache Solr for TYPO3 - Apache Solr for TYPO3 is the enterprise search server you were looking for with special features such as Faceted Search or Synonym Support and incredibly fast response times of results within milliseconds.

1493.2M48](/packages/apache-solr-for-typo3-solr)[thrieu/yii2-grid-view-state

Save filters from GridView to session, keep the filter state between pages.

1313.7k1](/packages/thrieu-yii2-grid-view-state)

PHPackages © 2026

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