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

Class Result

redis/commands/search/result.py:9–157  ·  view source on GitHub ↗

Represents the result of a search query, and has an array of Document objects

Source from the content-addressed store, hash-verified

7
8
9class Result:
10 """
11 Represents the result of a search query, and has an array of Document
12 objects
13 """
14
15 def __init__(
16 self,
17 res,
18 hascontent,
19 duration=0,
20 has_payload=False,
21 with_scores=False,
22 field_encodings: Optional[dict] = None,
23 warnings: Optional[List[str]] = None,
24 ):
25 """
26 - duration: the execution time of the query
27 - has_payload: whether the query has payloads
28 - with_scores: whether the query has scores
29 - field_encodings: a dictionary of field encodings if any is provided
30 - warnings: list of server warnings (from RESP3 responses)
31 """
32
33 self.total = res[0]
34 self.duration = duration
35 self.docs = []
36 self.warnings = warnings or []
37
38 step = 1
39 if hascontent:
40 step = step + 1
41 if has_payload:
42 step = step + 1
43 if with_scores:
44 step = step + 1
45
46 offset = 2 if with_scores else 1
47
48 for i in range(1, len(res), step):
49 id = to_string(res[i])
50 payload = to_string(res[i + offset]) if has_payload else None
51 # fields_offset = 2 if has_payload else 1
52 fields_offset = offset + 1 if has_payload else offset
53 score = float(res[i + 1]) if with_scores else None
54
55 fields = {}
56 if hascontent and res[i + fields_offset] is not None:
57 keys = map(to_string, res[i + fields_offset][::2])
58 values = res[i + fields_offset][1::2]
59
60 for key, value in zip(keys, values):
61 if field_encodings is None or key not in field_encodings:
62 fields[key] = to_string(value)
63 continue
64
65 encoding = field_encodings[key]
66

Callers 3

_parse_searchMethod · 0.85
_parse_profileMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected