summaryrefslogtreecommitdiff
path: root/redis/commands/search/commands.py
diff options
context:
space:
mode:
Diffstat (limited to 'redis/commands/search/commands.py')
-rw-r--r--redis/commands/search/commands.py118
1 files changed, 79 insertions, 39 deletions
diff --git a/redis/commands/search/commands.py b/redis/commands/search/commands.py
index c19cb93..553bc39 100644
--- a/redis/commands/search/commands.py
+++ b/redis/commands/search/commands.py
@@ -79,7 +79,9 @@ class SearchCommands:
allow searching in specific fields
- **stopwords**: If not None, we create the index with this custom
stopword list. The list can be empty
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftcreate
+ """ # noqa
args = [CREATE_CMD, self.index_name]
if definition is not None:
@@ -109,7 +111,9 @@ class SearchCommands:
### Parameters:
- **fields**: a list of Field objects to add for the index
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftalter_schema_add
+ """ # noqa
args = [ALTER_CMD, self.index_name, "SCHEMA", "ADD"]
try:
@@ -119,17 +123,6 @@ class SearchCommands:
return self.execute_command(*args)
- def drop_index(self, delete_documents=True):
- """
- Drop the index if it exists. Deprecated from RediSearch 2.0.
-
- ### Parameters:
-
- - **delete_documents**: If `True`, all documents will be deleted.
- """
- keep_str = "" if delete_documents else "KEEPDOCS"
- return self.execute_command(DROP_CMD, self.index_name, keep_str)
-
def dropindex(self, delete_documents=False):
"""
Drop the index if it exists.
@@ -139,7 +132,8 @@ class SearchCommands:
### Parameters:
- **delete_documents**: If `True`, all documents will be deleted.
- """
+ For more information: https://oss.redis.com/redisearch/Commands/#ftdropindex
+ """ # noqa
keep_str = "" if delete_documents else "KEEPDOCS"
return self.execute_command(DROP_CMD, self.index_name, keep_str)
@@ -246,7 +240,9 @@ class SearchCommands:
- **fields** kwargs dictionary of the document fields to be saved
and/or indexed.
NOTE: Geo points shoule be encoded as strings of "lon,lat"
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftadd
+ """ # noqa
return self._add_document(
doc_id,
conn=None,
@@ -278,7 +274,9 @@ class SearchCommands:
- **replace**: if True, and the document already is in the index, we
perform an update and reindex the document
- **language**: Specify the language used for document tokenization.
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftaddhash
+ """ # noqa
return self._add_document_hash(
doc_id,
conn=None,
@@ -296,7 +294,9 @@ class SearchCommands:
- **delete_actual_document**: if set to True, RediSearch also delete
the actual document if it is in the index
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftdel
+ """ # noqa
args = [DEL_CMD, self.index_name, doc_id]
if conn is None:
conn = self.client
@@ -327,6 +327,8 @@ class SearchCommands:
### Parameters
- **ids**: the ids of the saved documents.
+
+ For more information https://oss.redis.com/redisearch/Commands/#ftget
"""
return self.client.execute_command(MGET_CMD, self.index_name, *ids)
@@ -335,6 +337,8 @@ class SearchCommands:
"""
Get info an stats about the the current index, including the number of
documents, memory consumption, etc
+
+ For more information https://oss.redis.com/redisearch/Commands/#ftinfo
"""
res = self.client.execute_command(INFO_CMD, self.index_name)
@@ -362,7 +366,9 @@ class SearchCommands:
- **query**: the search query. Either a text for simple queries with
default parameters, or a Query object for complex queries.
See RediSearch's documentation on query format
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftsearch
+ """ # noqa
args, query = self._mk_query_args(query)
st = time.time()
res = self.execute_command(SEARCH_CMD, *args)
@@ -376,6 +382,10 @@ class SearchCommands:
)
def explain(self, query):
+ """Returns the execution plan for a complex query.
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftexplain
+ """ # noqa
args, query_text = self._mk_query_args(query)
return self.execute_command(EXPLAIN_CMD, *args)
@@ -392,7 +402,9 @@ class SearchCommands:
An `AggregateResult` object is returned. You can access the rows from
its `rows` property, which will always yield the rows of the result.
- """
+
+ Fpr more information: https://oss.redis.com/redisearch/Commands/#ftaggregate
+ """ # noqa
if isinstance(query, AggregateRequest):
has_cursor = bool(query._cursor)
cmd = [AGGREGATE_CMD, self.index_name] + query.build_args()
@@ -477,7 +489,9 @@ class SearchCommands:
suggestions (default: 1, max: 4).
**include**: specifies an inclusion custom dictionary.
**exclude**: specifies an exclusion custom dictionary.
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftspellcheck
+ """ # noqa
cmd = [SPELLCHECK_CMD, self.index_name, query]
if distance:
cmd.extend(["DISTANCE", distance])
@@ -534,7 +548,9 @@ class SearchCommands:
- **name**: Dictionary name.
- **terms**: List of items for adding to the dictionary.
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftdictadd
+ """ # noqa
cmd = [DICT_ADD_CMD, name]
cmd.extend(terms)
return self.execute_command(*cmd)
@@ -546,7 +562,9 @@ class SearchCommands:
- **name**: Dictionary name.
- **terms**: List of items for removing from the dictionary.
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftdictdel
+ """ # noqa
cmd = [DICT_DEL_CMD, name]
cmd.extend(terms)
return self.execute_command(*cmd)
@@ -557,7 +575,9 @@ class SearchCommands:
### Parameters
- **name**: Dictionary name.
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftdictdump
+ """ # noqa
cmd = [DICT_DUMP_CMD, name]
return self.execute_command(*cmd)
@@ -568,7 +588,9 @@ class SearchCommands:
- **option**: the name of the configuration option.
- **value**: a value for the configuration option.
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftconfig
+ """ # noqa
cmd = [CONFIG_CMD, "SET", option, value]
raw = self.execute_command(*cmd)
return raw == "OK"
@@ -579,7 +601,9 @@ class SearchCommands:
### Parameters
- **option**: the name of the configuration option.
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftconfig
+ """ # noqa
cmd = [CONFIG_CMD, "GET", option]
res = {}
raw = self.execute_command(*cmd)
@@ -595,7 +619,9 @@ class SearchCommands:
### Parameters
- **tagfield**: Tag field name
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#fttagvals
+ """ # noqa
return self.execute_command(TAGVALS_CMD, self.index_name, tagfield)
@@ -606,7 +632,9 @@ class SearchCommands:
### Parameters
- **alias**: Name of the alias to create
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftaliasadd
+ """ # noqa
return self.execute_command(ALIAS_ADD_CMD, alias, self.index_name)
@@ -617,7 +645,9 @@ class SearchCommands:
### Parameters
- **alias**: Name of the alias to create
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftaliasupdate
+ """ # noqa
return self.execute_command(ALIAS_UPDATE_CMD, alias, self.index_name)
@@ -628,7 +658,9 @@ class SearchCommands:
### Parameters
- **alias**: Name of the alias to delete
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftaliasdel
+ """ # noqa
return self.execute_command(ALIAS_DEL_CMD, alias)
def sugadd(self, key, *suggestions, **kwargs):
@@ -637,8 +669,9 @@ class SearchCommands:
a score and string.
If kwargs["increment"] is true and the terms are already in the
server's dictionary, we increment their scores.
- More information `here <https://oss.redis.com/redisearch/master/Commands/#ftsugadd>`_. # noqa
- """
+
+ For more information: https://oss.redis.com/redisearch/master/Commands/#ftsugadd
+ """ # noqa
# If Transaction is not False it will MULTI/EXEC which will error
pipe = self.pipeline(transaction=False)
for sug in suggestions:
@@ -656,16 +689,18 @@ class SearchCommands:
def suglen(self, key):
"""
Return the number of entries in the AutoCompleter index.
- More information `here <https://oss.redis.com/redisearch/master/Commands/#ftsuglen>`_. # noqa
- """
+
+ For more information https://oss.redis.com/redisearch/master/Commands/#ftsuglen
+ """ # noqa
return self.execute_command(SUGLEN_COMMAND, key)
def sugdel(self, key, string):
"""
Delete a string from the AutoCompleter index.
Returns 1 if the string was found and deleted, 0 otherwise.
- More information `here <https://oss.redis.com/redisearch/master/Commands/#ftsugdel>`_. # noqa
- """
+
+ For more information: https://oss.redis.com/redisearch/master/Commands/#ftsugdel
+ """ # noqa
return self.execute_command(SUGDEL_COMMAND, key, string)
def sugget(
@@ -674,7 +709,6 @@ class SearchCommands:
):
"""
Get a list of suggestions from the AutoCompleter, for a given prefix.
- More information `here <https://oss.redis.com/redisearch/master/Commands/#ftsugget>`_. # noqa
Parameters:
@@ -701,7 +735,9 @@ class SearchCommands:
list:
A list of Suggestion objects. If with_scores was False, the
score of all suggestions is 1.
- """
+
+ For more information: https://oss.redis.com/redisearch/master/Commands/#ftsugget
+ """ # noqa
args = [SUGGET_COMMAND, key, prefix, "MAX", num]
if fuzzy:
args.append(FUZZY)
@@ -733,7 +769,9 @@ class SearchCommands:
If set to true, we do not scan and index.
terms :
The terms.
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftsynupdate
+ """ # noqa
cmd = [SYNUPDATE_CMD, self.index_name, groupid]
if skipinitial:
cmd.extend(["SKIPINITIALSCAN"])
@@ -746,6 +784,8 @@ class SearchCommands:
The command is used to dump the synonyms data structure.
Returns a list of synonym terms and their synonym group ids.
- """
+
+ For more information: https://oss.redis.com/redisearch/Commands/#ftsyndump
+ """ # noqa
raw = self.execute_command(SYNDUMP_CMD, self.index_name)
return {raw[i]: raw[i + 1] for i in range(0, len(raw), 2)}