summaryrefslogtreecommitdiff
path: root/tests/test_search.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_search.py')
-rw-r--r--tests/test_search.py410
1 files changed, 149 insertions, 261 deletions
diff --git a/tests/test_search.py b/tests/test_search.py
index c7b570c..5b6a660 100644
--- a/tests/test_search.py
+++ b/tests/test_search.py
@@ -1,52 +1,32 @@
-import pytest
-import redis
import bz2
import csv
-import time
import os
-
+import time
from io import TextIOWrapper
-from .conftest import skip_ifmodversion_lt, default_redismod_url
-from redis import Redis
+import pytest
+
+import redis
import redis.commands.search
+import redis.commands.search.aggregation as aggregations
+import redis.commands.search.reducers as reducers
+from redis import Redis
from redis.commands.json.path import Path
from redis.commands.search import Search
-from redis.commands.search.field import (
- GeoField,
- NumericField,
- TagField,
- TextField
-)
-from redis.commands.search.query import (
- GeoFilter,
- NumericFilter,
- Query
-)
-from redis.commands.search.result import Result
+from redis.commands.search.field import GeoField, NumericField, TagField, TextField
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
+from redis.commands.search.query import GeoFilter, NumericFilter, Query
+from redis.commands.search.result import Result
from redis.commands.search.suggestion import Suggestion
-import redis.commands.search.aggregation as aggregations
-import redis.commands.search.reducers as reducers
-WILL_PLAY_TEXT = (
- os.path.abspath(
- os.path.join(
- os.path.dirname(__file__),
- "testdata",
- "will_play_text.csv.bz2"
- )
- )
+from .conftest import default_redismod_url, skip_ifmodversion_lt
+
+WILL_PLAY_TEXT = os.path.abspath(
+ os.path.join(os.path.dirname(__file__), "testdata", "will_play_text.csv.bz2")
)
-TITLES_CSV = (
- os.path.abspath(
- os.path.join(
- os.path.dirname(__file__),
- "testdata",
- "titles.csv"
- )
- )
+TITLES_CSV = os.path.abspath(
+ os.path.join(os.path.dirname(__file__), "testdata", "titles.csv")
)
@@ -81,9 +61,7 @@ def getClient():
def createIndex(client, num_docs=100, definition=None):
try:
client.create_index(
- (TextField("play", weight=5.0),
- TextField("txt"),
- NumericField("chapter")),
+ (TextField("play", weight=5.0), TextField("txt"), NumericField("chapter")),
definition=definition,
)
except redis.ResponseError:
@@ -96,8 +74,7 @@ def createIndex(client, num_docs=100, definition=None):
r = csv.reader(bzfp, delimiter=";")
for n, line in enumerate(r):
- play, chapter, _, text = \
- line[1], line[2], line[4], line[5]
+ play, chapter, _, text = line[1], line[2], line[4], line[5]
key = f"{play}:{chapter}".lower()
d = chapters.setdefault(key, {})
@@ -183,12 +160,10 @@ def test_client(client):
# test in fields
txt_total = (
- client.ft().search(
- Query("henry").no_content().limit_fields("txt")).total
+ client.ft().search(Query("henry").no_content().limit_fields("txt")).total
)
play_total = (
- client.ft().search(
- Query("henry").no_content().limit_fields("play")).total
+ client.ft().search(Query("henry").no_content().limit_fields("play")).total
)
both_total = (
client.ft()
@@ -217,10 +192,8 @@ def test_client(client):
# test slop and in order
assert 193 == client.ft().search(Query("henry king")).total
- assert 3 == client.ft().search(
- Query("henry king").slop(0).in_order()).total
- assert 52 == client.ft().search(
- Query("king henry").slop(0).in_order()).total
+ assert 3 == client.ft().search(Query("henry king").slop(0).in_order()).total
+ assert 52 == client.ft().search(Query("king henry").slop(0).in_order()).total
assert 53 == client.ft().search(Query("henry king").slop(0)).total
assert 167 == client.ft().search(Query("henry king").slop(100)).total
@@ -284,11 +257,7 @@ def test_replace(client):
res = client.ft().search("foo bar")
assert 2 == res.total
- client.ft().add_document(
- "doc1",
- replace=True,
- txt="this is a replaced doc"
- )
+ client.ft().add_document("doc1", replace=True, txt="this is a replaced doc")
res = client.ft().search("foo bar")
assert 1 == res.total
@@ -301,10 +270,7 @@ def test_replace(client):
@pytest.mark.redismod
def test_stopwords(client):
- client.ft().create_index(
- (TextField("txt"),),
- stopwords=["foo", "bar", "baz"]
- )
+ client.ft().create_index((TextField("txt"),), stopwords=["foo", "bar", "baz"])
client.ft().add_document("doc1", txt="foo bar")
client.ft().add_document("doc2", txt="hello world")
waitForIndex(client, "idx")
@@ -318,17 +284,8 @@ def test_stopwords(client):
@pytest.mark.redismod
def test_filters(client):
- client.ft().create_index(
- (TextField("txt"),
- NumericField("num"),
- GeoField("loc"))
- )
- client.ft().add_document(
- "doc1",
- txt="foo bar",
- num=3.141,
- loc="-0.441,51.458"
- )
+ client.ft().create_index((TextField("txt"), NumericField("num"), GeoField("loc")))
+ client.ft().add_document("doc1", txt="foo bar", num=3.141, loc="-0.441,51.458")
client.ft().add_document("doc2", txt="foo baz", num=2, loc="-0.1,51.2")
waitForIndex(client, "idx")
@@ -336,8 +293,7 @@ def test_filters(client):
q1 = Query("foo").add_filter(NumericFilter("num", 0, 2)).no_content()
q2 = (
Query("foo")
- .add_filter(
- NumericFilter("num", 2, NumericFilter.INF, minExclusive=True))
+ .add_filter(NumericFilter("num", 2, NumericFilter.INF, minExclusive=True))
.no_content()
)
res1, res2 = client.ft().search(q1), client.ft().search(q2)
@@ -348,10 +304,8 @@ def test_filters(client):
assert "doc1" == res2.docs[0].id
# Test geo filter
- q1 = Query("foo").add_filter(
- GeoFilter("loc", -0.44, 51.45, 10)).no_content()
- q2 = Query("foo").add_filter(
- GeoFilter("loc", -0.44, 51.45, 100)).no_content()
+ q1 = Query("foo").add_filter(GeoFilter("loc", -0.44, 51.45, 10)).no_content()
+ q2 = Query("foo").add_filter(GeoFilter("loc", -0.44, 51.45, 100)).no_content()
res1, res2 = client.ft().search(q1), client.ft().search(q2)
assert 1 == res1.total
@@ -377,10 +331,7 @@ def test_payloads_with_no_content(client):
@pytest.mark.redismod
def test_sort_by(client):
- client.ft().create_index(
- (TextField("txt"),
- NumericField("num", sortable=True))
- )
+ client.ft().create_index((TextField("txt"), NumericField("num", sortable=True)))
client.ft().add_document("doc1", txt="foo bar", num=1)
client.ft().add_document("doc2", txt="foo baz", num=2)
client.ft().add_document("doc3", txt="foo qux", num=3)
@@ -422,10 +373,7 @@ def test_drop_index():
@pytest.mark.redismod
def test_example(client):
# Creating the index definition and schema
- client.ft().create_index(
- (TextField("title", weight=5.0),
- TextField("body"))
- )
+ client.ft().create_index((TextField("title", weight=5.0), TextField("body")))
# Indexing a document
client.ft().add_document(
@@ -483,12 +431,7 @@ def test_auto_complete(client):
client.ft().sugadd("ac", Suggestion("pay2", payload="pl2"))
client.ft().sugadd("ac", Suggestion("pay3", payload="pl3"))
- sugs = client.ft().sugget(
- "ac",
- "pay",
- with_payloads=True,
- with_scores=True
- )
+ sugs = client.ft().sugget("ac", "pay", with_payloads=True, with_scores=True)
assert 3 == len(sugs)
for sug in sugs:
assert sug.payload
@@ -550,11 +493,7 @@ def test_no_index(client):
@pytest.mark.redismod
def test_partial(client):
- client.ft().create_index(
- (TextField("f1"),
- TextField("f2"),
- TextField("f3"))
- )
+ client.ft().create_index((TextField("f1"), TextField("f2"), TextField("f3")))
client.ft().add_document("doc1", f1="f1_val", f2="f2_val")
client.ft().add_document("doc2", f1="f1_val", f2="f2_val")
client.ft().add_document("doc1", f3="f3_val", partial=True)
@@ -572,11 +511,7 @@ def test_partial(client):
@pytest.mark.redismod
def test_no_create(client):
- client.ft().create_index(
- (TextField("f1"),
- TextField("f2"),
- TextField("f3"))
- )
+ client.ft().create_index((TextField("f1"), TextField("f2"), TextField("f3")))
client.ft().add_document("doc1", f1="f1_val", f2="f2_val")
client.ft().add_document("doc2", f1="f1_val", f2="f2_val")
client.ft().add_document("doc1", f3="f3_val", no_create=True)
@@ -592,21 +527,12 @@ def test_no_create(client):
assert 1 == res.total
with pytest.raises(redis.ResponseError):
- client.ft().add_document(
- "doc3",
- f2="f2_val",
- f3="f3_val",
- no_create=True
- )
+ client.ft().add_document("doc3", f2="f2_val", f3="f3_val", no_create=True)
@pytest.mark.redismod
def test_explain(client):
- client.ft().create_index(
- (TextField("f1"),
- TextField("f2"),
- TextField("f3"))
- )
+ client.ft().create_index((TextField("f1"), TextField("f2"), TextField("f3")))
res = client.ft().explain("@f3:f3_val @f2:f2_val @f1:f1_val")
assert res
@@ -629,8 +555,8 @@ def test_summarize(client):
doc = sorted(client.ft().search(q).docs)[0]
assert "<b>Henry</b> IV" == doc.play
assert (
- "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
- == doc.txt
+ "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
+ == doc.txt
)
q = Query("king henry").paging(0, 1).summarize().highlight()
@@ -638,8 +564,8 @@ def test_summarize(client):
doc = sorted(client.ft().search(q).docs)[0]
assert "<b>Henry</b> ... " == doc.play
assert (
- "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
- == doc.txt
+ "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
+ == doc.txt
)
@@ -786,11 +712,7 @@ def test_alter_schema_add(client):
def test_spell_check(client):
client.ft().create_index((TextField("f1"), TextField("f2")))
- client.ft().add_document(
- "doc1",
- f1="some valid content",
- f2="this is sample text"
- )
+ client.ft().add_document("doc1", f1="some valid content", f2="this is sample text")
client.ft().add_document("doc2", f1="very important", f2="lorem ipsum")
waitForIndex(client, "idx")
@@ -812,10 +734,10 @@ def test_spell_check(client):
res = client.ft().spellcheck("lorm", include="dict")
assert len(res["lorm"]) == 3
assert (
- res["lorm"][0]["suggestion"],
- res["lorm"][1]["suggestion"],
- res["lorm"][2]["suggestion"],
- ) == ("lorem", "lore", "lorm")
+ res["lorm"][0]["suggestion"],
+ res["lorm"][1]["suggestion"],
+ res["lorm"][2]["suggestion"],
+ ) == ("lorem", "lore", "lorm")
assert (res["lorm"][0]["score"], res["lorm"][1]["score"]) == ("0.5", "0")
# test spellcheck exclude
@@ -873,7 +795,7 @@ def test_scorer(client):
)
client.ft().add_document(
"doc2",
- description="Quick alice was beginning to get very tired of sitting by her quick sister on the bank, and of having nothing to do.", # noqa
+ description="Quick alice was beginning to get very tired of sitting by her quick sister on the bank, and of having nothing to do.", # noqa
)
# default scorer is TFIDF
@@ -881,8 +803,7 @@ def test_scorer(client):
assert 1.0 == res.docs[0].score
res = client.ft().search(Query("quick").scorer("TFIDF").with_scores())
assert 1.0 == res.docs[0].score
- res = client.ft().search(
- Query("quick").scorer("TFIDF.DOCNORM").with_scores())
+ res = client.ft().search(Query("quick").scorer("TFIDF.DOCNORM").with_scores())
assert 0.1111111111111111 == res.docs[0].score
res = client.ft().search(Query("quick").scorer("BM25").with_scores())
assert 0.17699114465425977 == res.docs[0].score
@@ -1060,7 +981,7 @@ def test_aggregations_groupby(client):
)
res = client.ft().aggregate(req).rows[0]
- assert res == ['parent', 'redis', 'first', 'RediSearch']
+ assert res == ["parent", "redis", "first", "RediSearch"]
req = aggregations.AggregateRequest("redis").group_by(
"@parent",
@@ -1083,35 +1004,33 @@ def test_aggregations_sort_by_and_limit(client):
)
)
- client.ft().client.hset("doc1", mapping={'t1': 'a', 't2': 'b'})
- client.ft().client.hset("doc2", mapping={'t1': 'b', 't2': 'a'})
+ client.ft().client.hset("doc1", mapping={"t1": "a", "t2": "b"})
+ client.ft().client.hset("doc2", mapping={"t1": "b", "t2": "a"})
# test sort_by using SortDirection
- req = aggregations.AggregateRequest("*") \
- .sort_by(aggregations.Asc("@t2"), aggregations.Desc("@t1"))
+ req = aggregations.AggregateRequest("*").sort_by(
+ aggregations.Asc("@t2"), aggregations.Desc("@t1")
+ )
res = client.ft().aggregate(req)
- assert res.rows[0] == ['t2', 'a', 't1', 'b']
- assert res.rows[1] == ['t2', 'b', 't1', 'a']
+ assert res.rows[0] == ["t2", "a", "t1", "b"]
+ assert res.rows[1] == ["t2", "b", "t1", "a"]
# test sort_by without SortDirection
- req = aggregations.AggregateRequest("*") \
- .sort_by("@t1")
+ req = aggregations.AggregateRequest("*").sort_by("@t1")
res = client.ft().aggregate(req)
- assert res.rows[0] == ['t1', 'a']
- assert res.rows[1] == ['t1', 'b']
+ assert res.rows[0] == ["t1", "a"]
+ assert res.rows[1] == ["t1", "b"]
# test sort_by with max
- req = aggregations.AggregateRequest("*") \
- .sort_by("@t1", max=1)
+ req = aggregations.AggregateRequest("*").sort_by("@t1", max=1)
res = client.ft().aggregate(req)
assert len(res.rows) == 1
# test limit
- req = aggregations.AggregateRequest("*") \
- .sort_by("@t1").limit(1, 1)
+ req = aggregations.AggregateRequest("*").sort_by("@t1").limit(1, 1)
res = client.ft().aggregate(req)
assert len(res.rows) == 1
- assert res.rows[0] == ['t1', 'b']
+ assert res.rows[0] == ["t1", "b"]
@pytest.mark.redismod
@@ -1123,17 +1042,17 @@ def test_aggregations_load(client):
)
)
- client.ft().client.hset("doc1", mapping={'t1': 'hello', 't2': 'world'})
+ client.ft().client.hset("doc1", mapping={"t1": "hello", "t2": "world"})
# load t1
req = aggregations.AggregateRequest("*").load("t1")
res = client.ft().aggregate(req)
- assert res.rows[0] == ['t1', 'hello']
+ assert res.rows[0] == ["t1", "hello"]
# load t2
req = aggregations.AggregateRequest("*").load("t2")
res = client.ft().aggregate(req)
- assert res.rows[0] == ['t2', 'world']
+ assert res.rows[0] == ["t2", "world"]
@pytest.mark.redismod
@@ -1147,24 +1066,19 @@ def test_aggregations_apply(client):
client.ft().client.hset(
"doc1",
- mapping={
- 'PrimaryKey': '9::362330',
- 'CreatedDateTimeUTC': '637387878524969984'
- }
+ mapping={"PrimaryKey": "9::362330", "CreatedDateTimeUTC": "637387878524969984"},
)
client.ft().client.hset(
"doc2",
- mapping={
- 'PrimaryKey': '9::362329',
- 'CreatedDateTimeUTC': '637387875859270016'
- }
+ mapping={"PrimaryKey": "9::362329", "CreatedDateTimeUTC": "637387875859270016"},
)
- req = aggregations.AggregateRequest("*") \
- .apply(CreatedDateTimeUTC='@CreatedDateTimeUTC * 10')
+ req = aggregations.AggregateRequest("*").apply(
+ CreatedDateTimeUTC="@CreatedDateTimeUTC * 10"
+ )
res = client.ft().aggregate(req)
- assert res.rows[0] == ['CreatedDateTimeUTC', '6373878785249699840']
- assert res.rows[1] == ['CreatedDateTimeUTC', '6373878758592700416']
+ assert res.rows[0] == ["CreatedDateTimeUTC", "6373878785249699840"]
+ assert res.rows[1] == ["CreatedDateTimeUTC", "6373878758592700416"]
@pytest.mark.redismod
@@ -1176,33 +1090,19 @@ def test_aggregations_filter(client):
)
)
- client.ft().client.hset(
- "doc1",
- mapping={
- 'name': 'bar',
- 'age': '25'
- }
- )
- client.ft().client.hset(
- "doc2",
- mapping={
- 'name': 'foo',
- 'age': '19'
- }
- )
+ client.ft().client.hset("doc1", mapping={"name": "bar", "age": "25"})
+ client.ft().client.hset("doc2", mapping={"name": "foo", "age": "19"})
- req = aggregations.AggregateRequest("*") \
- .filter("@name=='foo' && @age < 20")
+ req = aggregations.AggregateRequest("*").filter("@name=='foo' && @age < 20")
res = client.ft().aggregate(req)
assert len(res.rows) == 1
- assert res.rows[0] == ['name', 'foo', 'age', '19']
+ assert res.rows[0] == ["name", "foo", "age", "19"]
- req = aggregations.AggregateRequest("*") \
- .filter("@age > 15").sort_by("@age")
+ req = aggregations.AggregateRequest("*").filter("@age > 15").sort_by("@age")
res = client.ft().aggregate(req)
assert len(res.rows) == 2
- assert res.rows[0] == ['age', '19']
- assert res.rows[1] == ['age', '25']
+ assert res.rows[0] == ["age", "19"]
+ assert res.rows[1] == ["age", "25"]
@pytest.mark.redismod
@@ -1226,25 +1126,25 @@ def test_index_definition(client):
)
assert [
- "ON",
- "JSON",
- "PREFIX",
- 2,
- "hset:",
- "henry",
- "FILTER",
- "@f1==32",
- "LANGUAGE_FIELD",
- "play",
- "LANGUAGE",
- "English",
- "SCORE_FIELD",
- "chapter",
- "SCORE",
- 0.5,
- "PAYLOAD_FIELD",
- "txt",
- ] == definition.args
+ "ON",
+ "JSON",
+ "PREFIX",
+ 2,
+ "hset:",
+ "henry",
+ "FILTER",
+ "@f1==32",
+ "LANGUAGE_FIELD",
+ "play",
+ "LANGUAGE",
+ "English",
+ "SCORE_FIELD",
+ "chapter",
+ "SCORE",
+ 0.5,
+ "PAYLOAD_FIELD",
+ "txt",
+ ] == definition.args
createIndex(client.ft(), num_docs=500, definition=definition)
@@ -1274,10 +1174,7 @@ def test_create_client_definition_hash(client):
Create definition with IndexType.HASH as index type (ON HASH),
and use hset to test the client definition.
"""
- definition = IndexDefinition(
- prefix=["hset:", "henry"],
- index_type=IndexType.HASH
- )
+ definition = IndexDefinition(prefix=["hset:", "henry"], index_type=IndexType.HASH)
createIndex(client.ft(), num_docs=500, definition=definition)
info = client.ft().info()
@@ -1320,15 +1217,10 @@ def test_fields_as_name(client):
client.ft().create_index(SCHEMA, definition=definition)
# insert json data
- res = client.json().set(
- "doc:1",
- Path.rootPath(),
- {"name": "Jon", "age": 25}
- )
+ res = client.json().set("doc:1", Path.rootPath(), {"name": "Jon", "age": 25})
assert res
- total = client.ft().search(
- Query("Jon").return_fields("name", "just_a_number")).docs
+ total = client.ft().search(Query("Jon").return_fields("name", "just_a_number")).docs
assert 1 == len(total)
assert "doc:1" == total[0].id
assert "Jon" == total[0].name
@@ -1354,14 +1246,12 @@ def test_search_return_fields(client):
client.ft().create_index(SCHEMA, definition=definition)
waitForIndex(client, "idx")
- total = client.ft().search(
- Query("*").return_field("$.t", as_field="txt")).docs
+ total = client.ft().search(Query("*").return_field("$.t", as_field="txt")).docs
assert 1 == len(total)
assert "doc:1" == total[0].id
assert "riceratops" == total[0].txt
- total = client.ft().search(
- Query("*").return_field("$.t2", as_field="txt")).docs
+ total = client.ft().search(Query("*").return_field("$.t2", as_field="txt")).docs
assert 1 == len(total)
assert "doc:1" == total[0].id
assert "telmatosaurus" == total[0].txt
@@ -1379,17 +1269,10 @@ def test_synupdate(client):
)
client.ft().synupdate("id1", True, "boy", "child", "offspring")
- client.ft().add_document(
- "doc1",
- title="he is a baby",
- body="this is a test")
+ client.ft().add_document("doc1", title="he is a baby", body="this is a test")
client.ft().synupdate("id1", True, "baby")
- client.ft().add_document(
- "doc2",
- title="he is another baby",
- body="another test"
- )
+ client.ft().add_document("doc2", title="he is another baby", body="another test")
res = client.ft().search(Query("child").expander("SYNONYM"))
assert res.docs[0].id == "doc2"
@@ -1431,15 +1314,12 @@ def test_create_json_with_alias(client):
"""
definition = IndexDefinition(prefix=["king:"], index_type=IndexType.JSON)
client.ft().create_index(
- (TextField("$.name", as_name="name"),
- NumericField("$.num", as_name="num")),
- definition=definition
+ (TextField("$.name", as_name="name"), NumericField("$.num", as_name="num")),
+ definition=definition,
)
- client.json().set("king:1", Path.rootPath(), {"name": "henry",
- "num": 42})
- client.json().set("king:2", Path.rootPath(), {"name": "james",
- "num": 3.14})
+ client.json().set("king:1", Path.rootPath(), {"name": "henry", "num": 42})
+ client.json().set("king:2", Path.rootPath(), {"name": "james", "num": 3.14})
res = client.ft().search("@name:henry")
assert res.docs[0].id == "king:1"
@@ -1466,12 +1346,12 @@ def test_json_with_multipath(client):
"""
definition = IndexDefinition(prefix=["king:"], index_type=IndexType.JSON)
client.ft().create_index(
- (TagField("$..name", as_name="name")),
- definition=definition
+ (TagField("$..name", as_name="name")), definition=definition
)
- client.json().set("king:1", Path.rootPath(),
- {"name": "henry", "country": {"name": "england"}})
+ client.json().set(
+ "king:1", Path.rootPath(), {"name": "henry", "country": {"name": "england"}}
+ )
res = client.ft().search("@name:{henry}")
assert res.docs[0].id == "king:1"
@@ -1489,9 +1369,11 @@ def test_json_with_multipath(client):
def test_json_with_jsonpath(client):
definition = IndexDefinition(index_type=IndexType.JSON)
client.ft().create_index(
- (TextField('$["prod:name"]', as_name="name"),
- TextField('$.prod:name', as_name="name_unsupported")),
- definition=definition
+ (
+ TextField('$["prod:name"]', as_name="name"),
+ TextField("$.prod:name", as_name="name_unsupported"),
+ ),
+ definition=definition,
)
client.json().set("doc:1", Path.rootPath(), {"prod:name": "RediSearch"})
@@ -1510,11 +1392,10 @@ def test_json_with_jsonpath(client):
res = client.ft().search(Query("@name:RediSearch").return_field("name"))
assert res.total == 1
assert res.docs[0].id == "doc:1"
- assert res.docs[0].name == 'RediSearch'
+ assert res.docs[0].name == "RediSearch"
# return of an unsupported field fails
- res = client.ft().search(Query("@name:RediSearch")
- .return_field("name_unsupported"))
+ res = client.ft().search(Query("@name:RediSearch").return_field("name_unsupported"))
assert res.total == 1
assert res.docs[0].id == "doc:1"
with pytest.raises(Exception):
@@ -1523,42 +1404,49 @@ def test_json_with_jsonpath(client):
@pytest.mark.redismod
def test_profile(client):
- client.ft().create_index((TextField('t'),))
- client.ft().client.hset('1', 't', 'hello')
- client.ft().client.hset('2', 't', 'world')
+ client.ft().create_index((TextField("t"),))
+ client.ft().client.hset("1", "t", "hello")
+ client.ft().client.hset("2", "t", "world")
# check using Query
- q = Query('hello|world').no_content()
+ q = Query("hello|world").no_content()
res, det = client.ft().profile(q)
- assert det['Iterators profile']['Counter'] == 2.0
- assert len(det['Iterators profile']['Child iterators']) == 2
- assert det['Iterators profile']['Type'] == 'UNION'
- assert det['Parsing time'] < 0.3
+ assert det["Iterators profile"]["Counter"] == 2.0
+ assert len(det["Iterators profile"]["Child iterators"]) == 2
+ assert det["Iterators profile"]["Type"] == "UNION"
+ assert det["Parsing time"] < 0.3
assert len(res.docs) == 2 # check also the search result
# check using AggregateRequest
- req = aggregations.AggregateRequest("*").load("t")\
+ req = (
+ aggregations.AggregateRequest("*")
+ .load("t")
.apply(prefix="startswith(@t, 'hel')")
+ )
res, det = client.ft().profile(req)
- assert det['Iterators profile']['Counter'] == 2.0
- assert det['Iterators profile']['Type'] == 'WILDCARD'
- assert det['Parsing time'] < 0.3
+ assert det["Iterators profile"]["Counter"] == 2.0
+ assert det["Iterators profile"]["Type"] == "WILDCARD"
+ assert det["Parsing time"] < 0.3
assert len(res.rows) == 2 # check also the search result
@pytest.mark.redismod
def test_profile_limited(client):
- client.ft().create_index((TextField('t'),))
- client.ft().client.hset('1', 't', 'hello')
- client.ft().client.hset('2', 't', 'hell')
- client.ft().client.hset('3', 't', 'help')
- client.ft().client.hset('4', 't', 'helowa')
+ client.ft().create_index((TextField("t"),))
+ client.ft().client.hset("1", "t", "hello")
+ client.ft().client.hset("2", "t", "hell")
+ client.ft().client.hset("3", "t", "help")
+ client.ft().client.hset("4", "t", "helowa")
- q = Query('%hell% hel*')
+ q = Query("%hell% hel*")
res, det = client.ft().profile(q, limited=True)
- assert det['Iterators profile']['Child iterators'][0]['Child iterators'] \
- == 'The number of iterators in the union is 3'
- assert det['Iterators profile']['Child iterators'][1]['Child iterators'] \
- == 'The number of iterators in the union is 4'
- assert det['Iterators profile']['Type'] == 'INTERSECT'
+ assert (
+ det["Iterators profile"]["Child iterators"][0]["Child iterators"]
+ == "The number of iterators in the union is 3"
+ )
+ assert (
+ det["Iterators profile"]["Child iterators"][1]["Child iterators"]
+ == "The number of iterators in the union is 4"
+ )
+ assert det["Iterators profile"]["Type"] == "INTERSECT"
assert len(res.docs) == 3 # check also the search result