]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge remote-tracking branch 'upstream/master'
authorSarah Hoffmann <lonvia@denofr.de>
Fri, 25 Oct 2024 13:52:55 +0000 (15:52 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Fri, 25 Oct 2024 13:52:55 +0000 (15:52 +0200)
docs/admin/Deployment-Python.md
src/nominatim_api/search/db_searches.py
src/nominatim_api/v1/classtypes.py
src/nominatim_db/clicmd/api.py
test/python/api/search/test_search_postcode.py

index 9275bab86d536f6fcba5e61dcc08eda84ac0e9e7..5932f4e6bb0f482b7940ee2ff411608421133d92 100644 (file)
@@ -81,7 +81,7 @@ Type=simple
 User=www-data
 Group=www-data
 WorkingDirectory=/srv/nominatim-project
-ExecStart=/srv/nominatim-venv/bin/gunicorn -b unix:/run/nominatim.sock -w 4 -k uvicorn.workers.UvicornWorker nominatim_api.server.falcon.server:run_wsgi
+ExecStart=/srv/nominatim-venv/bin/gunicorn -b unix:/run/nominatim.sock -w 4 -k uvicorn.workers.UvicornWorker "nominatim_api.server.falcon.server:run_wsgi()"
 ExecReload=/bin/kill -s HUP $MAINPID
 StandardOutput=append:/var/log/gunicorn-nominatim.log
 StandardError=inherit
index 35c063fc937701dc4086eb677e826c671a3b7ac4..d2202b2ccfb827d737f19af6aae574ecdb69e622 100644 (file)
@@ -616,6 +616,8 @@ class PostcodeSearch(AbstractSearch):
 
             for prow in await conn.execute(placex_sql, _details_to_bind_params(details)):
                 result = nres.create_from_placex_row(prow, nres.SearchResult)
+                if result is not None:
+                    result.bbox = Bbox.from_wkb(prow.bbox)
                 break
             else:
                 result = nres.create_from_postcode_row(row, nres.SearchResult)
index 66708593b331ec9bcab8a492925b0a03aa63c5a8..9e78c83b5a634eeb171c8396df6227403b8837df 100644 (file)
@@ -48,7 +48,12 @@ def bbox_from_result(result: Union[ReverseResult, SearchResult]) -> Bbox:
         around the centroid according to dimensions derived from the
         search rank.
     """
+    if result.category == ('place', 'postcode') and result.bbox is None:
+        return Bbox.from_point(result.centroid,
+                               0.05 - 0.012 * (result.rank_search - 21))
+
     if (result.osm_object and result.osm_object[0] == 'N') or result.bbox is None:
+
         extent = NODE_EXTENT.get(result.category, 0.00005)
         return Bbox.from_point(result.centroid, extent)
 
index dcbbb24bb4bb785c13a2389162a5c0fd1dfa96ab..000a603296d5f7c6e95e21e288d34a62ec3639c6 100644 (file)
@@ -12,6 +12,7 @@ import argparse
 import logging
 import json
 import sys
+import pprint
 from functools import reduce
 
 import nominatim_api as napi
@@ -113,24 +114,29 @@ def _list_formats(formatter: napi.FormatDispatcher, rtype: Type[Any]) -> int:
     for fmt in formatter.list_formats(rtype):
         print(fmt)
     print('debug')
+    print('raw')
 
     return 0
 
 
 def _print_output(formatter: napi.FormatDispatcher, result: Any,
                   fmt: str, options: Mapping[str, Any]) -> None:
-    output = formatter.format_result(result, fmt, options)
-    if formatter.get_content_type(fmt) == CONTENT_JSON:
-        # reformat the result, so it is pretty-printed
-        try:
-            json.dump(json.loads(output), sys.stdout, indent=4, ensure_ascii=False)
-        except json.decoder.JSONDecodeError as err:
-            # Catch the error here, so that data can be debugged,
-            # when people are developping custom result formatters.
-            LOG.fatal("Parsing json failed: %s\nUnformatted output:\n%s", err, output)
+
+    if fmt == 'raw':
+        pprint.pprint(result)
     else:
-        sys.stdout.write(output)
-    sys.stdout.write('\n')
+        output = formatter.format_result(result, fmt, options)
+        if formatter.get_content_type(fmt) == CONTENT_JSON:
+            # reformat the result, so it is pretty-printed
+            try:
+                json.dump(json.loads(output), sys.stdout, indent=4, ensure_ascii=False)
+            except json.decoder.JSONDecodeError as err:
+                # Catch the error here, so that data can be debugged,
+                # when people are developping custom result formatters.
+                LOG.fatal("Parsing json failed: %s\nUnformatted output:\n%s", err, output)
+        else:
+            sys.stdout.write(output)
+        sys.stdout.write('\n')
 
 
 class APISearch:
@@ -174,7 +180,7 @@ class APISearch:
         if args.list_formats:
             return _list_formats(formatter, napi.SearchResults)
 
-        if args.format == 'debug':
+        if args.format in ('debug', 'raw'):
             loglib.set_log_output('text')
         elif not formatter.supports_format(napi.SearchResults, args.format):
             raise UsageError(f"Unsupported format '{args.format}'. "
@@ -254,7 +260,7 @@ class APIReverse:
         if args.list_formats:
             return _list_formats(formatter, napi.ReverseResults)
 
-        if args.format == 'debug':
+        if args.format in ('debug', 'raw'):
             loglib.set_log_output('text')
         elif not formatter.supports_format(napi.ReverseResults, args.format):
             raise UsageError(f"Unsupported format '{args.format}'. "
@@ -320,7 +326,7 @@ class APILookup:
         if args.list_formats:
             return _list_formats(formatter, napi.ReverseResults)
 
-        if args.format == 'debug':
+        if args.format in ('debug', 'raw'):
             loglib.set_log_output('text')
         elif not formatter.supports_format(napi.ReverseResults, args.format):
             raise UsageError(f"Unsupported format '{args.format}'. "
@@ -402,7 +408,7 @@ class APIDetails:
         if args.list_formats:
             return _list_formats(formatter, napi.DetailedResult)
 
-        if args.format == 'debug':
+        if args.format in ('debug', 'raw'):
             loglib.set_log_output('text')
         elif not formatter.supports_format(napi.DetailedResult, args.format):
             raise UsageError(f"Unsupported format '{args.format}'. "
@@ -473,7 +479,7 @@ class APIStatus:
         if args.list_formats:
             return _list_formats(formatter, napi.StatusResult)
 
-        if args.format == 'debug':
+        if args.format in ('debug', 'raw'):
             loglib.set_log_output('text')
         elif not formatter.supports_format(napi.StatusResult, args.format):
             raise UsageError(f"Unsupported format '{args.format}'. "
index 633e07bcf8574ea1caaad73b277d0c3978a839ed..369e15045e0fd4ecf11721e67ee342cb661ddef3 100644 (file)
@@ -59,6 +59,19 @@ def test_postcode_with_country(apiobj, frontend):
     assert results[0].place_id == 101
 
 
+def test_postcode_area(apiobj, frontend):
+    apiobj.add_postcode(place_id=100, country_code='ch', postcode='12345')
+    apiobj.add_placex(place_id=200, country_code='ch', postcode='12345',
+                      osm_type='R', osm_id=34, class_='boundary', type='postal_code',
+                      geometry='POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')
+
+    results = run_search(apiobj, frontend, 0.3, ['12345'], [0.0])
+
+    assert len(results) == 1
+    assert results[0].place_id == 200
+    assert results[0].bbox.area == 1
+
+
 class TestPostcodeSearchWithAddress:
 
     @pytest.fixture(autouse=True)