MacFJA/redisearch is a PHP Client for RediSearch.
The implemented API is for RediSearch 2.0
composer require macfja/redisearch
$client = new \Predis\Client(/* ... */);
$builder = new \MacFJA\RediSearch\Index\Builder($client);
// Field can be create in advance
$address = new \MacFJA\RediSearch\Index\Builder\GeoField('address');
$builder
->withName('person')
->addField($address)
// Or field can be create "inline"
->addTextField('lastname', false, null, null, true)
->addTextField('firstname')
->addNumericField('age')
->create();
$client = new \Predis\Client(/* ... */);
$index = new \MacFJA\RediSearch\Index('person', $client);
$index->addFromArray([
'firstname' => 'Joe',
'lastname' => 'Doe',
'age' => 30,
'address' => '40.689247,-74.044502'
]);
$client = new \Predis\Client(/* ... */);
$search = new \MacFJA\RediSearch\Search($client);
$results = $search
->withIndex('person')
->withQuery('Doe')
->withHighlight(['lastname'])
->withScores()
->search();
use \MacFJA\RediSearch\Search\QueryBuilder\NumericFacet;
use \MacFJA\RediSearch\Search\QueryBuilder\Negation;
use \MacFJA\RediSearch\Search\QueryBuilder\GeoFacet;
use \MacFJA\RediSearch\Search\QueryBuilder\Optional;
use \MacFJA\RediSearch\Search\QueryBuilder\Word;
use \MacFJA\RediSearch\Search\GeoFilter;
$queryBuilder = \MacFJA\RediSearch\Search\QueryBuilder::create();
$query = $queryBuilder
->addExpression(NumericFacet::greaterThan('age', 17))
->addString('Doe')
->addExpression(
new Negation(
new GeoFacet('address', 40.589247, -74.044502, 40, GeoFilter::UNIT_KILOMETERS)
)
)
->addExpression(new Optional(new Word('John')))
->render();
// The value of $query is:
// Doe ~John @age:[(17 +inf] -@address:[40.589247 -74.044502 40.000000 km]
- ethanhann/redisearch-php - Abandoned
- front/redisearch - Partial fork of
ethanhann/redisearch-php
- ashokgit/redisearch-php - Fork of
ethanhann/redisearch-php
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 for more information.
The MIT License (MIT). Please see License File for more information.