MCPcopy
hub / github.com/redis/redis-py / test_sort_by

Method test_sort_by

tests/test_search.py:499–527  ·  view source on GitHub ↗
(self, client)

Source from the content-addressed store, hash-verified

497
498 @pytest.mark.redismod
499 def test_sort_by(self, client):
500 client.ft().create_index((TextField("txt"), NumericField("num", sortable=True)))
501 client.hset("doc1", mapping={"txt": "foo bar", "num": 1})
502 client.hset("doc2", mapping={"txt": "foo baz", "num": 2})
503 client.hset("doc3", mapping={"txt": "foo qux", "num": 3})
504
505 # Test sort
506 q1 = Query("foo").sort_by("num", asc=True).no_content()
507 q2 = Query("foo").sort_by("num", asc=False).no_content()
508 res1, res2 = client.ft().search(q1), client.ft().search(q2)
509
510 if expects_resp2_shape(client) or expects_unified_shape(client):
511 assert 3 == res1.total
512 assert "doc1" == res1.docs[0].id
513 assert "doc2" == res1.docs[1].id
514 assert "doc3" == res1.docs[2].id
515 assert 3 == res2.total
516 assert "doc1" == res2.docs[2].id
517 assert "doc2" == res2.docs[1].id
518 assert "doc3" == res2.docs[0].id
519 elif expects_resp3_shape(client):
520 assert 3 == res1["total_results"]
521 assert "doc1" == res1["results"][0]["id"]
522 assert "doc2" == res1["results"][1]["id"]
523 assert "doc3" == res1["results"][2]["id"]
524 assert 3 == res2["total_results"]
525 assert "doc1" == res2["results"][2]["id"]
526 assert "doc2" == res2["results"][1]["id"]
527 assert "doc3" == res2["results"][0]["id"]
528
529 @pytest.mark.redismod
530 @skip_ifmodversion_lt("2.0.0", "search")

Callers

nothing calls this directly

Calls 12

TextFieldClass · 0.90
NumericFieldClass · 0.90
QueryClass · 0.90
expects_resp2_shapeFunction · 0.85
expects_unified_shapeFunction · 0.85
expects_resp3_shapeFunction · 0.85
create_indexMethod · 0.80
hsetMethod · 0.80
no_contentMethod · 0.80
ftMethod · 0.45
sort_byMethod · 0.45
searchMethod · 0.45

Tested by

no test coverage detected