@@ -25,8 +25,6 @@ def __init__(self, *args):
2525 new_db = not os .path .exists (dbdir )
2626 self ._store = objectbox .Store (model = get_objectbox_model (),directory = dbdir )
2727 self ._box = self ._store .box (City )
28- self ._name_prop : Property = City .get_property ("name" )
29- self ._location_prop : Property = City .get_property ("location" )
3028 if new_db :
3129 with open (os .path .join (os .path .dirname (__file__ ), 'cities.csv' )) as f :
3230 r = csv .reader (f )
@@ -40,8 +38,7 @@ def __init__(self, *args):
4038
4139 def do_ls (self , name : str = "" ):
4240 """list all cities or starting with <prefix>\n usage: ls [<prefix>]"""
43- qb = self ._box .query ()
44- qb .starts_with_string (self ._name_prop , name )
41+ qb = self ._box .query ( City .name .starts_with (name ) )
4542 query = qb .build ()
4643 list_cities (query .find ())
4744
@@ -57,15 +54,15 @@ def do_city_neighbors(self, args: str):
5754 num = 5
5855 if len (args ) == 2 :
5956 num = int (args [1 ])
60- qb = self ._box .query ()
61- qb .equals_string (self ._name_prop , city )
57+ qb = self ._box .query ( City .name .equals (city ) )
6258 query = qb .build ()
6359 cities = query .find ()
6460 if len (cities ) == 1 :
6561 location = cities [0 ].location
66- qb = self ._box .query ()
67- qb .nearest_neighbors_f32 (self ._location_prop , location , num + 1 ) # +1 for the city
68- qb .not_equals_string (self ._name_prop , city )
62+ # +1 for the city
63+ qb = self ._box .query (
64+ City .location .nearest_neighbor (location , num + 1 ) & City .name .not_equals (city )
65+ )
6966 neighbors = qb .build ().find_with_scores ()
7067 list_cities_with_scores (neighbors )
7168 else :
@@ -81,8 +78,9 @@ def do_neighbors(self, args):
8178 raise ValueError ()
8279 num = int (args [0 ])
8380 geocoord = [ float (args [1 ]), float (args [2 ]) ]
84- qb = self ._box .query ()
85- qb .nearest_neighbors_f32 (self ._location_prop , geocoord , num )
81+ qb = self ._box .query (
82+ City .location .nearest_neighbor (geocoord , num )
83+ )
8684 neighbors = qb .build ().find_with_scores ()
8785 list_cities_with_scores (neighbors )
8886 except ValueError :
0 commit comments