Compare commits

...

6 Commits

Author SHA1 Message Date
Grant Lanham Jr c90654aa61
Merge 81f0cb01e8 into dfaf5868e2 2024-11-12 07:36:38 +01:00
Leo Liu dfaf5868e2 [fix] settings.yml - enabled_plugins: document to reflect default settings
Remove 'Autodetect search language', which is no longer valid, from settings,
and add 'Unit converter plugin', which is now default enabled, to settings.
2024-11-10 16:09:41 +01:00
Leo Liu b173f3a8b9 Fix scheduler.lua 2024-11-10 15:53:58 +01:00
dependabot[bot] 2fbf15eccb [upd] pypi: Bump typer-slim from 0.12.5 to 0.13.0
Bumps [typer-slim](https://github.com/fastapi/typer) from 0.12.5 to 0.13.0.
- [Release notes](https://github.com/fastapi/typer/releases)
- [Changelog](https://github.com/fastapi/typer/blob/master/docs/release-notes.md)
- [Commits](https://github.com/fastapi/typer/compare/0.12.5...0.13.0)

---
updated-dependencies:
- dependency-name: typer-slim
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-11-08 08:51:43 +01:00
searxng-bot 08c5f258d8 [l10n] update translations from Weblate
8d90a7e6d - 2024-11-06 - sahussawud <sahussawud@users.noreply.translate.codeberg.org>
41ee8bb0d - 2024-11-02 - laaknor <laaknor@users.noreply.translate.codeberg.org>
c1a30afab - 2024-11-02 - return42 <return42@users.noreply.translate.codeberg.org>
627ab7a8e - 2024-11-01 - zarlin <zarlin@users.noreply.translate.codeberg.org>
2024-11-08 08:45:07 +01:00
Grant Lanham 81f0cb01e8 Remove RawTextQuery.changeQuery in favor of getNewFullQuery
Also includes the following:
- Introduce typing in RawTextQuery
- Remove an outdated description based on the change
- Refactor setting the autocomplete_location, its more clear to set the
variable in the construct instead of within the method
- Update unit tests to reflect the new method

rephrasing

format

undo change
2024-06-16 14:18:31 -04:00
15 changed files with 73 additions and 61 deletions

View File

@ -18,4 +18,4 @@ fasttext-predict==0.9.2.2
tomli==2.0.2; python_version < '3.11' tomli==2.0.2; python_version < '3.11'
msgspec==0.18.6 msgspec==0.18.6
eval_type_backport; python_version < '3.9' eval_type_backport; python_version < '3.9'
typer-slim==0.12.5 typer-slim==0.13.0

View File

@ -1,10 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
# pylint: disable=invalid-name, missing-module-docstring, missing-class-docstring # pylint: disable=invalid-name, missing-module-docstring, missing-class-docstring
from __future__ import annotations
from __future__ import annotations from __future__ import annotations
from abc import abstractmethod, ABC from abc import abstractmethod, ABC
import re import re
from searx import settings from searx import settings
from searx.sxng_locales import sxng_locales from searx.sxng_locales import sxng_locales
from searx.engines import categories, engines, engine_shortcuts from searx.engines import categories, engines, engine_shortcuts
@ -272,16 +272,19 @@ class RawTextQuery:
self.specific = False self.specific = False
self.autocomplete_list = [] self.autocomplete_list = []
# internal properties # internal properties
self.query_parts = [] # use self.getFullQuery() self.query_parts = [] # use self.getFullQuery() or self.getNewFullQuery(query)
self.user_query_parts = [] # use self.getQuery() self.user_query_parts = [] # use self.getQuery()
self.autocomplete_location = None
self.redirect_to_first_result = False self.redirect_to_first_result = False
self._parse_query() self.autocomplete_location = self._parse_query()
def _parse_query(self): def _parse_query(self):
""" """
parse self.query, if tags are set, which parse self.query, if tags are set, which
change the search engine or search-language change the search engine or search-language
Returns a tuple:
[0] The query parts as a list
[1] The indexor into the above list
""" """
# split query, including whitespaces # split query, including whitespaces
@ -307,28 +310,33 @@ class RawTextQuery:
qlist.append(query_part) qlist.append(query_part)
last_index_location = (qlist, len(qlist) - 1) last_index_location = (qlist, len(qlist) - 1)
self.autocomplete_location = last_index_location return last_index_location
def get_autocomplete_full_query(self, text): def get_autocomplete_full_query(self, text: str) -> str:
assert self.autocomplete_location is not None
qlist, position = self.autocomplete_location qlist, position = self.autocomplete_location
qlist[position] = text qlist[position] = text
return self.getFullQuery() return self.getFullQuery()
def changeQuery(self, query): def getNewFullQuery(self, query: str):
self.user_query_parts = query.strip().split() """
self.query = self.getFullQuery() Generate a new FullQuery based on the input query rather than the internal
self.autocomplete_location = (self.user_query_parts, len(self.user_query_parts) - 1) user_query_parts
self.autocomplete_list = [] """
return self return RawTextQuery._getFullQuery(self.query_parts, query.strip())
def getQuery(self): def getQuery(self) -> str:
return ' '.join(self.user_query_parts) return ' '.join(self.user_query_parts)
def getFullQuery(self): def getFullQuery(self) -> str:
""" """
get full query including whitespaces Get full query including whitespaces
""" """
return '{0} {1}'.format(' '.join(self.query_parts), self.getQuery()).strip() return RawTextQuery._getFullQuery(self.query_parts, self.getQuery())
@staticmethod
def _getFullQuery(query_parts: list[str], query: str) -> str:
return '{0} {1}'.format(' '.join(query_parts), query).strip()
def __str__(self): def __str__(self):
return self.getFullQuery() return self.getFullQuery()

View File

@ -20,7 +20,7 @@ if (next_call_ts == false or next_call_ts == nil) then
-- 2/ the next call is a random time between start_after_from and start_after_to -- 2/ the next call is a random time between start_after_from and start_after_to
local initial_delay = math.random(start_after_from, start_after_to) local initial_delay = math.random(start_after_from, start_after_to)
redis.call('SET', redis_key, now + initial_delay) redis.call('SET', redis_key, now + initial_delay)
return { false, delay } return { false, initial_delay }
end end
-- next_call_ts is defined -- next_call_ts is defined

View File

@ -144,6 +144,7 @@ class EngineProcessor(ABC):
- A page-number > 1 when engine does not support paging. - A page-number > 1 when engine does not support paging.
- A time range when the engine does not support time range. - A time range when the engine does not support time range.
""" """
# if paging is not supported, skip # if paging is not supported, skip
if search_query.pageno > 1 and not self.engine.paging: if search_query.pageno > 1 and not self.engine.paging:
return None return None

View File

@ -226,15 +226,12 @@ outgoing:
# - 'Hash plugin' # - 'Hash plugin'
# - 'Self Information' # - 'Self Information'
# - 'Tracker URL remover' # - 'Tracker URL remover'
# - 'Unit converter plugin'
# - 'Ahmia blacklist' # activation depends on outgoing.using_tor_proxy # - 'Ahmia blacklist' # activation depends on outgoing.using_tor_proxy
# # these plugins are disabled if nothing is configured .. # # these plugins are disabled if nothing is configured ..
# - 'Hostnames plugin' # see 'hostnames' configuration below # - 'Hostnames plugin' # see 'hostnames' configuration below
# - 'Open Access DOI rewrite' # - 'Open Access DOI rewrite'
# - 'Tor check plugin' # - 'Tor check plugin'
# # Read the docs before activate: auto-detection of the language could be
# # detrimental to users expectations / users can activate the plugin in the
# # preferences if they want.
# - 'Autodetect search language'
# Configuration of the "Hostnames plugin": # Configuration of the "Hostnames plugin":
# #

View File

@ -39,9 +39,8 @@ msgstr ""
"Project-Id-Version: searx\n" "Project-Id-Version: searx\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-10-05 06:24+0000\n" "POT-Creation-Date: 2024-10-05 06:24+0000\n"
"PO-Revision-Date: 2024-10-26 21:13+0000\n" "PO-Revision-Date: 2024-11-03 09:08+0000\n"
"Last-Translator: Atul_Eterno <Atul_Eterno@users.noreply.translate.codeberg." "Last-Translator: return42 <return42@users.noreply.translate.codeberg.org>\n"
"org>\n"
"Language-Team: Spanish <https://translate.codeberg.org/projects/searxng/" "Language-Team: Spanish <https://translate.codeberg.org/projects/searxng/"
"searxng/es/>\n" "searxng/es/>\n"
"Language: es\n" "Language: es\n"
@ -1246,7 +1245,7 @@ msgstr "Tiempo máximo"
#: searx/templates/simple/preferences/favicon.html:2 #: searx/templates/simple/preferences/favicon.html:2
msgid "Favicon Resolver" msgid "Favicon Resolver"
msgstr "" msgstr "Buscador de favicon"
#: searx/templates/simple/preferences/favicon.html:15 #: searx/templates/simple/preferences/favicon.html:15
msgid "Display favicons near search results" msgid "Display favicons near search results"

View File

@ -10,21 +10,22 @@
# return42 <return42@users.noreply.translate.codeberg.org>, 2024. # return42 <return42@users.noreply.translate.codeberg.org>, 2024.
# omfj <omfj@users.noreply.translate.codeberg.org>, 2024. # omfj <omfj@users.noreply.translate.codeberg.org>, 2024.
# combwizard <combwizard@users.noreply.translate.codeberg.org>, 2024. # combwizard <combwizard@users.noreply.translate.codeberg.org>, 2024.
# laaknor <laaknor@users.noreply.translate.codeberg.org>, 2024.
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PROJECT VERSION\n" "Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-10-05 06:24+0000\n" "POT-Creation-Date: 2024-10-05 06:24+0000\n"
"PO-Revision-Date: 2024-10-04 21:35+0000\n" "PO-Revision-Date: 2024-11-03 09:08+0000\n"
"Last-Translator: combwizard " "Last-Translator: laaknor <laaknor@users.noreply.translate.codeberg.org>\n"
"<combwizard@users.noreply.translate.codeberg.org>\n" "Language-Team: Norwegian Bokmål <https://translate.codeberg.org/projects/"
"searxng/searxng/nb_NO/>\n"
"Language: nb_NO\n" "Language: nb_NO\n"
"Language-Team: Norwegian Bokmål "
"<https://translate.codeberg.org/projects/searxng/searxng/nb_NO/>\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n" "Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.8.1\n"
"Generated-By: Babel 2.16.0\n" "Generated-By: Babel 2.16.0\n"
#. CONSTANT_NAMES['NO_SUBGROUPING'] #. CONSTANT_NAMES['NO_SUBGROUPING']
@ -1051,7 +1052,7 @@ msgstr "Det er ingen flere resultater. Du kan prøve å:"
#: searx/templates/simple/messages/no_results.html:19 #: searx/templates/simple/messages/no_results.html:19
msgid "Refresh the page." msgid "Refresh the page."
msgstr "oppfrisk siden" msgstr "oppfrisk siden."
#: searx/templates/simple/messages/no_results.html:20 #: searx/templates/simple/messages/no_results.html:20
msgid "Search for another query or select another category (above)." msgid "Search for another query or select another category (above)."
@ -1882,4 +1883,3 @@ msgstr "skjul video"
#~ msgid "Engines cannot retrieve results" #~ msgid "Engines cannot retrieve results"
#~ msgstr "Søkemotorer kan ikke motta resultater" #~ msgstr "Søkemotorer kan ikke motta resultater"

View File

@ -23,13 +23,14 @@
# notlmutsaers <notlmutsaers@users.noreply.translate.codeberg.org>, 2024. # notlmutsaers <notlmutsaers@users.noreply.translate.codeberg.org>, 2024.
# return42 <return42@users.noreply.translate.codeberg.org>, 2024. # return42 <return42@users.noreply.translate.codeberg.org>, 2024.
# ljansen <ljansen@users.noreply.translate.codeberg.org>, 2024. # ljansen <ljansen@users.noreply.translate.codeberg.org>, 2024.
# zarlin <zarlin@users.noreply.translate.codeberg.org>, 2024.
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: searx\n" "Project-Id-Version: searx\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-10-05 06:24+0000\n" "POT-Creation-Date: 2024-10-05 06:24+0000\n"
"PO-Revision-Date: 2024-10-28 21:07+0000\n" "PO-Revision-Date: 2024-11-02 04:00+0000\n"
"Last-Translator: ljansen <ljansen@users.noreply.translate.codeberg.org>\n" "Last-Translator: zarlin <zarlin@users.noreply.translate.codeberg.org>\n"
"Language-Team: Dutch <https://translate.codeberg.org/projects/searxng/" "Language-Team: Dutch <https://translate.codeberg.org/projects/searxng/"
"searxng/nl/>\n" "searxng/nl/>\n"
"Language: nl\n" "Language: nl\n"
@ -493,7 +494,7 @@ msgstr "stemmen"
#: searx/engines/radio_browser.py:107 #: searx/engines/radio_browser.py:107
msgid "clicks" msgid "clicks"
msgstr "clicks" msgstr "klikken"
#: searx/engines/seekr.py:193 searx/engines/yummly.py:71 #: searx/engines/seekr.py:193 searx/engines/yummly.py:71
#: searx/engines/zlibrary.py:137 #: searx/engines/zlibrary.py:137
@ -662,7 +663,7 @@ msgstr "Voorkeuren"
#: searx/templates/simple/base.html:68 #: searx/templates/simple/base.html:68
msgid "Powered by" msgid "Powered by"
msgstr "Zoekmachine" msgstr "Verzorgd door"
#: searx/templates/simple/base.html:68 #: searx/templates/simple/base.html:68
msgid "a privacy-respecting, open metasearch engine" msgid "a privacy-respecting, open metasearch engine"
@ -1069,7 +1070,7 @@ msgstr "Er zijn geen resultaten meer. U kunt proberen om:"
#: searx/templates/simple/messages/no_results.html:19 #: searx/templates/simple/messages/no_results.html:19
msgid "Refresh the page." msgid "Refresh the page."
msgstr "Ververs de pagina" msgstr "Ververs de pagina."
#: searx/templates/simple/messages/no_results.html:20 #: searx/templates/simple/messages/no_results.html:20
msgid "Search for another query or select another category (above)." msgid "Search for another query or select another category (above)."
@ -1235,9 +1236,8 @@ msgid "Max time"
msgstr "Max. duur" msgstr "Max. duur"
#: searx/templates/simple/preferences/favicon.html:2 #: searx/templates/simple/preferences/favicon.html:2
#, fuzzy
msgid "Favicon Resolver" msgid "Favicon Resolver"
msgstr "favicon-resolver" msgstr "Favicon Oplosser"
#: searx/templates/simple/preferences/favicon.html:15 #: searx/templates/simple/preferences/favicon.html:15
msgid "Display favicons near search results" msgid "Display favicons near search results"

View File

@ -8,21 +8,23 @@
# return42 <return42@users.noreply.translate.codeberg.org>, 2024. # return42 <return42@users.noreply.translate.codeberg.org>, 2024.
# abhabongse <abhabongse@users.noreply.translate.codeberg.org>, 2024. # abhabongse <abhabongse@users.noreply.translate.codeberg.org>, 2024.
# tutakrab <tutakrab@users.noreply.translate.codeberg.org>, 2024. # tutakrab <tutakrab@users.noreply.translate.codeberg.org>, 2024.
# sahussawud <sahussawud@users.noreply.translate.codeberg.org>, 2024.
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PROJECT VERSION\n" "Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-10-05 06:24+0000\n" "POT-Creation-Date: 2024-10-05 06:24+0000\n"
"PO-Revision-Date: 2024-10-02 16:10+0000\n" "PO-Revision-Date: 2024-11-06 07:26+0000\n"
"Last-Translator: tutakrab <tutakrab@users.noreply.translate.codeberg.org>" "Last-Translator: sahussawud <sahussawud@users.noreply.translate.codeberg.org>"
"\n" "\n"
"Language-Team: Thai <https://translate.codeberg.org/projects/searxng/searxng/"
"th/>\n"
"Language: th\n" "Language: th\n"
"Language-Team: Thai "
"<https://translate.codeberg.org/projects/searxng/searxng/th/>\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n" "Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Weblate 5.8.1\n"
"Generated-By: Babel 2.16.0\n" "Generated-By: Babel 2.16.0\n"
#. CONSTANT_NAMES['NO_SUBGROUPING'] #. CONSTANT_NAMES['NO_SUBGROUPING']
@ -163,7 +165,7 @@ msgstr "มืด"
#. STYLE_NAMES['BLACK'] #. STYLE_NAMES['BLACK']
#: searx/searxng.msg #: searx/searxng.msg
msgid "black" msgid "black"
msgstr "" msgstr "สีดำ"
#. BRAND_CUSTOM_LINKS['UPTIME'] #. BRAND_CUSTOM_LINKS['UPTIME']
#: searx/searxng.msg #: searx/searxng.msg
@ -331,12 +333,12 @@ msgstr "ผู้เขียน"
#. SOCIAL_MEDIA_TERMS['THREAD OPEN'] #. SOCIAL_MEDIA_TERMS['THREAD OPEN']
#: searx/engines/discourse.py:149 searx/searxng.msg #: searx/engines/discourse.py:149 searx/searxng.msg
msgid "open" msgid "open"
msgstr "" msgstr "สร้าง"
#. SOCIAL_MEDIA_TERMS['THREAD CLOSED'] #. SOCIAL_MEDIA_TERMS['THREAD CLOSED']
#: searx/engines/discourse.py:149 searx/searxng.msg #: searx/engines/discourse.py:149 searx/searxng.msg
msgid "closed" msgid "closed"
msgstr "" msgstr "ลบ"
#. SOCIAL_MEDIA_TERMS['THREAD ANSWERED'] #. SOCIAL_MEDIA_TERMS['THREAD ANSWERED']
#: searx/engines/discourse.py:160 searx/searxng.msg #: searx/engines/discourse.py:160 searx/searxng.msg
@ -450,7 +452,7 @@ msgstr "คำนวณ {functions} จากอาร์กิวเมนต
#: searx/engines/mozhi.py:57 #: searx/engines/mozhi.py:57
msgid "Synonyms" msgid "Synonyms"
msgstr "" msgstr "คำเหมือน"
#: searx/engines/openstreetmap.py:159 #: searx/engines/openstreetmap.py:159
msgid "Get directions" msgid "Get directions"
@ -538,8 +540,9 @@ msgid "hash digest"
msgstr "แฮชย่อย" msgstr "แฮชย่อย"
#: searx/plugins/hostnames.py:103 #: searx/plugins/hostnames.py:103
#, fuzzy
msgid "Hostnames plugin" msgid "Hostnames plugin"
msgstr "" msgstr "ชื่อโฮส ปลั๊กอิน"
#: searx/plugins/hostnames.py:104 #: searx/plugins/hostnames.py:104
msgid "Rewrite hostnames, remove results or prioritize them based on the hostname" msgid "Rewrite hostnames, remove results or prioritize them based on the hostname"
@ -1698,4 +1701,3 @@ msgstr "ซ่อนวิดีโอ"
#~ msgid "Engines cannot retrieve results" #~ msgid "Engines cannot retrieve results"
#~ msgstr "เครื่องมือไม่สามารถดึงผลลัพธ์ได้" #~ msgstr "เครื่องมือไม่สามารถดึงผลลัพธ์ได้"

View File

@ -753,14 +753,14 @@ def search():
# suggestions: use RawTextQuery to get the suggestion URLs with the same bang # suggestions: use RawTextQuery to get the suggestion URLs with the same bang
suggestion_urls = list( suggestion_urls = list(
map( map(
lambda suggestion: {'url': raw_text_query.changeQuery(suggestion).getFullQuery(), 'title': suggestion}, lambda suggestion: {'url': raw_text_query.getNewFullQuery(suggestion), 'title': suggestion},
result_container.suggestions, result_container.suggestions,
) )
) )
correction_urls = list( correction_urls = list(
map( map(
lambda correction: {'url': raw_text_query.changeQuery(correction).getFullQuery(), 'title': correction}, lambda correction: {'url': raw_text_query.getNewFullQuery(correction), 'title': correction},
result_container.corrections, result_container.corrections,
) )
) )
@ -851,10 +851,8 @@ def autocompleter():
backend_name = request.preferences.get_value('autocomplete') backend_name = request.preferences.get_value('autocomplete')
for result in search_autocomplete(backend_name, sug_prefix, sxng_locale): for result in search_autocomplete(backend_name, sug_prefix, sxng_locale):
# attention: this loop will change raw_text_query object and this is
# the reason why the sug_prefix was stored before (see above)
if result != sug_prefix: if result != sug_prefix:
results.append(raw_text_query.changeQuery(result).getFullQuery()) results.append(raw_text_query.getNewFullQuery(result))
if len(raw_text_query.autocomplete_list) > 0: if len(raw_text_query.autocomplete_list) > 0:
for autocomplete_text in raw_text_query.autocomplete_list: for autocomplete_text in raw_text_query.autocomplete_list:

View File

@ -51,12 +51,19 @@ class TestQuery(SearxTestCase): # pylint:disable=missing-class-docstring
r = repr(query) r = repr(query)
self.assertTrue(r.startswith(f"<RawTextQuery query='{query_text}' ")) self.assertTrue(r.startswith(f"<RawTextQuery query='{query_text}' "))
def test_change_query(self): def test_get_new_full_query(self):
query_text = '<8 the query' query_text = '<8 the query'
query = RawTextQuery(query_text, []) query = RawTextQuery(query_text, [])
another_query = query.changeQuery('another text') full_query = query.getFullQuery()
self.assertEqual(query, another_query) new_full_query = query.getNewFullQuery('another text')
self.assertEqual(query.getFullQuery(), '<8 another text') self.assertNotEqual(full_query, new_full_query)
def test_get_new_full_query_trim(self):
query_text = 'foo bar'
query = RawTextQuery(query_text, [])
new_query = 'bizz bazz'
new_full_query = query.getNewFullQuery(" " + new_query + " ")
self.assertEqual(new_query, new_full_query)
class TestLanguageParser(SearxTestCase): # pylint:disable=missing-class-docstring class TestLanguageParser(SearxTestCase): # pylint:disable=missing-class-docstring