(self, client)
| 2585 | @pytest.mark.redismod |
| 2586 | @skip_ifmodversion_lt("2.2.0", "search") |
| 2587 | def test_json_with_jsonpath(self, client): |
| 2588 | definition = IndexDefinition(index_type=IndexType.JSON) |
| 2589 | client.ft().create_index( |
| 2590 | ( |
| 2591 | TextField('$["prod:name"]', as_name="name"), |
| 2592 | TextField("$.prod:name", as_name="name_unsupported"), |
| 2593 | ), |
| 2594 | definition=definition, |
| 2595 | ) |
| 2596 | |
| 2597 | client.json().set("doc:1", Path.root_path(), {"prod:name": "RediSearch"}) |
| 2598 | |
| 2599 | if expects_resp2_shape(client) or expects_unified_shape(client): |
| 2600 | # query for a supported field succeeds |
| 2601 | res = client.ft().search(Query("@name:RediSearch")) |
| 2602 | assert res.total == 1 |
| 2603 | assert res.docs[0].id == "doc:1" |
| 2604 | assert res.docs[0].json == '{"prod:name":"RediSearch"}' |
| 2605 | |
| 2606 | # query for an unsupported field |
| 2607 | res = client.ft().search("@name_unsupported:RediSearch") |
| 2608 | assert res.total == 1 |
| 2609 | |
| 2610 | # return of a supported field succeeds |
| 2611 | res = client.ft().search(Query("@name:RediSearch").return_field("name")) |
| 2612 | assert res.total == 1 |
| 2613 | assert res.docs[0].id == "doc:1" |
| 2614 | assert res.docs[0].name == "RediSearch" |
| 2615 | elif expects_resp3_shape(client): |
| 2616 | # query for a supported field succeeds |
| 2617 | res = client.ft().search(Query("@name:RediSearch")) |
| 2618 | assert res["total_results"] == 1 |
| 2619 | assert res["results"][0]["id"] == "doc:1" |
| 2620 | assert ( |
| 2621 | res["results"][0]["extra_attributes"]["$"] |
| 2622 | == '{"prod:name":"RediSearch"}' |
| 2623 | ) |
| 2624 | |
| 2625 | # query for an unsupported field |
| 2626 | res = client.ft().search("@name_unsupported:RediSearch") |
| 2627 | assert res["total_results"] == 1 |
| 2628 | |
| 2629 | # return of a supported field succeeds |
| 2630 | res = client.ft().search(Query("@name:RediSearch").return_field("name")) |
| 2631 | assert res["total_results"] == 1 |
| 2632 | assert res["results"][0]["id"] == "doc:1" |
| 2633 | assert res["results"][0]["extra_attributes"]["name"] == "RediSearch" |
| 2634 | |
| 2635 | |
| 2636 | class TestProfile(SearchTestsBase): |
nothing calls this directly
no test coverage detected