(self, client)
| 1595 | @skip_if_server_version_lt("7.4.0") |
| 1596 | @skip_ifmodversion_lt("2.10.0", "search") |
| 1597 | def test_search_empty_fields(self, client): |
| 1598 | definition = IndexDefinition(prefix=["property:"], index_type=IndexType.HASH) |
| 1599 | |
| 1600 | fields = [ |
| 1601 | TextField("title", sortable=True), |
| 1602 | TagField("features", index_empty=True), |
| 1603 | TextField("description", index_empty=True), |
| 1604 | ] |
| 1605 | |
| 1606 | client.ft().create_index(fields, definition=definition) |
| 1607 | |
| 1608 | # All fields present |
| 1609 | client.hset( |
| 1610 | "property:1", |
| 1611 | mapping={ |
| 1612 | "title": "Luxury Villa in Malibu", |
| 1613 | "features": "pool,sea view,modern", |
| 1614 | "description": "A stunning modern villa overlooking the Pacific Ocean.", |
| 1615 | }, |
| 1616 | ) |
| 1617 | |
| 1618 | # Empty features |
| 1619 | client.hset( |
| 1620 | "property:2", |
| 1621 | mapping={ |
| 1622 | "title": "Downtown Flat", |
| 1623 | "features": "", |
| 1624 | "description": "Modern flat in central Paris with easy access to metro.", |
| 1625 | }, |
| 1626 | ) |
| 1627 | |
| 1628 | # Empty description |
| 1629 | client.hset( |
| 1630 | "property:3", |
| 1631 | mapping={ |
| 1632 | "title": "Beachfront Bungalow", |
| 1633 | "features": "beachfront,sun deck", |
| 1634 | "description": "", |
| 1635 | }, |
| 1636 | ) |
| 1637 | |
| 1638 | with pytest.raises(redis.exceptions.ResponseError) as e: |
| 1639 | client.ft().search(Query("@title:''").return_field("id").no_content()) |
| 1640 | assert "Use `INDEXEMPTY` in field creation" in e.value.args[0] |
| 1641 | |
| 1642 | res = client.ft().search( |
| 1643 | Query("@features:{$empty}").return_field("id").no_content(), |
| 1644 | query_params={"empty": ""}, |
| 1645 | ) |
| 1646 | _assert_search_result(client, res, ["property:2"]) |
| 1647 | |
| 1648 | res = client.ft().search( |
| 1649 | Query("-@features:{$empty}").return_field("id").no_content(), |
| 1650 | query_params={"empty": ""}, |
| 1651 | ) |
| 1652 | _assert_search_result(client, res, ["property:1", "property:3"]) |
| 1653 | |
| 1654 | res = client.ft().search( |
nothing calls this directly
no test coverage detected