jesseobrien / reach
PHP Redis 搜索库。
dev-master
2014-02-21 01:32 UTC
Requires
- illuminate/redis: 4.1.*@dev
- illuminate/support: 4.1.*@dev
Requires (Dev)
- mockery/mockery: 0.9.*@dev
- phpunit/phpunit: 4.1.*
This package is not auto-updated.
Last update: 2024-09-24 06:16:27 UTC
README
PHP 的 Redis 搜索层。
安装
将 "jesseobrien/reach": "dev-master" 添加到您的 composer.json 的 require 部分。
用法
插入一本书
# Ensure your object has the searchable variables set. class Book { protected $searchableAttributes = ['name', 'author']; protected $searchableNamespace = 'books'; } // Create a new book and save it to the database. $b = new Book(); $b->name = 'The Adventures of Sherlock Holmes'; $b->author = 'Arthur Conan Doyle'; $b->save(); // Now that our object has an id from save(), insert it into Reach $searchIndex = new Reach(); $searchIndex->add($b);
查找书籍
// Search in books for 'sherlock holmes' // Reach will return the ids of books it finds matching 'sherlock' and 'holmes' $ids = $searchIndex->find('books', 'sherlock holmes'); $results = []; foreach ($ids as $id) { $result[] = Book::find($id); }