Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
my-spot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
e
cloud
my-spot
Commits
2c6531b2
Commit
2c6531b2
authored
Jun 09, 2020
by
Adam Tauber
2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[enh] add routing directions to osm search - closes #254
parent
785f0938
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
12 deletions
+38
-12
searx/engines/openstreetmap.py
searx/engines/openstreetmap.py
+14
-0
searx/plugins/self_info.py
searx/plugins/self_info.py
+2
-4
searx/results.py
searx/results.py
+2
-2
searx/templates/legacy/results.html
searx/templates/legacy/results.html
+6
-2
searx/templates/oscar/results.html
searx/templates/oscar/results.html
+6
-2
searx/templates/simple/results.html
searx/templates/simple/results.html
+8
-2
No files found.
searx/engines/openstreetmap.py
View file @
2c6531b2
...
@@ -10,7 +10,9 @@
...
@@ -10,7 +10,9 @@
@parse url, title
@parse url, title
"""
"""
import
re
from
json
import
loads
from
json
import
loads
from
flask_babel
import
gettext
# engine dependent config
# engine dependent config
categories
=
[
'map'
]
categories
=
[
'map'
]
...
@@ -21,10 +23,15 @@ base_url = 'https://nominatim.openstreetmap.org/'
...
@@ -21,10 +23,15 @@ base_url = 'https://nominatim.openstreetmap.org/'
search_string
=
'search/{query}?format=json&polygon_geojson=1&addressdetails=1'
search_string
=
'search/{query}?format=json&polygon_geojson=1&addressdetails=1'
result_base_url
=
'https://openstreetmap.org/{osm_type}/{osm_id}'
result_base_url
=
'https://openstreetmap.org/{osm_type}/{osm_id}'
route_url
=
'https://graphhopper.com/maps/?point={}&point={}&locale=en-US&vehicle=car&weighting=fastest&turn_costs=true&use_miles=false&layer=Omniscale'
route_re
=
re
.
compile
(
'(?:from )?(.+) to (.+)'
)
# do search-request
# do search-request
def
request
(
query
,
params
):
def
request
(
query
,
params
):
params
[
'url'
]
=
base_url
+
search_string
.
format
(
query
=
query
.
decode
(
'utf-8'
))
params
[
'url'
]
=
base_url
+
search_string
.
format
(
query
=
query
.
decode
(
'utf-8'
))
params
[
'route'
]
=
route_re
.
match
(
query
.
decode
(
'utf-8'
))
return
params
return
params
...
@@ -34,6 +41,13 @@ def response(resp):
...
@@ -34,6 +41,13 @@ def response(resp):
results
=
[]
results
=
[]
json
=
loads
(
resp
.
text
)
json
=
loads
(
resp
.
text
)
if
resp
.
search_params
[
'route'
]:
results
.
append
({
'answer'
:
gettext
(
'Get directions'
),
'url'
:
route_url
.
format
(
*
resp
.
search_params
[
'route'
].
groups
()),
})
# parse results
# parse results
for
r
in
json
:
for
r
in
json
:
if
'display_name'
not
in
r
:
if
'display_name'
not
in
r
:
...
...
searx/plugins/self_info.py
View file @
2c6531b2
...
@@ -37,10 +37,8 @@ def post_search(request, search):
...
@@ -37,10 +37,8 @@ def post_search(request, search):
ip
=
x_forwarded_for
[
0
]
ip
=
x_forwarded_for
[
0
]
else
:
else
:
ip
=
request
.
remote_addr
ip
=
request
.
remote_addr
search
.
result_container
.
answers
.
clear
()
search
.
result_container
.
answers
[
'ip'
]
=
{
'answer'
:
ip
}
search
.
result_container
.
answers
.
add
(
ip
)
elif
p
.
match
(
search
.
search_query
.
query
):
elif
p
.
match
(
search
.
search_query
.
query
):
ua
=
request
.
user_agent
ua
=
request
.
user_agent
search
.
result_container
.
answers
.
clear
()
search
.
result_container
.
answers
[
'user-agent'
]
=
{
'answer'
:
ua
}
search
.
result_container
.
answers
.
add
(
ua
)
return
True
return
True
searx/results.py
View file @
2c6531b2
...
@@ -131,7 +131,7 @@ class ResultContainer(object):
...
@@ -131,7 +131,7 @@ class ResultContainer(object):
self
.
_merged_results
=
[]
self
.
_merged_results
=
[]
self
.
infoboxes
=
[]
self
.
infoboxes
=
[]
self
.
suggestions
=
set
()
self
.
suggestions
=
set
()
self
.
answers
=
set
()
self
.
answers
=
{}
self
.
corrections
=
set
()
self
.
corrections
=
set
()
self
.
_number_of_results
=
[]
self
.
_number_of_results
=
[]
self
.
_ordered
=
False
self
.
_ordered
=
False
...
@@ -146,7 +146,7 @@ class ResultContainer(object):
...
@@ -146,7 +146,7 @@ class ResultContainer(object):
self
.
suggestions
.
add
(
result
[
'suggestion'
])
self
.
suggestions
.
add
(
result
[
'suggestion'
])
results
.
remove
(
result
)
results
.
remove
(
result
)
elif
'answer'
in
result
:
elif
'answer'
in
result
:
self
.
answers
.
add
(
result
[
'answer'
])
self
.
answers
[
result
[
'answer'
]]
=
result
results
.
remove
(
result
)
results
.
remove
(
result
)
elif
'correction'
in
result
:
elif
'correction'
in
result
:
self
.
corrections
.
add
(
result
[
'correction'
])
self
.
corrections
.
add
(
result
[
'correction'
])
...
...
searx/templates/legacy/results.html
View file @
2c6531b2
...
@@ -33,8 +33,12 @@
...
@@ -33,8 +33,12 @@
{% if answers %}
{% if answers %}
<div
id=
"answers"
><span>
{{ _('Answers') }}
</span>
<div
id=
"answers"
><span>
{{ _('Answers') }}
</span>
{% for answer in answers %}
{% for answer in answers.values() %}
<span>
{{ answer }}
</span>
{% if answer.url %}
<a
href=
"{{ answer.url }}"
>
{{ answer.answer }}
</a>
{% else %}
<span>
{{ answer.answer }}
</span>
{% endif %}
{% endfor %}
{% endfor %}
</div>
</div>
{% endif %}
{% endif %}
...
...
searx/templates/oscar/results.html
View file @
2c6531b2
...
@@ -94,9 +94,13 @@
...
@@ -94,9 +94,13 @@
{%- endif %}
{%- endif %}
{% if answers -%}
{% if answers -%}
{%- for answer in answers %}
{%- for answer in answers
.values()
%}
<div
class=
"result well"
>
<div
class=
"result well"
>
<span>
{{ answer }}
</span>
{% if answer.url %}
<a
href=
"{{ answer.url }}"
>
{{ answer.answer }}
</a>
{% else %}
<span>
{{ answer.answer }}
</span>
{% endif %}
</div>
</div>
{%- endfor %}
{%- endfor %}
{%- endif %}
{%- endif %}
...
...
searx/templates/simple/results.html
View file @
2c6531b2
...
@@ -15,8 +15,14 @@
...
@@ -15,8 +15,14 @@
<div
id=
"results"
class=
"{{ only_template }}"
>
<div
id=
"results"
class=
"{{ only_template }}"
>
{% if answers -%}
{% if answers -%}
<div
id=
"answers"
><h4
class=
"title"
>
{{ _('Answers') }} :
</h4>
<div
id=
"answers"
><h4
class=
"title"
>
{{ _('Answers') }} :
</h4>
{%- for answer in answers -%}
{%- for answer in answers.values() -%}
<div
class=
"answer"
>
{{- answer -}}
</div>
<div
class=
"answer"
>
{% if answer.url %}
<a
href=
"{{ answer.url }}"
>
{{ answer.answer }}
</a>
{% else %}
<span>
{{ answer.answer }}
</span>
{% endif %}
</div>
{%- endfor -%}
{%- endfor -%}
</div>
</div>
{%- endif %}
{%- endif %}
...
...
Nicolas Gelot
@nicofonk
mentioned in commit
eae34816
·
Jun 25, 2020
mentioned in commit
eae34816
mentioned in commit eae34816881b97c2be8b24630244a27ec0a09c6d
Toggle commit list
Nicolas Gelot
@nicofonk
mentioned in commit
6fb5c6aa
·
Jun 25, 2020
mentioned in commit
6fb5c6aa
mentioned in commit 6fb5c6aad920b31599292bdffa1dd2ab2f7d1adc
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment