From 8bfd492240fd33489a86cd3d353e3ece1fc94c10 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Sinha Date: Thu, 16 Mar 2023 01:19:02 +0530 Subject: [PATCH] Making search document subscriptable (#2615) * Fixed issue #2598 - make Document class subscriptable * Last time added older file, fixed it * retrigger checks * update json().arrindex() default values (#2611) * update json().arrindex() default values * add unit test * fix falsy checks * more unit tests * add asyncio tests * fix lint line length --------- Co-authored-by: Alex Schmitz * Speeding up the protocol parsing (#2596) * speeding up the protocol parser * linting * changes to ease * Fixed CredentialsProvider examples (#2587) Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com> * ConnectionPool SSL example (#2605) * [types] update return type of smismember to list[int] (#2617) * update return type of smismember * use Literal instead of int * retrigger checks * Added test for document subscriptable in tests/test_search.py * Fixed linter issue * retrigger checks --------- Co-authored-by: Alex Schmitz Co-authored-by: Alex Schmitz Co-authored-by: Chayim Co-authored-by: Bar Shaul <88437685+barshaul@users.noreply.github.com> Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com> Co-authored-by: CrimsonGlory Co-authored-by: Raymond Yin --- redis/commands/search/document.py | 4 ++++ tests/test_search.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/redis/commands/search/document.py b/redis/commands/search/document.py index 5b3050545a..47534ec248 100644 --- a/redis/commands/search/document.py +++ b/redis/commands/search/document.py @@ -11,3 +11,7 @@ def __init__(self, id, payload=None, **fields): def __repr__(self): return f"Document {self.__dict__}" + + def __getitem__(self, item): + value = getattr(self, item) + return value diff --git a/tests/test_search.py b/tests/test_search.py index 57d4338ead..7a2428151e 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -140,7 +140,9 @@ def test_client(client): for doc in res.docs: assert doc.id + assert doc["id"] assert doc.play == "Henry IV" + assert doc["play"] == "Henry IV" assert len(doc.txt) > 0 # test no content