Repository: redis/redis-py
File: tests/test_search.py (Python)

Code before:
            assert len(res["results"]) == 1
            assert res["results"][0]["extra_attributes"] == {"name": "foo", "age": "19"}

            req = (
                aggregations.AggregateRequest("*")
                .filter("@age > 15")
                .sort_by("@age")
                .dialect(dialect)
            )
            res = client.ft().aggregate(req)
            assert len(res["results"]) == 2
            assert res["results"][0]["extra_attributes"] == {"age": "19"}
            assert res["results"][1]["extra_attributes"] == {"age": "25"}


@pytest.mark.redismod
@skip_ifmodversion_lt("2.10.05", "search")
def test_aggregations_add_scores(client):
    client.ft().create_index(
        (
            TextField("name", sortable=True, weight=5.0),
            NumericField("age", sortable=True),
        )
    )

    client.ft().client.hset("doc1", mapping={"name": "bar", "age": "25"})
    client.ft().client.hset("doc2", mapping={"name": "foo", "age": "19"})

    req = aggregations.AggregateRequest("*").add_scores()
    res = client.ft().aggregate(req)
    assert len(res.rows) == 2
    assert res.rows[0] == ["__score", "0.2"]
    assert res.rows[1] == ["__score", "0.2"]


@pytest.mark.redismod
@skip_ifmodversion_lt("2.0.0", "search")
def test_index_definition(client):
    """
    Create definition and test its args
    """
    with pytest.raises(RuntimeError):
        IndexDefinition(prefix=["hset:", "henry"], index_type="json")

    definition = IndexDefinition(
        prefix=["hset:", "henry"],
        filter="@f1==32",
        language="English",
        language_field="play",
        score_field="chapter",
        score=0.5,

Review comment (suggestion):
See my comment above. In this case should be just `client` instead of `client.ft().client`

Code after:
            assert len(res["results"]) == 1
            assert res["results"][0]["extra_attributes"] == {"name": "foo", "age": "19"}

            req = (
                aggregations.AggregateRequest("*")
                .filter("@age > 15")
                .sort_by("@age")
                .dialect(dialect)
            )
            res = client.ft().aggregate(req)
            assert len(res["results"]) == 2
            assert res["results"][0]["extra_attributes"] == {"age": "19"}
            assert res["results"][1]["extra_attributes"] == {"age": "25"}


@pytest.mark.redismod
@skip_ifmodversion_lt("2.10.05", "search")
def test_aggregations_add_scores(client):
    client.ft().create_index(
        (
            TextField("name", sortable=True, weight=5.0),
            NumericField("age", sortable=True),
        )
    )

    client.hset("doc1", mapping={"name": "bar", "age": "25"})
    client.hset("doc2", mapping={"name": "foo", "age": "19"})

    req = aggregations.AggregateRequest("*").add_scores()
    res = client.ft().aggregate(req)

    if isinstance(res, dict):
        assert len(res["results"]) == 2
        assert res["results"][0]["extra_attributes"] == {"__score": "0.2"}
        assert res["results"][1]["extra_attributes"] == {"__score": "0.2"}
    else:
        assert len(res.rows) == 2
        assert res.rows[0] == ["__score", "0.2"]
        assert res.rows[1] == ["__score", "0.2"]


@pytest.mark.redismod
@skip_ifmodversion_lt("2.0.0", "search")
def test_index_definition(client):
    """
    Create definition and test its args
    """
    with pytest.raises(RuntimeError):
        IndexDefinition(prefix=["hset:", "henry"], index_type="json")

    definition = IndexDefinition(