Skip to content

Commit f48cb08

Browse files
committed
properties: nearest_neighbor bound to Float32Vector exclusively; tests: added bool #29
1 parent fb2e926 commit f48cb08

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

objectbox/model/properties.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,6 @@ def contains_key_value(self, key: str, value: str, case_sensitive: bool = True)
320320
class _VectorProperty(Property):
321321
def __init__(self, py_type : Type, **kwargs):
322322
super(_VectorProperty, self).__init__(py_type, **kwargs)
323-
def nearest_neighbor(self, query_vector, element_count: int) -> PropertyQueryCondition:
324-
args = {'query_vector': query_vector, 'element_count': element_count}
325-
return PropertyQueryCondition(self._id, PropertyQueryConditionOp.NEAREST_NEIGHBOR, args)
326323

327324
class BoolVector(_VectorProperty):
328325
def __init__(self, id: int = 0, uid: int = 0, **kwargs):
@@ -350,6 +347,9 @@ def __init__(self, id: int = 0, uid: int = 0, **kwargs):
350347
class Float32Vector(_VectorProperty):
351348
def __init__(self, id: int = 0, uid: int = 0, **kwargs):
352349
super(Float32Vector, self).__init__(np.ndarray, type=PropertyType.floatVector, id=id, uid=uid, **kwargs)
350+
def nearest_neighbor(self, query_vector, element_count: int) -> PropertyQueryCondition:
351+
args = {'query_vector': query_vector, 'element_count': element_count}
352+
return PropertyQueryCondition(self._id, PropertyQueryConditionOp.NEAREST_NEIGHBOR, args)
353353

354354
class Float64Vector(_VectorProperty):
355355
def __init__(self, id: int = 0, uid: int = 0, **kwargs):

tests/test_query.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,24 @@ def test_basics():
1212
store = create_test_store()
1313

1414
box_test_entity = store.box(TestEntity)
15-
box_test_entity.put(TestEntity(str="foo", int64=123))
16-
box_test_entity.put(TestEntity(str="bar", int64=456))
15+
id1 = box_test_entity.put(TestEntity(bool=True, str="foo", int64=123))
16+
id2 = box_test_entity.put(TestEntity(bool=False, str="bar", int64=456))
1717

1818
box_vector_entity = store.box(VectorEntity)
1919
box_vector_entity.put(VectorEntity(name="Object 1", vector_euclidean=[1, 1]))
2020
box_vector_entity.put(VectorEntity(name="Object 2", vector_euclidean=[2, 2]))
2121
box_vector_entity.put(VectorEntity(name="Object 3", vector_euclidean=[3, 3]))
2222

23+
# Bool query
24+
bool_prop: Property = TestEntity.get_property("bool")
25+
query = box_test_entity.query(bool_prop.equals(True)).build()
26+
assert query.count() == 1
27+
assert query.find()[0].id == id1
28+
29+
query = box_test_entity.query(bool_prop.equals(False)).build()
30+
assert query.count() == 1
31+
assert query.find()[0].id == id2
32+
2333
# String query
2434
str_prop: Property = TestEntity.get_property("str")
2535

@@ -194,7 +204,8 @@ def test_float_scalars():
194204
box_test_entity = store.box(TestEntity)
195205
id1 = box_test_entity.put(TestEntity(float32=12, float64=12))
196206
id2 = box_test_entity.put(TestEntity(float32=45, float64=45))
197-
207+
208+
# Test int scalar literals
198209
props = [ "float32", "float64" ]
199210
for p in props:
200211
prop = TestEntity.get_property(p)
@@ -217,7 +228,7 @@ def test_float_scalars():
217228
assert query.find()[0].id == id1
218229
assert query.find()[1].id == id2
219230

220-
# Test float scalar values
231+
# Test float scalar literals
221232
for p in props:
222233
prop = TestEntity.get_property(p)
223234
query = box_test_entity.query(prop.greater_or_equal(11.0)).build()

0 commit comments

Comments
 (0)