RediSearch-PHP is a PHP client library for the RediSearch module which adds Full-Text search to Redis.

What is this?

RediSearch-PHP is a PHP client library for the RediSearch module which adds Full-Text search to Redis.

Requirements

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;
posted @ 2017-08-16 09:03  haiwei.sun  阅读(391)  评论(0编辑  收藏  举报
返回顶部