]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/python/api/search/test_search_places.py
enable connection pools for sqlite
[nominatim.git] / test / python / api / search / test_search_places.py
index df369b81e1d36f77c65d0c66ea0fb9182a5051e3..8a363e97735b585aee1372ea6d87d05a3a12a17e 100644 (file)
@@ -7,6 +7,8 @@
 """
 Tests for running the generic place searcher.
 """
+import json
+
 import pytest
 
 import nominatim.api as napi
@@ -130,23 +132,48 @@ class TestNameOnlySearches:
         assert geom.name.lower() in results[0].geometry
 
 
+    @pytest.mark.parametrize('factor,npoints', [(0.0, 3), (1.0, 2)])
+    def test_return_simplified_geometry(self, apiobj, factor, npoints):
+        apiobj.add_placex(place_id=333, country_code='us',
+                          centroid=(9.0, 9.0),
+                          geometry='LINESTRING(8.9 9.0, 9.0 9.0, 9.1 9.0)')
+        apiobj.add_search_name(333, names=[55], country_code='us',
+                               centroid=(5.6, 4.3))
+
+        lookup = FieldLookup('name_vector', [55], 'lookup_all')
+        ranking = FieldRanking('name_vector', 0.9, [RankedTokens(0.0, [21])])
+
+        results = run_search(apiobj, 0.1, [lookup], [ranking],
+                             details=SearchDetails(geometry_output=napi.GeometryFormat.GEOJSON,
+                                                   geometry_simplification=factor))
+
+        assert len(results) == 1
+        result = results[0]
+        geom = json.loads(result.geometry['geojson'])
+
+        assert result.place_id == 333
+        assert len(geom['coordinates']) == npoints
+
+
     @pytest.mark.parametrize('viewbox', ['5.0,4.0,6.0,5.0', '5.7,4.0,6.0,5.0'])
-    def test_prefer_viewbox(self, apiobj, viewbox):
+    @pytest.mark.parametrize('wcount,rids', [(2, [100, 101]), (20000, [100])])
+    def test_prefer_viewbox(self, apiobj, viewbox, wcount, rids):
         lookup = FieldLookup('name_vector', [1, 2], 'lookup_all')
-        ranking = FieldRanking('name_vector', 0.9, [RankedTokens(0.0, [21])])
+        ranking = FieldRanking('name_vector', 0.2, [RankedTokens(0.0, [21])])
 
         results = run_search(apiobj, 0.1, [lookup], [ranking])
         assert [r.place_id for r in results] == [101, 100]
 
-        results = run_search(apiobj, 0.1, [lookup], [ranking],
+        results = run_search(apiobj, 0.1, [lookup], [ranking], count=wcount,
                              details=SearchDetails.from_kwargs({'viewbox': viewbox}))
-        assert [r.place_id for r in results] == [100, 101]
+        assert [r.place_id for r in results] == rids
 
 
-    def test_force_viewbox(self, apiobj):
+    @pytest.mark.parametrize('viewbox', ['5.0,4.0,6.0,5.0', '5.55,4.27,5.62,4.31'])
+    def test_force_viewbox(self, apiobj, viewbox):
         lookup = FieldLookup('name_vector', [1, 2], 'lookup_all')
 
-        details=SearchDetails.from_kwargs({'viewbox': '5.0,4.0,6.0,5.0',
+        details=SearchDetails.from_kwargs({'viewbox': viewbox,
                                            'bounded_viewbox': True})
 
         results = run_search(apiobj, 0.1, [lookup], [], details=details)
@@ -166,11 +193,12 @@ class TestNameOnlySearches:
         assert [r.place_id for r in results] == [100, 101]
 
 
-    def test_force_near(self, apiobj):
+    @pytest.mark.parametrize('radius', [0.09, 0.11])
+    def test_force_near(self, apiobj, radius):
         lookup = FieldLookup('name_vector', [1, 2], 'lookup_all')
 
         details=SearchDetails.from_kwargs({'near': '5.6,4.3',
-                                           'near_radius': 0.11})
+                                           'near_radius': radius})
 
         results = run_search(apiobj, 0.1, [lookup], [], details=details)
 
@@ -253,6 +281,37 @@ class TestStreetWithHousenumber:
         assert [r.place_id for r in results] == [2, 92, 2000]
 
 
+    def test_lookup_only_house_qualifier(self, apiobj):
+        lookup = FieldLookup('name_vector', [1,2], 'lookup_all')
+        ranking = FieldRanking('name_vector', 0.3, [RankedTokens(0.0, [10])])
+
+        results = run_search(apiobj, 0.1, [lookup], [ranking], hnrs=['22'],
+                             quals=[('place', 'house')])
+
+        assert [r.place_id for r in results] == [2, 92]
+
+
+    def test_lookup_only_street_qualifier(self, apiobj):
+        lookup = FieldLookup('name_vector', [1,2], 'lookup_all')
+        ranking = FieldRanking('name_vector', 0.3, [RankedTokens(0.0, [10])])
+
+        results = run_search(apiobj, 0.1, [lookup], [ranking], hnrs=['22'],
+                             quals=[('highway', 'residential')])
+
+        assert [r.place_id for r in results] == [1000, 2000]
+
+
+    @pytest.mark.parametrize('rank,found', [(26, True), (27, False), (30, False)])
+    def test_lookup_min_rank(self, apiobj, rank, found):
+        lookup = FieldLookup('name_vector', [1,2], 'lookup_all')
+        ranking = FieldRanking('name_vector', 0.3, [RankedTokens(0.0, [10])])
+
+        results = run_search(apiobj, 0.1, [lookup], [ranking], hnrs=['22'],
+                             details=SearchDetails(min_rank=rank))
+
+        assert [r.place_id for r in results] == ([2, 92, 1000, 2000] if found else [2, 92])
+
+
     @pytest.mark.parametrize('geom', [napi.GeometryFormat.GEOJSON,
                                       napi.GeometryFormat.KML,
                                       napi.GeometryFormat.SVG,
@@ -267,6 +326,54 @@ class TestStreetWithHousenumber:
         assert all(geom.name.lower() in r.geometry for r in results)
 
 
+def test_very_large_housenumber(apiobj):
+    apiobj.add_placex(place_id=93, class_='place', type='house',
+                      parent_place_id=2000,
+                      housenumber='2467463524544', country_code='pt')
+    apiobj.add_placex(place_id=2000, class_='highway', type='residential',
+                      rank_search=26, rank_address=26,
+                      country_code='pt')
+    apiobj.add_search_name(2000, names=[1,2],
+                           search_rank=26, address_rank=26,
+                           country_code='pt')
+
+    lookup = FieldLookup('name_vector', [1, 2], 'lookup_all')
+
+    results = run_search(apiobj, 0.1, [lookup], [], hnrs=['2467463524544'],
+                         details=SearchDetails())
+
+    assert results
+    assert [r.place_id for r in results] == [93, 2000]
+
+
+@pytest.mark.parametrize('wcount,rids', [(2, [990, 991]), (30000, [990])])
+def test_name_and_postcode(apiobj, wcount, rids):
+    apiobj.add_placex(place_id=990, class_='highway', type='service',
+                      rank_search=27, rank_address=27,
+                      postcode='11225',
+                      centroid=(10.0, 10.0),
+                      geometry='LINESTRING(9.995 10, 10.005 10)')
+    apiobj.add_search_name(990, names=[111], centroid=(10.0, 10.0),
+                           search_rank=27, address_rank=27)
+    apiobj.add_placex(place_id=991, class_='highway', type='service',
+                      rank_search=27, rank_address=27,
+                      postcode='11221',
+                      centroid=(10.1, 10.1),
+                      geometry='LINESTRING(9.995 10.1, 10.005 10.1)')
+    apiobj.add_search_name(991, names=[111], centroid=(10.1, 10.1),
+                           search_rank=27, address_rank=27)
+    apiobj.add_postcode(place_id=100, country_code='ch', postcode='11225',
+                        geometry='POINT(10 10)')
+
+    lookup = FieldLookup('name_vector', [111], 'lookup_all')
+
+    results = run_search(apiobj, 0.1, [lookup], [], pcs=['11225'], count=wcount,
+                         details=SearchDetails())
+
+    assert results
+    assert [r.place_id for r in results] == rids
+
+
 class TestInterpolations:
 
     @pytest.fixture(autouse=True)
@@ -298,6 +405,21 @@ class TestInterpolations:
         assert [r.place_id for r in results] == res + [990]
 
 
+    @pytest.mark.parametrize('geom', [napi.GeometryFormat.GEOJSON,
+                                      napi.GeometryFormat.KML,
+                                      napi.GeometryFormat.SVG,
+                                      napi.GeometryFormat.TEXT])
+    def test_osmline_with_geometries(self, apiobj, geom):
+        lookup = FieldLookup('name_vector', [111], 'lookup_all')
+
+        results = run_search(apiobj, 0.1, [lookup], [], hnrs=['21'],
+                             details=SearchDetails(geometry_output=geom))
+
+        assert results[0].place_id == 992
+        assert geom.name.lower() in results[0].geometry
+
+
+
 class TestTiger:
 
     @pytest.fixture(autouse=True)
@@ -331,6 +453,20 @@ class TestTiger:
         assert [r.place_id for r in results] == res + [990]
 
 
+    @pytest.mark.parametrize('geom', [napi.GeometryFormat.GEOJSON,
+                                      napi.GeometryFormat.KML,
+                                      napi.GeometryFormat.SVG,
+                                      napi.GeometryFormat.TEXT])
+    def test_tiger_with_geometries(self, apiobj, geom):
+        lookup = FieldLookup('name_vector', [111], 'lookup_all')
+
+        results = run_search(apiobj, 0.1, [lookup], [], hnrs=['21'],
+                             details=SearchDetails(geometry_output=geom))
+
+        assert results[0].place_id == 992
+        assert geom.name.lower() in results[0].geometry
+
+
 class TestLayersRank30:
 
     @pytest.fixture(autouse=True)