def search_name(self, search_terms): results = self._search.search( { 'query': { 'bool': { 'should': [ {'match': {'names': search_terms}}, {'term': {'identifiers': search_terms}} ] } } }, index=self._instance_name, doc_type='poi' ) slugs = [result['_id'] for result in results['hits']['hits']] if len(slugs) > 0: poi_dicts = { data['slug']: PointOfInterest.from_dict(data) for data in self._collection.find({'$or': [{'slug': slug} for slug in slugs]}) } return [poi_dicts[slug] for slug in slugs] else: return []
def test_geojson_is_deserialised(self): point = Point(-2.14, 53.28) poi = PointOfInterest.from_dict( {"geography": self._point_to_geojson(point), "location": self._point_to_geojson(point)} ) self.assertEquals(point.wkt, poi.location.wkt) self.assertEquals(point.wkt, poi.geography.wkt)
def select_by_slug(self, slug): poi_dict = self._collection.find_one({'slug': slug}) return PointOfInterest.from_dict(poi_dict) if poi_dict else None