PHPackages                             tubber/model-indexer - 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. tubber/model-indexer

ActiveLibrary[Search &amp; Filtering](/categories/search)

tubber/model-indexer
====================

This package makes it simple to index large amounts of data to Solr.

0.5.1(6y ago)0118MITPHPPHP ^7.2CI failing

Since Jun 21Pushed 6y agoCompare

[ Source](https://github.com/roelofjan-elsinga/model-indexer)[ Packagist](https://packagist.org/packages/tubber/model-indexer)[ RSS](/packages/tubber-model-indexer/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (3)Versions (9)Used By (0)

[![](https://camo.githubusercontent.com/85c9ce76ba85b8bc1d529edc02cfeb44418faa269219ac2d020c8011c0de5418/68747470733a2f2f73332d65752d776573742d312e616d617a6f6e6177732e636f6d2f6c697665747562626265722f696d616765732f736974652f4f6f676d65726b547562626265722e706e67)](https://camo.githubusercontent.com/85c9ce76ba85b8bc1d529edc02cfeb44418faa269219ac2d020c8011c0de5418/68747470733a2f2f73332d65752d776573742d312e616d617a6f6e6177732e636f6d2f6c697665747562626265722f696d616765732f736974652f4f6f676d65726b547562626265722e706e67)

Model indexer (Apache Solr)
===========================

[](#model-indexer-apache-solr)

[![Build status](https://camo.githubusercontent.com/7df8d1c0234f0993d2f0845acc87f901efcd050436a3ca582d1991adca48169b/68747470733a2f2f7472617669732d63692e636f6d2f726f656c6f666a616e2d656c73696e67612f6d6f64656c2d696e64657865722e737667)](https://travis-ci.com/roelofjan-elsinga/model-indexer)[![StyleCI Status](https://camo.githubusercontent.com/a621ca66ea7907d83bad9937075486708baf5a070dce9d1f5d9484b9907cd33a/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3139333034333338382f736869656c64)](https://github.styleci.io/repos/193043388)[![Code coverage](https://camo.githubusercontent.com/6ae2ab6d32708c523c993746bae97e3a9581cfca7bae6709d32e9b5b7b3f30b7/68747470733a2f2f636f6465636f762e696f2f67682f726f656c6f666a616e2d656c73696e67612f6d6f64656c2d696e64657865722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/roelofjan-elsinga/model-indexer)[![Total Downloads](https://camo.githubusercontent.com/d4355c35a8347e9303b7ca791be46c6670f39b9df62334fc21dbe8f5d205eb4d/68747470733a2f2f706f7365722e707567782e6f72672f7475626265722f6d6f64656c2d696e64657865722f646f776e6c6f616473)](https://packagist.org/packages/tubber/model-indexer)[![Latest Stable Version](https://camo.githubusercontent.com/84afad7b43e033f6d5e976c0dcf36e66747043bbc3d293ee88a89c01c6671a8d/68747470733a2f2f706f7365722e707567782e6f72672f7475626265722f6d6f64656c2d696e64657865722f762f737461626c65)](https://packagist.org/packages/tubber/model-indexer)[![License](https://camo.githubusercontent.com/7ee92ca9ef6a4e15ed8b21b223126c330a595ce7931ef9604f67dbf2df171db6/68747470733a2f2f706f7365722e707567782e6f72672f7475626265722f6d6f64656c2d696e64657865722f6c6963656e7365)](https://packagist.org/packages/tubber/model-indexer)

This package makes it simple to index large amounts of data to Solr.

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

[](#installation)

You can include this package through Composer using:

```
composer require tubber/model-indexer
```

Usage
-----

[](#usage)

#### Indexing documents

[](#indexing-documents)

To be able to index any documents, you first need a class that implements the `IndexableInterface`:

```
use Solarium\QueryType\Update\Query\Document;

class IndexableModel implements \Tubber\Indexer\Contracts\IndexableInterface
{

    /**
     * Get an array of documents that need to be indexed for this object
     *
     * @return array|Document[]
     */
    public function indexingDocuments(): array
    {
        return [
            new Document([
                'id' => 1,
                'name' => 'document 1'
            ]),
            new Document([
                'id' => 2,
                'name' => 'document 2'
            ]),
        ];
    }

    /**
     * Mark this object as indexed
     *
     * @return void
     */
    public function markAsIndexed(): void
    {
        return; // Perform some kind of action to indicate this object has been indexed
    }

    /**
     * Get the query to delete this object from the given core
     *
     * @param string $search_core
     * @return string
     */
    public function getDeleteQueryFor(string $search_core): string
    {
        return "id: 1";
    }
}
```

This class is now ready to be indexed. However, you will also need to provide the ModelIndexer with some kind of configuration, so it knows where to send your documents. All you need to do is create a new class that implements SolrConfigInterface:

```
use Solarium\Client;
use Tubber\Indexer\Contracts\SolrConfigInterface;

class SearchConfig implements SolrConfigInterface
{

    /**
     * Get the client for this Solr interaction
     *
     * @return Client
     */
    public function getClient(): Client
    {
        $client = new Client();

        $client
            ->getEndpoint('your_solarium_endpoint_name')
            ->setCore('your_core_name');

        return $client;
    }

    /**
     * Reload the core that's provided in $this->getClient
     *
     * @return void
     */
    public function reloadCollection(): void
    {
        // You can implement your own way of reloading the collection
        // This method is call after indexing has finished
    }
}
```

Now you can index your documents by running the ModelIndexer `perform()` method:

```
/**@var array|Document[] $documents*/
$documents = [
    new IndexableModel()
];

ModelIndexer::forModels($documents, new SearchConfig)->perform();
```

#### Removing documents

[](#removing-documents)

You can remove documents by using the `ModelRemover` class. The invocation is identical to `ModelIndexer`:

```
use Tubber\Indexer\ModelRemover;

ModelRemover::forModels($documents, new SearchConfig)->perform();
```

You need to specify the delete query in the `getDeleteQueryFor` method on your classes that implement `IndexableInterface`. The search core name is passed to the method, in case you're indexing that class into multiple cores.

Available methods
-----------------

[](#available-methods)

To start using the ModelIndexer class, you have to call `forModels()`.

```
/**
 * Set the collection of models that need to be indexed
 *
 * @param array $models
 * @param SolrConfigInterface $config
 * @return ModelIndexer
 * @throws NoCoreFoundException
 */
public static function forModels(array $models, SolrConfigInterface $config): ModelIndexer;
```

You can customize the buffer size and the commit within value:

```
public function setBufferSize(int $buffer_size = 100): ModelIndexer;
```

and

```
public function setCommitWithin(int $commit_within = 10000): ModelIndexer;
```

These methods are fluent setters, so you can chain them:

```
ModelIndexer::forModels($models, new SearchConfig)
    ->setBufferSize(1500)
    ->setCommitWithin(5000)
    ->perform();
```

You can index the documents by calling the `perform()` method.

```
/**
 * Perform the indexing for the models in this class
 *
 * @throws \InvalidArgumentException
 */
public function perform(): void;
```

Testing
-------

[](#testing)

You can run the included tests by running `./vendor/bin/phpunit` in your terminal.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.2% 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 ~26 days

Recently: every ~45 days

Total

8

Last Release

2336d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2602444740bac106e338fc57a5d16b085ba02a9ca3d714c2106dccccbf97bba2?d=identicon)[roelofjanelsinga](/maintainers/roelofjanelsinga)

---

Top Contributors

[![roelofjan-elsinga](https://avatars.githubusercontent.com/u/9220754?v=4)](https://github.com/roelofjan-elsinga "roelofjan-elsinga (25 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

solrindexingBatching

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tubber-model-indexer/health.svg)

```
[![Health](https://phpackages.com/badges/tubber-model-indexer/health.svg)](https://phpackages.com/packages/tubber-model-indexer)
```

###  Alternatives

[nelmio/solarium-bundle

Integration with solarium solr client.

1493.0M12](/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.

1473.0M32](/packages/apache-solr-for-typo3-solr)[floriansemm/solr-bundle

Symfony Solr integration bundle

12280.2k2](/packages/floriansemm-solr-bundle)[sammaye/yii2-solr

Solr plugin for the Yii2 framework built ontop of Solarium

1063.1k](/packages/sammaye-yii2-solr)[jeroenherczeg/laravel-scout-solr

Solr Driver for Laravel Scout

121.0k](/packages/jeroenherczeg-laravel-scout-solr)

PHPackages © 2026

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