summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2022-09-23 19:58:14 +0200
committerAlexandre Flament <alex@al-f.net>2022-09-23 20:52:55 +0200
commitd6446be38f3f858c09887a89c8fc490a3c300b95 (patch)
tree1b911cba1b96970455b115d1cc706db52d5613da
parent08b88597052dfdf17e947289d79510fdadad51e3 (diff)
downloadsearxng-d6446be38f3f858c09887a89c8fc490a3c300b95.tar.gz
searxng-d6446be38f3f858c09887a89c8fc490a3c300b95.zip
[mod] science category: various update of about PR 1705
-rw-r--r--docs/dev/engine_overview.rst10
-rw-r--r--searx/engines/crossref.py4
-rw-r--r--searx/engines/semantic_scholar.py3
-rw-r--r--searx/engines/springer.py3
-rw-r--r--searx/settings.yml3
-rw-r--r--searx/templates/simple/result_templates/paper.html4
-rwxr-xr-xsearx/webapp.py4
-rw-r--r--searx/webutils.py8
8 files changed, 20 insertions, 19 deletions
diff --git a/docs/dev/engine_overview.rst b/docs/dev/engine_overview.rst
index 731e2f86a..7d94b83f1 100644
--- a/docs/dev/engine_overview.rst
+++ b/docs/dev/engine_overview.rst
@@ -369,13 +369,9 @@ the parameter ``template`` must be set to the desired type.
- :py:class:`str`
- volume number
- * - start_page
- - :py:class:`int`
- - page number where the article starts
-
- * - end_page
- - :py:class:`int`
- - page number where the article ends
+ * - pages
+ - :py:class:`str`
+ - page range where the article is
* - number
- :py:class:`str`
diff --git a/searx/engines/crossref.py b/searx/engines/crossref.py
index d61318146..fbe2f0c2a 100644
--- a/searx/engines/crossref.py
+++ b/searx/engines/crossref.py
@@ -33,10 +33,10 @@ def response(resp):
if record_type == 'book-chapter':
title = record['container-title'][0]
if record['title'][0].lower().strip() != title.lower().strip():
- title = title + ' (' + record['title'][0] + ')'
+ title = html_to_text(title) + ' (' + html_to_text(record['title'][0]) + ')'
journal = None
else:
- title = record['title'][0]
+ title = html_to_text(record['title'][0])
journal = record.get('container-title', [None])[0]
url = record.get('resource', {}).get('primary', {}).get('URL') or record['URL']
authors = [author.get('given', '') + ' ' + author.get('family', '') for author in record.get('author', [])]
diff --git a/searx/engines/semantic_scholar.py b/searx/engines/semantic_scholar.py
index b2701c333..7a1b5b231 100644
--- a/searx/engines/semantic_scholar.py
+++ b/searx/engines/semantic_scholar.py
@@ -48,7 +48,6 @@ def request(query, params):
def response(resp):
res = loads(resp.text)
results = []
-
for result in res['results']:
url = result.get('primaryPaperLink', {}).get('url')
if not url and result.get('links'):
@@ -72,7 +71,7 @@ def response(resp):
# pick for the first alternate link, but not from the crawler
pdf_url = None
for doc in result.get('alternatePaperLinks', []):
- if doc['linkType'] != 'crawler':
+ if doc['linkType'] not in ('crawler', 'doi'):
pdf_url = doc['url']
break
diff --git a/searx/engines/springer.py b/searx/engines/springer.py
index 2711fa807..e5255b794 100644
--- a/searx/engines/springer.py
+++ b/searx/engines/springer.py
@@ -58,8 +58,7 @@ def response(resp):
'authors': authors,
'doi': record.get('doi'),
'journal': record.get('publicationName'),
- 'start_page': record.get('start_page'),
- 'end_page': record.get('end_page'),
+ 'pages': record.get('start_page') + '-' + record.get('end_page'),
'tags': tags,
'issn': [record.get('issn')],
'isbn': [record.get('isbn')],
diff --git a/searx/settings.yml b/searx/settings.yml
index ba38e694a..9e9b2f9e6 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -412,7 +412,8 @@ engines:
- name: crossref
engine: crossref
shortcut: cr
- timeout: 10
+ timeout: 30
+ disable: true
- name: yep
engine: json_engine
diff --git a/searx/templates/simple/result_templates/paper.html b/searx/templates/simple/result_templates/paper.html
index 3ede1b250..54704c866 100644
--- a/searx/templates/simple/result_templates/paper.html
+++ b/searx/templates/simple/result_templates/paper.html
@@ -13,8 +13,8 @@
.{{- result.number -}}
{%- endif -%}
{%- endif -%}
- {%- if result.start_page -%}
- &nbsp;{{- result.start_page -}} / {{- result.end_page -}}
+ {%- if result.pages -%}
+ &nbsp;{{- result.pages -}}
{%- endif -%}
</span>
</div>
diff --git a/searx/webapp.py b/searx/webapp.py
index e6bda42be..44500911a 100755
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -77,7 +77,7 @@ from searx.webutils import (
is_hmac_of,
is_flask_run_cmdline,
group_engines_in_tab,
- searxng_format_date,
+ searxng_l10n_timespan,
)
from searx.webadapter import (
get_search_query_from_webapp,
@@ -723,7 +723,7 @@ def search():
except ValueError:
result['publishedDate'] = None
else:
- result['publishedDate'] = searxng_format_date(result['publishedDate'])
+ result['publishedDate'] = searxng_l10n_timespan(result['publishedDate'])
# set result['open_group'] = True when the template changes from the previous result
# set result['close_group'] = True when the template changes on the next result
diff --git a/searx/webutils.py b/searx/webutils.py
index f084fe9d3..a5ed27c2c 100644
--- a/searx/webutils.py
+++ b/searx/webutils.py
@@ -141,7 +141,13 @@ def highlight_content(content, query):
return content
-def searxng_format_date(dt: datetime): # pylint: disable=invalid-name
+def searxng_l10n_timespan(dt: datetime) -> str: # pylint: disable=invalid-name
+ """Returns a human-readable and translated string indicating how long ago
+ a date was in the past / the time span of the date to the present.
+
+ On January 1st, midnight, the returned string only indicates how many years
+ ago the date was.
+ """
# TODO, check if timezone is calculated right # pylint: disable=fixme
d = dt.date()
t = dt.time()