summaryrefslogtreecommitdiff
path: root/redis/commands/search
diff options
context:
space:
mode:
Diffstat (limited to 'redis/commands/search')
-rw-r--r--redis/commands/search/__init__.py4
-rw-r--r--redis/commands/search/commands.py43
-rw-r--r--redis/commands/search/field.py6
-rw-r--r--redis/commands/search/query.py9
-rw-r--r--redis/commands/search/querystring.py7
-rw-r--r--redis/commands/search/result.py2
-rw-r--r--redis/commands/search/suggestion.py6
7 files changed, 33 insertions, 44 deletions
diff --git a/redis/commands/search/__init__.py b/redis/commands/search/__init__.py
index a30cebe..94bc037 100644
--- a/redis/commands/search/__init__.py
+++ b/redis/commands/search/__init__.py
@@ -35,7 +35,7 @@ class Search(SearchCommands):
replace=False,
partial=False,
no_create=False,
- **fields
+ **fields,
):
"""
Add a document to the batch query
@@ -49,7 +49,7 @@ class Search(SearchCommands):
replace=replace,
partial=partial,
no_create=no_create,
- **fields
+ **fields,
)
self.current_chunk += 1
self.total += 1
diff --git a/redis/commands/search/commands.py b/redis/commands/search/commands.py
index 553bc39..4ec6fc9 100644
--- a/redis/commands/search/commands.py
+++ b/redis/commands/search/commands.py
@@ -1,13 +1,13 @@
import itertools
import time
-from .document import Document
-from .result import Result
-from .query import Query
+from ..helpers import parse_to_dict
from ._util import to_string
from .aggregation import AggregateRequest, AggregateResult, Cursor
+from .document import Document
+from .query import Query
+from .result import Result
from .suggestion import SuggestionParser
-from ..helpers import parse_to_dict
NUMERIC = "NUMERIC"
@@ -148,7 +148,7 @@ class SearchCommands:
partial=False,
language=None,
no_create=False,
- **fields
+ **fields,
):
"""
Internal add_document used for both batch and single doc indexing
@@ -211,7 +211,7 @@ class SearchCommands:
partial=False,
language=None,
no_create=False,
- **fields
+ **fields,
):
"""
Add a single document to the index.
@@ -253,7 +253,7 @@ class SearchCommands:
partial=partial,
language=language,
no_create=no_create,
- **fields
+ **fields,
)
def add_document_hash(
@@ -274,7 +274,7 @@ 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(
@@ -294,7 +294,7 @@ 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]
@@ -453,7 +453,7 @@ class SearchCommands:
cmd = [PROFILE_CMD, self.index_name, ""]
if limited:
cmd.append("LIMITED")
- cmd.append('QUERY')
+ cmd.append("QUERY")
if isinstance(query, AggregateRequest):
cmd[2] = "AGGREGATE"
@@ -462,19 +462,20 @@ class SearchCommands:
cmd[2] = "SEARCH"
cmd += query.get_args()
else:
- raise ValueError("Must provide AggregateRequest object or "
- "Query object.")
+ raise ValueError("Must provide AggregateRequest object or " "Query object.")
res = self.execute_command(*cmd)
if isinstance(query, AggregateRequest):
result = self._get_AggregateResult(res[0], query, query._cursor)
else:
- result = Result(res[0],
- not query._no_content,
- duration=(time.time() - st) * 1000.0,
- has_payload=query._with_payloads,
- with_scores=query._with_scores,)
+ result = Result(
+ res[0],
+ not query._no_content,
+ duration=(time.time() - st) * 1000.0,
+ has_payload=query._with_payloads,
+ with_scores=query._with_scores,
+ )
return result, parse_to_dict(res[1])
@@ -535,8 +536,7 @@ class SearchCommands:
# ]
# }
corrections[_correction[1]] = [
- {"score": _item[0], "suggestion": _item[1]}
- for _item in _correction[2]
+ {"score": _item[0], "suggestion": _item[1]} for _item in _correction[2]
]
return corrections
@@ -704,8 +704,7 @@ class SearchCommands:
return self.execute_command(SUGDEL_COMMAND, key, string)
def sugget(
- self, key, prefix, fuzzy=False, num=10, with_scores=False,
- with_payloads=False
+ self, key, prefix, fuzzy=False, num=10, with_scores=False, with_payloads=False
):
"""
Get a list of suggestions from the AutoCompleter, for a given prefix.
@@ -769,7 +768,7 @@ 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]
diff --git a/redis/commands/search/field.py b/redis/commands/search/field.py
index 076c872..69e3908 100644
--- a/redis/commands/search/field.py
+++ b/redis/commands/search/field.py
@@ -9,8 +9,7 @@ class Field:
NOINDEX = "NOINDEX"
AS = "AS"
- def __init__(self, name, args=[], sortable=False,
- no_index=False, as_name=None):
+ def __init__(self, name, args=[], sortable=False, no_index=False, as_name=None):
self.name = name
self.args = args
self.args_suffix = list()
@@ -47,8 +46,7 @@ class TextField(Field):
def __init__(
self, name, weight=1.0, no_stem=False, phonetic_matcher=None, **kwargs
):
- Field.__init__(self, name,
- args=[Field.TEXT, Field.WEIGHT, weight], **kwargs)
+ Field.__init__(self, name, args=[Field.TEXT, Field.WEIGHT, weight], **kwargs)
if no_stem:
Field.append_arg(self, self.NOSTEM)
diff --git a/redis/commands/search/query.py b/redis/commands/search/query.py
index 5534f7b..2bb8347 100644
--- a/redis/commands/search/query.py
+++ b/redis/commands/search/query.py
@@ -62,11 +62,9 @@ class Query:
def _mk_field_list(self, fields):
if not fields:
return []
- return \
- [fields] if isinstance(fields, str) else list(fields)
+ return [fields] if isinstance(fields, str) else list(fields)
- def summarize(self, fields=None, context_len=None,
- num_frags=None, sep=None):
+ def summarize(self, fields=None, context_len=None, num_frags=None, sep=None):
"""
Return an abridged format of the field, containing only the segments of
the field which contain the matching term(s).
@@ -300,8 +298,7 @@ class NumericFilter(Filter):
INF = "+inf"
NEG_INF = "-inf"
- def __init__(self, field, minval, maxval, minExclusive=False,
- maxExclusive=False):
+ def __init__(self, field, minval, maxval, minExclusive=False, maxExclusive=False):
args = [
minval if not minExclusive else f"({minval}",
maxval if not maxExclusive else f"({maxval}",
diff --git a/redis/commands/search/querystring.py b/redis/commands/search/querystring.py
index ffba542..1da0387 100644
--- a/redis/commands/search/querystring.py
+++ b/redis/commands/search/querystring.py
@@ -15,8 +15,7 @@ def between(a, b, inclusive_min=True, inclusive_max=True):
"""
Indicate that value is a numeric range
"""
- return RangeValue(a, b, inclusive_min=inclusive_min,
- inclusive_max=inclusive_max)
+ return RangeValue(a, b, inclusive_min=inclusive_min, inclusive_max=inclusive_max)
def equal(n):
@@ -200,9 +199,7 @@ class Node:
return [BaseNode(f"@{key}:{vals[0].to_string()}")]
if not vals[0].combinable:
return [BaseNode(f"@{key}:{v.to_string()}") for v in vals]
- s = BaseNode(
- f"@{key}:({self.JOINSTR.join(v.to_string() for v in vals)})"
- )
+ s = BaseNode(f"@{key}:({self.JOINSTR.join(v.to_string() for v in vals)})")
return [s]
@classmethod
diff --git a/redis/commands/search/result.py b/redis/commands/search/result.py
index 57ba53d..5f4aca6 100644
--- a/redis/commands/search/result.py
+++ b/redis/commands/search/result.py
@@ -1,5 +1,5 @@
-from .document import Document
from ._util import to_string
+from .document import Document
class Result:
diff --git a/redis/commands/search/suggestion.py b/redis/commands/search/suggestion.py
index 6d295a6..5d1eba6 100644
--- a/redis/commands/search/suggestion.py
+++ b/redis/commands/search/suggestion.py
@@ -46,8 +46,6 @@ class SuggestionParser:
def __iter__(self):
for i in range(0, len(self._sugs), self.sugsize):
ss = self._sugs[i]
- score = float(self._sugs[i + self._scoreidx]) \
- if self.with_scores else 1.0
- payload = self._sugs[i + self._payloadidx] \
- if self.with_payloads else None
+ score = float(self._sugs[i + self._scoreidx]) if self.with_scores else 1.0
+ payload = self._sugs[i + self._payloadidx] if self.with_payloads else None
yield Suggestion(ss, score, payload)