What is this?
RediSearch-PHP is a PHP client library for the RediSearch module which adds Full-Text search to Redis.
Requirements
- Redis running with the RediSearch module loaded.
- PHP >=7
- PhpRedis OR Predis.
Install
composer install ethanhann/redisearch-php
Load
<?php
require_once 'vendor/autoload.php';
Create the Schema
<?php
$bookIndex = new Index();
$bookIndex->addTextField('title') ->addTextField('author') ->addNumericField('price') ->addNumericField('stock') ->create();
Add a Document
<?php
$bookIndex->add([
new TextField('title', 'Tale of Two Cities'), new TextField('author', 'Charles Dickens'), new NumericField('price', 9.99), new NumericField('stock', 231), ]);
Search the Index
<?php
$result = $bookIndex->search('two cities');
$result->count(); // Number of documents. $result->documents(); // Array of matches. // Documents are returned as objects by default. $firstResult = $result->documents()[0]; $firstResult->title; $firstResult->author;