PHPackages                             nmarniesse/phindexer - 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. nmarniesse/phindexer

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

nmarniesse/phindexer
====================

PHP data indexer

v1.0.0(7y ago)15MITPHPPHP &gt;=7.1

Since May 5Pushed 7y ago1 watchersCompare

[ Source](https://github.com/nmarniesse/phindexer)[ Packagist](https://packagist.org/packages/nmarniesse/phindexer)[ RSS](/packages/nmarniesse-phindexer/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

Phindexer
=========

[](#phindexer)

PHP data indexer that speeds up your data operations.

When you need to filter or search item from a collection, the operation could take time and effort to retrieve your data. And unless you index your data manually (with a hash strategy for example) the operation could slow down your program drastically.

This projects helps you to index your data and retrieve them simply and quickly.

Requirements
------------

[](#requirements)

- php 7.1
- ext-json

Install
-------

[](#install)

```
composer require nmarniesse/phindexer
```

Performances
------------

[](#performances)

Here is some tests to check the performance. First we create a collection of 10,000 items then we launch 1000 searches on it. The `PhindexerJob` uses this lib to index the items, the `ClassicJob` do not index and iterates on items on each searches. The results vary depending on the computer.

```
$ php ./tests/Performance/console performance:array:launch 10000 1000
Create fixtures... OK

Start tests with data size [10000] and searches repetition [1000]...

Launch tests... OK
Results
-------
Strategy   : NMarniesse\Phindexer\Test\Performance\Job\PhindexerJob
Memory used: 2.147781 MB
Time       : 0.042447 seconds

Launch tests... OK
Results
-------
Strategy   : NMarniesse\Phindexer\Test\Performance\Job\ClassicJob
Memory used: 0.000359 MB
Time       : 11.652977 seconds

```

Documentation
-------------

[](#documentation)

### Index and search on a collection

[](#index-and-search-on-a-collection)

```
use NMarniesse\Phindexer\Collection\Collection;

$list = [
    ['name' => 'A', 'color' => 'green', 'price' => 60],
    ['name' => 'B', 'color' => 'green', 'price' => 80],
    ['name' => 'C', 'color' => 'blue', 'price' => 10],
    ['name' => 'D', 'color' => 'green', 'price' => 40],
    ['name' => 'E', 'color' => 'red', 'price' => 50],
];

$collection = new Collection($list);

$collection->addKeyIndex('color');
$results = $collection->findWhere('color', 'green');

// Results is a new instance of Collection that contains the results
foreach ($results as $result) {
    print_r($result);
}
```

### Using custom index

[](#using-custom-index)

Maybe you want index your data with more complex condition. You can pass the function you want with `ExpressionIndex`:

```
// Create the custom index
$expression_index = new ExpressionIndex(function (array $item) {
    return $item['color'] === 'green' && $item['price'] addExpressionIndex($expression_index);

// Search using the index
$results = $collection->findWhereExpression($expression_index, true);

// Search the items that do not satisfy the expression index
$results = $collection->findWhereExpression($expression_index, false);
```

### Using collection of objects

[](#using-collection-of-objects)

The `Collection` class can also contains a set of objects. You can even mix objects and associative arrays.
When you index by key, the system tries to index the property. It can be a public properties or protected/private property if the getter function is available.

```
use NMarniesse\Phindexer\Collection\Collection;
use NMarniesse\Phindexer\IndexType\ExpressionIndex;

// $list can be an array or an iterator
$list = [
   new Planet('Earth', 'Solar system'),
   new Planet('Mars', 'Solar system'),
   new Planet('Kepler 186-f', 'Kepler 186 system'),
];

$collection = new Collection($list);

// Index with property
$collection->addKeyIndex('system');
$results = $collection->findWhere('system', 'Solar system');

// Index with custom expression
$expression_index = new ExpressionIndex(function (Planet $planet) {
    return strpos(strtolower($planet->getSystem()), 'solar') !== false;
});
$collection->addExpressionIndex($expression_index);
$results = $collection->findWhereExpression($expression_index, true);
```

### Add items in a collection

[](#add-items-in-a-collection)

Once the collection is initialize, you can add items in it. You can even create an empty collection in one hand and add items in other hand. Added items are indexed the same way.

Here is an example with `Collection`, the same behavior exists with `Collection`:

```
use NMarniesse\Phindexer\Collection\Collection;

$collection = new Collection([]);
$collection->addKeyIndex('system');

$collection->addItem(new Planet('Earth', 'Solar system'));
$collection->addItem(new Planet('Mars', 'Solar system'));
$collection->addItem(new Planet('Kepler 186-f', 'Kepler 186 system'));

$results = $collection->findWhere('system', 'Solar system');
```

### Validation constraint

[](#validation-constraint)

If you need to ensure the items have always the good structure, or the same type, you can specified some constraints in your collection.
The validation is checked on each items when the collection is instantiated, and on each item you add further.

```
use NMarniesse\Phindexer\Collection\Collection;
use Symfony\Component\Validator\Constraints as Assert;

// Valiation ok.
$constraint = new Assert\Type(['type' => Planet::class]);
$collection = new Collection([new Planet('Earth', 'Solar system')], $constraint);

// Valiation ok.
$collection->addItem(new Planet('Mars', 'Solar system'));
$collection->addItem(new Planet('Kepler 186-f', 'Kepler 186 system'));

// Valiation fails.
$collection->addItem(new Star('Sun'));
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

2565d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e0a90aaecb6c34cd8c3993f229e59e0b5072802b868dc4dda80fc47e44509358?d=identicon)[nmarniesse](/maintainers/nmarniesse)

### Embed Badge

![Health badge](/badges/nmarniesse-phindexer/health.svg)

```
[![Health](https://phpackages.com/badges/nmarniesse-phindexer/health.svg)](https://phpackages.com/packages/nmarniesse-phindexer)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

22.8k69.3k](/packages/grumpydictator-firefly-iii)[phpro/soap-client

A general purpose SoapClient library

8885.6M46](/packages/phpro-soap-client)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)

PHPackages © 2026

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