PHPackages                             macfja/redisearch - 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. [Caching](/categories/caching)
4. /
5. macfja/redisearch

ActiveLibrary[Caching](/categories/caching)

macfja/redisearch
=================

PHP Client for RediSearch

2.2.0(3y ago)67174.7k↓49.1%11[12 issues](https://github.com/MacFJA/php-redisearch/issues)[2 PRs](https://github.com/MacFJA/php-redisearch/pulls)1MITPHPPHP ^7.2 || ^8.0

Since Dec 5Pushed 2y ago2 watchersCompare

[ Source](https://github.com/MacFJA/php-redisearch)[ Packagist](https://packagist.org/packages/macfja/redisearch)[ RSS](/packages/macfja-redisearch/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (9)Dependencies (22)Versions (15)Used By (1)

PHP RediSearch
==============

[](#php-redisearch)

[MacFJA/redisearch](https://packagist.org/packages/macfja/redisearch) is a PHP Client for [RediSearch](https://oss.redislabs.com/redisearch/).

The implemented API is for RediSearch 2.x

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

[](#installation)

```
composer require macfja/redisearch

```

Usage
-----

[](#usage)

### Get a Redis client

[](#get-a-redis-client)

This lib can use several connector for Redis:

- [Predis](https://github.com/predis/predis/wiki) - Pure PHP implementation
- [Phpredis](https://github.com/phpredis/phpredis) - PHP extension
- [Phpiredis](https://github.com/nrk/phpiredis) - PHP extension depending on [hiredis](https://github.com/redis/hiredis)
- [Amp\\Redis](https://github.com/amphp/redis) - Pure PHP Async implementation
- [cheprasov/php-redis-client](https://github.com/cheprasov/php-redis-client) - Pure PHP implementation
- [Credis](https://github.com/colinmollenhour/credis) - Pure PHP implementation
- [Rediska](https://github.com/Shumkov/Rediska) - Pure PHP implementation
- [Redisent](https://github.com/jdp/redisent) - Pure PHP implementation
- [TinyRedis](https://github.com/ptrofimov/tinyredisclient) - Pure PHP implementation

You can pick the connector depending on your need.

```
$clientFacade = new \MacFJA\RediSearch\Redis\Client\ClientFacade();

// With Predis
$client = $clientFacade->getClient(new \Predis\Client(/* ... */));

// With Phpredis extension
$client = $clientFacade->getClient(new \Redis([/* ... */]));

// With Phpiredis extension
$client = $clientFacade->getClient(phpiredis_connect($host));

// With Amp\Redis
$client = $clientFacade->getClient(new \Amp\Redis\Redis(new RemoteExecutor(Config::fromUri(/* ... */))));

// With Cheprasov
$client = $clientFacade->getClient(new \RedisClient\Client\Version\RedisClient6x0([/* ... */]));

// With Rediska
$client = $clientFacade->getClient(new \Rediska(['servers' => [[/* ... */]]]));

// With Redisent
$client = $clientFacade->getClient(new \redisent\Redis(/* ... */));

// With TinyRedisClient
$client = $clientFacade->getClient(new \TinyRedisClient(/* ... */));

// With Credis
$client = $clientFacade->getClient(new \Credis_Client(/* ... */));
```

You can add your own implementation, all you need is to implement the interface `\MacFJA\RediSearch\Redis\Client` and add it to the client facace with:

```
$clientFacade = new \MacFJA\RediSearch\Redis\Client\ClientFacade();
$clientFacade->addFactory(\MyVendor\MyPackage\MyRedisClient::class);
```

### Create a new index

[](#create-a-new-index)

```
$client = /* ... */;
$builder = new \MacFJA\RediSearch\IndexBuilder();

// Field can be created in advance
$address = (new \MacFJA\RediSearch\Redis\Command\CreateCommand\GeoFieldOption())
    ->setField('address');

$builder
    ->setIndex('person')
    ->addField($address)
    // Or field can be created "inline"
    ->addTextField('lastname', false, null, null, true)
    ->addTextField('firstname')
    ->addNumericField('age')
    ->create($client);
```

The builder can also be used with `withXxx` and `withAddedXxx` instead of `setXxx` and `addXxx`. This will give you a new instance of the builder with the configured data.

### Add a document

[](#add-a-document)

```
$client = /* ... */;
$index = new \MacFJA\RediSearch\Index('person', $client);
$index->addDocumentFromArray([
    'firstname' => 'Joe',
    'lastname' => 'Doe',
    'age' => 30,
    'address' => '-74.044502,40.689247'
]);
```

### Search

[](#search)

```
$client = /* ... */;
$search = new \MacFJA\RediSearch\Redis\Command\Search();

$search
    ->setIndex('person')
    ->setQuery('Doe')
    ->setHighlight(['lastname'])
    ->setWithScores();
$results = $client->execute($search);
```

#### Create a search query

[](#create-a-search-query)

```
use MacFJA\RediSearch\Query\Builder\GeoFacet;
use MacFJA\RediSearch\Query\Builder\Negation;
use MacFJA\RediSearch\Query\Builder\NumericFacet;
use MacFJA\RediSearch\Query\Builder\Optional;
use MacFJA\RediSearch\Query\Builder\Word;
use MacFJA\RediSearch\Redis\Command\SearchCommand\GeoFilterOption;

$queryBuilder = new \MacFJA\RediSearch\Query\Builder();
$query = $queryBuilder
    ->addElement(NumericFacet::greaterThan('age', 17))
    ->addString('Doe')
    ->addElement(
        new Negation(
            new GeoFacet(['address'], -74.044502, 40.589247, 40, GeoFilterOption::UNIT_KILOMETERS)
        )
    )
    ->addElement(new Optional(new Word('John')))
    ->render();

// The value of $query is:
// @age:[(17 +inf] Doe -@address:[-74.044502 40.589247 40.000000 km] ~John
```

### Pipeline

[](#pipeline)

```
use MacFJA\RediSearch\Redis\Command\Aggregate;
use MacFJA\RediSearch\Redis\Command\AggregateCommand\GroupByOption;
use MacFJA\RediSearch\Redis\Command\AggregateCommand\ReduceOption;
use MacFJA\RediSearch\Redis\Command\Search;
use MacFJA\RediSearch\Redis\Command\SugGet;

$client = /* ... */;

$query = '@age:[(17 +inf] %john%';
$search = new Search();
$search->setIndex('people')
    ->setQuery($query);

$stats = new Aggregate();
$stats->setIndex('people')
    ->setQuery($query)
    ->addGroupBy(new GroupByOption([], [
        ReduceOption::average('age', 'avg'),
        ReduceOption::maximum('age', 'oldest')
    ]));

$aggregate = new Aggregate();
$aggregate->setIndex('people')
    ->setQuery($query)
    ->addGroupBy(new GroupByOption(['lastname'], [ReduceOption::count('count')]));

$suggestion = new SugGet();
$suggestion->setDictionary('names')
    ->setPrefix('john')
    ->setFuzzy();

$result = $client->pipeline($search, $stats, $aggregate, $suggestion);

// $result[0] is the search result
// $result[1] is the first aggregation result
// $result[2] is the second aggregation result
// $result[3] is the suggestion result
```

### Use Predis (v1.x) shorthand syntax

[](#use-predis-v1x-shorthand-syntax)

```
$client = new \Predis\Client(/* ... */);
\MacFJA\RediSearch\Redis\Initializer::registerCommandsPredis($client->getProfile());

$client->ftsearch('people', '@age:[(17 +inf] %john%');
// But you will have raw Redis output.
```

### Use Rediska shorthand syntax

[](#use-rediska-shorthand-syntax)

```
$client = new \Rediska(/* ... */);
\MacFJA\RediSearch\Redis\Initializer::registerCommandsRediska();

$client->ftsearch('people', '@age:[(17 +inf] %john%');
// But you will have raw Redis output.
```

Similar projects
----------------

[](#similar-projects)

- [ethanhann/redisearch-php](https://packagist.org/packages/ethanhann/redisearch-php) - Abandoned
- [front/redisearch](https://packagist.org/packages/front/redisearch) - Partial fork of `ethanhann/redisearch-php`
- [ashokgit/redisearch-php](https://packagist.org/packages/ashokgit/redisearch-php) - Fork of `ethanhann/redisearch-php`

Contributing
------------

[](#contributing)

You can contribute to the library. To do so, you have Github issues to:

- ask your question
- request any change (typo, bad code, new feature etc.)
- and much more...

You also have PR to:

- suggest a correction
- suggest a new feature
- and much more...

See [CONTRIBUTING](CONTRIBUTING.md) for more information.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 94.1% 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 ~51 days

Recently: every ~64 days

Total

13

Last Release

1420d ago

Major Versions

1.x-dev → 2.0.02021-11-06

PHP version history (3 changes)1.0.0PHP &gt;= 7.1

2.0.0PHP ^7.2

2.0.2PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1475671?v=4)[MacFJA](/maintainers/MacFJA)[@MacFJA](https://github.com/MacFJA)

---

Top Contributors

[![MacFJA](https://avatars.githubusercontent.com/u/1475671?v=4)](https://github.com/MacFJA "MacFJA (111 commits)")[![vlradstake](https://avatars.githubusercontent.com/u/24358266?v=4)](https://github.com/vlradstake "vlradstake (3 commits)")[![ghdi](https://avatars.githubusercontent.com/u/6251993?v=4)](https://github.com/ghdi "ghdi (2 commits)")[![alister](https://avatars.githubusercontent.com/u/173165?v=4)](https://github.com/alister "alister (1 commits)")[![pierrexp9](https://avatars.githubusercontent.com/u/50573670?v=4)](https://github.com/pierrexp9 "pierrexp9 (1 commits)")

---

Tags

redisearchredisearch-phpredissearch engineredisearchsuggestion

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/macfja-redisearch/health.svg)

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

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k325.4M2.8k](/packages/predis-predis)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[snc/redis-bundle

A Redis bundle for Symfony

1.0k40.9M75](/packages/snc-redis-bundle)[symfony/asset-mapper

Maps directories of assets &amp; makes them available in a public directory with versioned filenames.

1678.8M238](/packages/symfony-asset-mapper)

PHPackages © 2026

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