@@ -22,10 +22,10 @@ def __init__(self, c_query, box: 'Box'):
22
22
self ._ob = box ._ob
23
23
24
24
def find (self ) -> list :
25
+ """ Finds a list of objects matching query. """
25
26
with self ._ob .read_tx ():
26
27
# OBX_bytes_array*
27
28
c_bytes_array_p = obx_query_find (self ._c_query )
28
-
29
29
try :
30
30
# OBX_bytes_array
31
31
c_bytes_array = c_bytes_array_p .contents
@@ -36,11 +36,48 @@ def find(self) -> list:
36
36
c_bytes = c_bytes_array .data [i ]
37
37
data = c_voidp_as_bytes (c_bytes .data , c_bytes .size )
38
38
result .append (self ._box ._entity .unmarshal (data ))
39
-
40
39
return result
41
40
finally :
42
41
obx_bytes_array_free (c_bytes_array_p )
43
42
43
+ def find_ids (self ) -> List [int ]:
44
+ """ Finds a list of object IDs matching query. The result is sorted by ID (ascending order). """
45
+ c_id_array_p = obx_query_find_ids (self ._c_query )
46
+ try :
47
+ return list (c_id_array_p .contents )
48
+ finally :
49
+ obx_id_array_free (c_id_array_p )
50
+
51
+ def find_with_scores (self ):
52
+ """ Finds objects matching the query associated to their query score (e.g. distance in NN search).
53
+ The result is sorted by score in ascending order. """
54
+ c_bytes_score_array_p = obx_query_find_with_scores (self ._c_query )
55
+ try :
56
+ # OBX_bytes_score_array
57
+ c_bytes_score_array : OBX_bytes_score_array = c_bytes_score_array_p .contents
58
+ result = []
59
+ for i in range (c_bytes_score_array .count ):
60
+ # TODO implement
61
+ pass
62
+ return result
63
+ finally :
64
+ obx_bytes_score_array_free (c_bytes_score_array_p )
65
+
66
+ def find_ids_with_scores (self ) -> List [Tuple [int , float ]]:
67
+ """ Finds object IDs matching the query associated to their query score (e.g. distance in NN search).
68
+ The resulting list is sorted by score in ascending order. """
69
+ c_id_score_array_p = obx_query_find_ids_with_scores (self ._c_query )
70
+ try :
71
+ # OBX_id_score_array
72
+ c_id_score_array : OBX_bytes_score_array = c_id_score_array_p .contents
73
+ result = []
74
+ for i in range (c_id_score_array .count ):
75
+ c_id_score : OBX_id_score = c_id_score_array .ids_scores [i ]
76
+ result .append ((c_id_score .id , c_id_score .score ))
77
+ return result
78
+ finally :
79
+ obx_id_score_array_free (c_id_score_array_p )
80
+
44
81
def count (self ) -> int :
45
82
count = ctypes .c_uint64 ()
46
83
obx_query_count (self ._c_query , ctypes .byref (count ))
@@ -55,4 +92,4 @@ def offset(self, offset: int):
55
92
return obx_query_offset (self ._c_query , offset )
56
93
57
94
def limit (self , limit : int ):
58
- return obx_query_limit (self ._c_query , limit )
95
+ return obx_query_limit (self ._c_query , limit )
0 commit comments