Download the PHP package front/redisearch without Composer
On this page you can find all versions of the php package front/redisearch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download front/redisearch
More information about front/redisearch
Files in front/redisearch
Package redisearch
Short Description CMS/Framework agnostic RediSearch client
License MIT
Homepage http://github.com/front/redisearch
Informations about the package redisearch
RediSearch client
This is a light weight, CMS/Framework agnostic client for RediSearch
For RediSearch version 1.0, please use version 1.0.2
How to use
First, you will need to install and configure Redis and RediSearch.
Then add this package to your project via composer require front/redisearch
.
For all kind of operations, first step is to connect to redis server:
Default values are: $server = '127.0.0.1'
, $port = 6379
, $password = null
, $database = 0
Field types
Redisearch supports some field types:
- TEXT [NOSTEM] [WEIGHT {weight}] [PHONETIC {matcher}] ex:
TEXT NOSTEM WEIGHT 5.6 PHONETIC {maycher}*
- NUMERIC [SORTABLE] [NOINDEX]
- GEO [SORTABLE] [NOINDEX]
- TAG [SEPARATOR {sep}]
*matcher: Declaring a text field as PHONETIC will perform phonetic matching on it in searches by default. The obligatory {matcher} argument specifies the phonetic algorithm and language used. The following matchers are supported:
dm:en
- Double Metaphone for English
dm:fr
- Double Metaphone for French
dm:pt
- Double Metaphone for Portuguese
dm:es
- Double Metaphone for Spanish
Create an index
To create index, first we need to specify indexName
, then we can pass some optional flags and at the end, schema (fields).
Available commands are:
In the RediSearch version 2.0, the whole structure of the index have been changed. Unlike version 1.0 which used to store indexed documents into Redis HASHed, in version 2.0 the Redis HASHes are indexed automatically. This means:
- While creating an index, you need to tell RediSearch which HASH prefixes should be indexed
- The HASH key in which you want to index, you needs to have the same prefix specified for the index
Also you need to tell RediSearch which Redis type should be indexed. For now, only HASH is supported, but other data types might be added in the future.
In the new version of RediSearch, indexes can be created temporarily for a specified period of inactivity. The internal idle timer is reset whenever the index is searched or added to. This is specially useful for example: order history of individual users in a commerce website.
RediSearch by default supports basic english stop-words. There is two option, you can totally disable stop-word exclusion or specify your own list:
Some other flags are:
And finally, we need to specify the schema (the fields, their types and flags):
Some notes:
- field weight is float value and only applies to the field. Default value is 1.0
- Don't forget to call
create()
method at the end
Synonym
Synonym matching is supported as well: `
Add document to the index (indexing)
Persistence
After indexing documents, index can be written to the disk and in case of network issues, you won't miss your index.
Query builder
Class Query\QueryBuilder is designed to help with construction of redisearch queries used in search and aggregation. It uses addCondition()
, addGenericCondition()
and addSubcondition()
methods to add conditions to a query and also enables using partial search, fuzzy search, escaping, tokenization and stop words. Example:
Search
And here is how to search:
There is two methods available to apply on search results which are:
Delete an index
Notes:
- NUMBERIC, TAG and GEO fields only can be used as filter and matching does not work on them.
Todos:
- Add support for suggestion (auto-complete).
- Implement individual document deletion
- Implement filter on index
- Implement document updating