mirror of
https://github.com/searxng/searxng.git
synced 2026-05-29 14:14:13 +02:00
[unbload] drop meaningless field `number_of_results_xpath` from results (#6130)
In the result-list, the ``number_of_results`` indicate the number of hits in the Index, they do not indicate how many results are in the answer. In the past, search engines such as google or ddg had an indication on the first page of a search term of how many hits there were for this term in total in their index. This info was added up in SearXNG and delivered under ``number_of_results``. Nowadays the search engines no longer indicate how many hits there are in the index and so this field in SearXNG is also superfluous. - https://github.com/searxng/searxng/issues/2457#issuecomment-2566181574 - https://github.com/searxng/searxng/issues/2987 - https://github.com/searxng/searxng/issues/5034 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
@@ -39,7 +39,6 @@ url_xpath = './h4/a/@href'
|
||||
title_xpath = './h4/a[1]'
|
||||
content_xpath = './/p[1]'
|
||||
correction_xpath = '//*[@id="didYouMean"]//a'
|
||||
number_of_results_xpath = '//*[@id="totalResults"]'
|
||||
name_token_xpath = '//form[@id="searchForm"]/input[@type="hidden"]/@name'
|
||||
value_token_xpath = '//form[@id="searchForm"]/input[@type="hidden"]/@value'
|
||||
|
||||
@@ -107,14 +106,6 @@ def response(resp):
|
||||
for correction in eval_xpath_list(dom, correction_xpath):
|
||||
results.append({'correction': extract_text(correction)})
|
||||
|
||||
# get number of results
|
||||
number_of_results = eval_xpath(dom, number_of_results_xpath)
|
||||
if number_of_results:
|
||||
try:
|
||||
results.append({'number_of_results': int(extract_text(number_of_results))})
|
||||
except: # pylint: disable=bare-except
|
||||
pass
|
||||
|
||||
# Update the tokens to the newest ones
|
||||
token_str = _get_tokens(dom)
|
||||
CACHE.set('ahmia-tokens', token_str, expire=60 * 60)
|
||||
|
||||
@@ -13,7 +13,6 @@ implementations are shared by other engines:
|
||||
"""
|
||||
|
||||
import base64
|
||||
import re
|
||||
import typing as t
|
||||
from urllib.parse import parse_qs, urlencode, urlparse
|
||||
|
||||
@@ -159,12 +158,6 @@ def response(resp: "SXNG_Response") -> list[dict[str, t.Any]]:
|
||||
|
||||
results.append({"url": href, "title": title, "content": content})
|
||||
|
||||
if results:
|
||||
result_len_container = "".join(eval_xpath(dom, '//span[@class="sb_count"]//text()'))
|
||||
result_len_container = re.sub(r"[^0-9]", "", result_len_container)
|
||||
if result_len_container:
|
||||
results.append({"number_of_results": int(result_len_container)})
|
||||
|
||||
return results
|
||||
|
||||
|
||||
|
||||
@@ -109,7 +109,6 @@ def search(query: str, params: "RequestParams") -> EngineResults:
|
||||
kvmap=kvmap,
|
||||
)
|
||||
)
|
||||
res.add(res.types.LegacyResult(number_of_results=count))
|
||||
|
||||
# cache counter value for 20sec
|
||||
CACHE.set("count", count, expire=20)
|
||||
|
||||
@@ -176,6 +176,4 @@ def response(resp):
|
||||
|
||||
results.append(result)
|
||||
|
||||
results.append({'number_of_results': len(json_data['topics'])})
|
||||
|
||||
return results
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""Duden"""
|
||||
|
||||
import re
|
||||
from urllib.parse import quote, urljoin
|
||||
from lxml import html
|
||||
from searx.utils import extract_text, eval_xpath, eval_xpath_list, eval_xpath_getindex
|
||||
@@ -51,13 +50,6 @@ def response(resp):
|
||||
|
||||
dom = html.fromstring(resp.text)
|
||||
|
||||
number_of_results_element = eval_xpath_getindex(
|
||||
dom, '//a[@class="active" and contains(@href,"/suchen/dudenonline")]/span/text()', 0, default=None
|
||||
)
|
||||
if number_of_results_element is not None:
|
||||
number_of_results_string = re.sub('[^0-9]', '', number_of_results_element)
|
||||
results.append({'number_of_results': int(number_of_results_string)})
|
||||
|
||||
for result in eval_xpath_list(dom, '//section[not(contains(@class, "essay"))]'):
|
||||
url = eval_xpath_getindex(result, './/h2/a', 0).get('href')
|
||||
url = urljoin(base_url, url)
|
||||
|
||||
@@ -93,7 +93,6 @@ def search(query, params) -> EngineResults:
|
||||
|
||||
query = _client.find({key: q}).skip((params['pageno'] - 1) * results_per_page).limit(results_per_page)
|
||||
|
||||
res.add(res.types.LegacyResult(number_of_results=query.count()))
|
||||
for row in query:
|
||||
del row['_id']
|
||||
kvmap = {str(k): str(v) for k, v in row.items()}
|
||||
|
||||
@@ -54,6 +54,4 @@ def response(resp):
|
||||
|
||||
results.extend({'suggestion': s} for s in response_json['suggestions'])
|
||||
|
||||
results.append({'number_of_results': response_json['number_of_results']})
|
||||
|
||||
return results
|
||||
|
||||
@@ -211,8 +211,4 @@ def response(resp) -> EngineResults:
|
||||
|
||||
# append number of results
|
||||
|
||||
number_of_results = json_data.get('num_matches')
|
||||
if number_of_results:
|
||||
results.append({'number_of_results': number_of_results})
|
||||
|
||||
return results
|
||||
|
||||
Reference in New Issue
Block a user