Parameters: |
|
---|
RedisEngine is responsible for storing and searching data suitable for autocompletion. There are many different options you can use to configure how autocomplete behaves, but the defaults are intended to provide good general performance for searching things like blog post titles and the like.
The underlying data structure used to provide autocompletion is a sorted set, details are described in this post.
Usage:
from redis_completion import RedisEngine
engine = RedisEngine()
Parameters: |
|
---|
Store an object in the index and allow it to be searched for.
Examples:
engine.store('some phrase')
engine.store('some other phrase')
In the following example a list of blog entries is being stored in the index. Note that arbitrary data can be stored in the index. When a search is performed this data will be returned.
for entry in Entry.select():
engine.store(entry.id, entry.title, json.dumps({
'id': entry.id,
'published': entry.published,
'title': entry.title,
'url': entry.url,
})
Like store() except data is automatically serialized as JSON before being stored in the index. Best when used in conjunction with search_json().
Parameters: | obj_id – a unique identifier for the object |
---|
Removes the given object from the index.
Parameters: |
|
---|---|
Return type: | A list containing data returned by the index |
Note
Mappers act upon data before it is passed to the filters
Assume we have stored some interesting blog posts, encoding some metadata using JSON:
>>> engine.search('python', mappers=[json.loads])
[{'published': True, 'title': 'an entry about python', 'url': '/blog/1/'},
{'published': False, 'title': 'using redis with python', 'url': '/blog/3/'}]
Like search() except json.loads is inserted as the very first mapper. Best when used in conjunction with store_json().