on master help sign in
[enh] template_oscar: show addressdata if possible
c38917bThomas Pointhuber
searx/engines/openstreetmap.py+26−1
@@ -15,7 +15,7 @@ categories = ['map']
15paging = False
15paging = False
16
16
17# search-url
17# search-url
18−url = 'https://nominatim.openstreetmap.org/search/{query}?format=json&polygon_geojson=1'
18+url = 'https://nominatim.openstreetmap.org/search/{query}?format=json&polygon_geojson=1&addressdetails=1'
19
19
20result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'
20result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}'
21
21
@@ -47,6 +47,30 @@ def response(resp):
47 geojson = {u'type':u'Point',
47 geojson = {u'type':u'Point',
48 u'coordinates':[r['lon'],r['lat']]}
48 u'coordinates':[r['lon'],r['lat']]}
49
49
50+ address_raw = r.get('address')
51+ address = {}
52+
53+ # get name
54+ if r['class'] == 'amenity' or\
55+ r['class'] == 'shop' or\
56+ r['class'] == 'tourism' or\
57+ r['class'] == 'leisure':
58+ if address_raw.get('address29'):
59+ address = {'name':address_raw.get('address29')}
60+ else:
61+ address = {'name':address_raw.get(r['type'])}
62+
63+ # add rest of adressdata, if something is already found
64+ if address.get('name'):
65+ address.update({'house_number':address_raw.get('house_number'),
66+ 'road':address_raw.get('road'),
67+ 'locality':address_raw.get('town', address_raw.get('village')),
68+ 'postcode':address_raw.get('postcode'),
69+ 'country':address_raw.get('country'),
70+ 'country_code':address_raw.get('country_code')})
71+ else:
72+ address = None
73+
50 # append result
74 # append result
51 results.append({'template': 'map.html',
75 results.append({'template': 'map.html',
52 'title': title,
76 'title': title,
@@ -55,6 +79,7 @@ def response(resp):
55 'latitude': r['lat'],
79 'latitude': r['lat'],
56 'boundingbox': r['boundingbox'],
80 'boundingbox': r['boundingbox'],
57 'geojson': geojson,
81 'geojson': geojson,
82+ 'address': address,
58 'url': url})
83 'url': url})
59
84
60 # return results
85 # return results
searx/static/oscar/css/oscar.min.css+1−1
@@ -5,7 +5,7 @@ input[type=checkbox]:checked~.label_hide_if_checked{display:none}
5input[type=checkbox]:not(:checked)~.label_hide_if_not_checked{display:none}
5input[type=checkbox]:not(:checked)~.label_hide_if_not_checked{display:none}
6.result_header{margin-bottom:5px;margin-top:20px}.result_header .favicon{margin-bottom:-3px}
6.result_header{margin-bottom:5px;margin-top:20px}.result_header .favicon{margin-bottom:-3px}
7.result_header a{vertical-align:bottom}.result_header a .highlight{font-weight:bold}
7.result_header a{vertical-align:bottom}.result_header a .highlight{font-weight:bold}
8−.result-content .highlight{font-weight:bold}
8+.result-content{margin-top:5px}.result-content .highlight{font-weight:bold}
9.result-default{clear:both}
9.result-default{clear:both}
10.result-images{float:left !important}
10.result-images{float:left !important}
11.img-thumbnail{margin:5px;max-height:128px;min-height:128px}
11.img-thumbnail{margin:5px;max-height:128px;min-height:128px}
searx/static/oscar/less/oscar/results.less+2
@@ -17,6 +17,8 @@
17}
17}
18
18
19.result-content {
19.result-content {
20+ margin-top: 5px;
21+
20 .highlight {
22 .highlight {
21 font-weight:bold;
23 font-weight:bold;
22 }
24 }
searx/templates/oscar/result_templates/map.html+23−1
@@ -7,7 +7,29 @@
7{% if (result.latitude and result.longitude) or result.boundingbox %}
7{% if (result.latitude and result.longitude) or result.boundingbox %}
8 <small> &bull; <a class="text-info btn-collapse collapsed searx_init_map cursor-pointer" data-toggle="collapse" data-target="#result-map-{{ index }}" data-leaflet-target="osm-map-{{ index }}" data-map-lon="{{ result.longitude }}" data-map-lat="{{ result.latitude }}" {% if result.boundingbox %}data-map-boundingbox='{{ result.boundingbox|tojson|safe }}'{% endif %} {% if result.geojson %}data-map-geojson='{{ result.geojson|tojson|safe }}'{% endif %} data-btn-text-collapsed="{{ _('show map') }}" data-btn-text-not-collapsed="{{ _('hide map') }}">{{ icon('globe') }} {{ _('show map') }}</a></small>
8 <small> &bull; <a class="text-info btn-collapse collapsed searx_init_map cursor-pointer" data-toggle="collapse" data-target="#result-map-{{ index }}" data-leaflet-target="osm-map-{{ index }}" data-map-lon="{{ result.longitude }}" data-map-lat="{{ result.latitude }}" {% if result.boundingbox %}data-map-boundingbox='{{ result.boundingbox|tojson|safe }}'{% endif %} {% if result.geojson %}data-map-geojson='{{ result.geojson|tojson|safe }}'{% endif %} data-btn-text-collapsed="{{ _('show map') }}" data-btn-text-not-collapsed="{{ _('hide map') }}">{{ icon('globe') }} {{ _('show map') }}</a></small>
9{% endif %}
9{% endif %}
10−
10+
11+{% if result.address %}
12+<p class="result-content result-adress" itemscope itemtype="http://schema.org/PostalAddress">
13+ {% if result.address.name %}
14+ <strong itemprop="name">{{ result.address.name }}</strong><br/>
15+ {% endif %}
16+ {% if result.address.road %}
17+ <span itemprop="streetAddress">
18+ {% if result.address.house_number %}{{ result.address.house_number }}, {% endif %}
19+ {{ result.address.road }}
20+ </span><br/>
21+ {% endif %}
22+ {% if result.address.locality %}
23+ <span itemprop="addressLocality">{{ result.address.locality }}</span>,
24+ {% if result.address.postcode %} <span itemprop="postalCode">{{ result.address.postcode }}</span>{% endif %}
25+ <br/>
26+ {% endif %}
27+ {% if result.address.country %}
28+ <span itemprop="addressCountry">{{ result.address.country }}</span>
29+ {% endif %}
30+</p><div class="clearfix"></div>
31+{% endif %}
32+
11{% if result.content %}<p class="result-content">{{ result.content|safe }}</p>{% endif %}
33{% if result.content %}<p class="result-content">{{ result.content|safe }}</p>{% endif %}
12
34
13{% if (result.latitude and result.longitude) or result.boundingbox %}
35{% if (result.latitude and result.longitude) or result.boundingbox %}