summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.dir-locals.el201
-rwxr-xr-xmanage2
-rw-r--r--searx/engines/google.py119
-rw-r--r--searx/engines/google_images.py12
-rw-r--r--searx/engines/google_news.py12
-rw-r--r--searx/engines/google_scholar.py17
-rw-r--r--searx/engines/google_videos.py12
-rw-r--r--utils/templates/etc/searx/use_default_settings.yml43
8 files changed, 236 insertions, 182 deletions
diff --git a/.dir-locals.el b/.dir-locals.el
index 23609b4d2..d0e62208e 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -1,13 +1,22 @@
;;; .dir-locals.el
;;
-;; If you get ``*** EPC Error ***`` (even after a jedi:install-server) in your
-;; emacs session, mostly you have jedi-mode enabled but the python enviroment is
-;; missed. The python environment has to be next to the
-;; ``<repo>/.dir-locals.el`` in::
+;; Per-Directory Local Variables:
+;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html
;;
-;; ./local/py3
+;; .. hint::
;;
-;; In Emacs, some buffer locals are referencing the project environment:
+;; If you get ``*** EPC Error ***`` (even after a jedi:install-server) in
+;; your emacs session, mostly you have jedi-mode enabled but the python
+;; enviroment is missed. The python environment has to be next to the
+;; ``<repo>/.dir-locals.el`` in::
+;;
+;; ./local/py3
+;;
+;; To setup such an environment, build target::
+;;
+;; $ make pyenv.install
+;;
+;; Some buffer locals are referencing the project environment:
;;
;; - prj-root --> <repo>/
;; - python-environment-directory --> <repo>/local
@@ -17,22 +26,12 @@
;; `process-environment' and `exec-path' get proper values in order to run
;; shells inside the specified virtualenv, example::
;; (setq python-shell-virtualenv-root "/path/to/env/")
+;; - python-shell-interpreter --> <repo>/local/py3/bin/python
;;
-;; To setup such an environment build target 'pyenv' or 'pyenvinstall'::
-;;
-;; $ make pyenvinstall
-;;
-;; Alternatively create the virtualenv, source it and install jedi + epc
-;; (required by `emacs-jedi <https://tkf.github.io/emacs-jedi>`_)::
+;; Jedi, flycheck & other python stuff should use the 'python-shell-interpreter'
+;; from the local py3 environment.
;;
-;; $ python -m venv ./local/py3
-;; ...
-;; $ source ./local/py3/bin/activate
-;; (py3)$ # now install into the activated 'py3' environment ..
-;; (py3)$ pip install jedi epc
-;; ...
-;;
-;; Here is what also I found useful to add to my .emacs::
+;; Other useful jedi stuff you might add to your ~/.emacs::
;;
;; (global-set-key [f6] 'flycheck-mode)
;; (add-hook 'python-mode-hook 'my:python-mode-hook)
@@ -45,97 +44,91 @@
;; (define-key python-mode-map (kbd "M-.") 'jedi:goto-definition)
;; (define-key python-mode-map (kbd "M-,") 'jedi:goto-definition-pop-marker)
;; )
-;;
((nil
. ((fill-column . 80)
(indent-tabs-mode . nil)
- ;; project root folder is where the `.dir-locals.el' is located
- (eval . (setq-local
- prj-root (locate-dominating-file default-directory ".dir-locals.el")))
- (eval . (setq-local
- python-environment-directory (expand-file-name "./local" prj-root)))
- ;; use 'py3' enviroment as default
- (eval . (setq-local
- python-environment-default-root-name "py3"))
- (eval . (setq-local
- python-shell-virtualenv-root
- (expand-file-name python-environment-default-root-name python-environment-directory)
- ))
- (eval . (setq-local
- python-shell-interpreter
- (expand-file-name "bin/python" python-shell-virtualenv-root)))
- ))
+ (eval . (progn
+
+ ;; project root folder is where the `.dir-locals.el' is located
+ (setq-local prj-root
+ (locate-dominating-file default-directory ".dir-locals.el"))
+
+ (setq-local python-environment-directory
+ (expand-file-name "./local" prj-root))
+
+ ;; use 'py3' enviroment as default
+ (setq-local python-environment-default-root-name
+ "py3")
+ (setq-local python-shell-virtualenv-root
+ (expand-file-name
+ python-environment-default-root-name python-environment-directory))
+
+ (setq-local python-shell-interpreter
+ (expand-file-name
+ "bin/python" python-shell-virtualenv-root))))))
(makefile-gmake-mode
- . ((indent-tabs-mode . t)
- ))
+ . ((indent-tabs-mode . t)))
(yaml-mode
- . (
- ;; flycheck should use the local py3 environment
- (eval . (setq-local
- flycheck-yaml-yamllint-executable
- (expand-file-name "bin/yamllint" python-shell-virtualenv-root)))
- (eval . (setq-local
- flycheck-yamllintrc
- (expand-file-name ".yamllint.yml" prj-root)))
- (flycheck-checker . yaml-yamllint)
- ))
+ . ((eval . (progn
+
+ ;; flycheck should use the local py3 environment
+ (setq-local flycheck-yaml-yamllint-executable
+ (expand-file-name "bin/yamllint" python-shell-virtualenv-root))
+
+ (setq-local flycheck-yamllintrc
+ (expand-file-name ".yamllint.yml" prj-root))
+
+ (flycheck-checker . yaml-yamllint)))))
(python-mode
- . ((indent-tabs-mode . nil)
-
- (eval . (setq-local
- python-environment-virtualenv
- (list (expand-file-name "bin/virtualenv" python-shell-virtualenv-root)
- ;;"--system-site-packages"
- "--quiet")))
-
- (eval . (setq-local
- pylint-command
- (expand-file-name "bin/pylint" python-shell-virtualenv-root)))
-
- ;; pylint will find the '.pylintrc' file next to the CWD
- ;; https://pylint.readthedocs.io/en/latest/user_guide/run.html#command-line-options
- (eval . (setq-local
- flycheck-pylintrc ".pylintrc"))
-
- ;; flycheck & other python stuff should use the local py3 environment
- (eval . (setq-local
- flycheck-python-pylint-executable python-shell-interpreter))
-
- ;; use 'M-x jedi:show-setup-info' and 'M-x epc:controller' to inspect jedi server
-
- ;; https://tkf.github.io/emacs-jedi/latest/#jedi:environment-root -- You
- ;; can specify a full path instead of a name (relative path). In that case,
- ;; python-environment-directory is ignored and Python virtual environment
- ;; is created at the specified path.
- (eval . (setq-local jedi:environment-root python-shell-virtualenv-root))
-
- ;; https://tkf.github.io/emacs-jedi/latest/#jedi:server-command
- (eval .(setq-local
- jedi:server-command
- (list python-shell-interpreter
- jedi:server-script)
- ))
-
- ;; jedi:environment-virtualenv --> see above 'python-environment-virtualenv'
- ;; is set buffer local! No need to setup jedi:environment-virtualenv:
- ;;
- ;; Virtualenv command to use. A list of string. If it is nil,
- ;; python-environment-virtualenv is used instead. You must set non-nil
- ;; value to jedi:environment-root in order to make this setting work.
- ;;
- ;; https://tkf.github.io/emacs-jedi/latest/#jedi:environment-virtualenv
- ;;
- ;; (eval . (setq-local
- ;; jedi:environment-virtualenv
- ;; (list (expand-file-name "bin/virtualenv" python-shell-virtualenv-root)
- ;; ;;"--python"
- ;; ;;"/usr/bin/python3.4"
- ;; )))
-
- ;; jedi:server-args
-
- )))
+ . ((eval . (progn
+
+ (setq-local python-environment-virtualenv
+ (list (expand-file-name "bin/virtualenv" python-shell-virtualenv-root)
+ ;;"--system-site-packages"
+ "--quiet"))
+
+ (setq-local pylint-command
+ (expand-file-name "bin/pylint" python-shell-virtualenv-root))
+
+ ;; pylint will find the '.pylintrc' file next to the CWD
+ ;; https://pylint.readthedocs.io/en/latest/user_guide/run.html#command-line-options
+ (setq-local flycheck-pylintrc
+ ".pylintrc")
+
+ ;; flycheck & other python stuff should use the local py3 environment
+ (setq-local flycheck-python-pylint-executable
+ python-shell-interpreter)
+
+ ;; use 'M-x jedi:show-setup-info' and 'M-x epc:controller' to inspect jedi server
+ ;; https://tkf.github.io/emacs-jedi/latest/#jedi:environment-root -- You
+ ;; can specify a full path instead of a name (relative path). In that case,
+ ;; python-environment-directory is ignored and Python virtual environment
+ ;; is created at the specified path.
+ (setq-local jedi:environment-root
+ python-shell-virtualenv-root)
+
+ ;; https://tkf.github.io/emacs-jedi/latest/#jedi:server-command
+ (setq-local jedi:server-command
+ (list python-shell-interpreter
+ jedi:server-script))
+
+ ;; jedi:environment-virtualenv --> see above 'python-environment-virtualenv'
+ ;; is set buffer local! No need to setup jedi:environment-virtualenv:
+ ;;
+ ;; Virtualenv command to use. A list of string. If it is nil,
+ ;; python-environment-virtualenv is used instead. You must set non-nil
+ ;; value to jedi:environment-root in order to make this setting work.
+ ;;
+ ;; https://tkf.github.io/emacs-jedi/latest/#jedi:environment-virtualenv
+ ;;
+ ;; (setq-local jedi:environment-virtualenv
+ ;; (list (expand-file-name "bin/virtualenv" python-shell-virtualenv-root)
+ ;; "--python"
+ ;; "/usr/bin/python3.4"
+ ;; ))
+ ))))
+ )
diff --git a/manage b/manage
index c9b70bf9f..631fe926a 100755
--- a/manage
+++ b/manage
@@ -32,7 +32,7 @@ pylint.FILES() {
YAMLLINT_FILES=()
while IFS= read -r line; do
YAMLLINT_FILES+=("$line")
-done <<< "$(git ls-files './tests/*.yml' './searx/*.yml')"
+done <<< "$(git ls-files './tests/*.yml' './searx/*.yml' './utils/templates/etc/searx/*.yml')"
PYLINT_SEARX_DISABLE_OPTION="\
I,C,R,\
diff --git a/searx/engines/google.py b/searx/engines/google.py
index 92c9e1399..841212e09 100644
--- a/searx/engines/google.py
+++ b/searx/engines/google.py
@@ -133,56 +133,121 @@ suggestion_xpath = '//div[contains(@class, "card-section")]//a'
spelling_suggestion_xpath = '//div[@class="med"]/p/a'
-def get_lang_info(params, lang_list, custom_aliases):
- ret_val = {}
+def get_lang_info(params, lang_list, custom_aliases, supported_any_language):
+ """Composing various language properties for the google engines.
+
+ This function is called by the various google engines (google itself,
+ google-images, -news, -scholar, -videos).
+
+ :param dict param: request parameters of the engine
+
+ :param list lang_list: list of supported languages of the engine
+ :py:obj:`ENGINES_LANGUAGES[engine-name] <searx.data.ENGINES_LANGUAGES>`
+
+ :param dict lang_list: custom aliases for non standard language codes
+ (used when calling :py:func:`searx.utils.match_language)
+
+ :param bool supported_any_language: When a language is not specified, the
+ language interpretation is left up to Google to decide how the search
+ results should be delivered. This argument is ``True`` for the google
+ engine and ``False`` for the other engines (google-images, -news,
+ -scholar, -videos).
+
+ :rtype: dict
+ :returns:
+ Py-Dictionary with the key/value pairs:
+
+ language:
+ Return value from :py:func:`searx.utils.match_language
+
+ country:
+ The country code (e.g. US, AT, CA, FR, DE ..)
+
+ subdomain:
+ Google subdomain :py:obj:`google_domains` that fits to the country
+ code.
+
+ params:
+ Py-Dictionary with additional request arguments (can be passed to
+ :py:func:`urllib.parse.urlencode`).
+
+ headers:
+ Py-Dictionary with additional HTTP headers (can be passed to
+ request's headers)
+ """
+ ret_val = {
+ 'language' : None,
+ 'country' : None,
+ 'subdomain' : None,
+ 'params' : {},
+ 'headers' : {},
+ }
+
+ # language ...
_lang = params['language']
- if _lang.lower() == 'all':
+ _any_language = _lang.lower() == 'all'
+ if _any_language:
_lang = 'en-US'
-
language = match_language(_lang, lang_list, custom_aliases)
ret_val['language'] = language
- # the requested language from params (en, en-US, de, de-AT, fr, fr-CA, ...)
- _l = _lang.split('-')
+ # country ...
- # the country code (US, AT, CA)
+ _l = _lang.split('-')
if len(_l) == 2:
country = _l[1]
else:
country = _l[0].upper()
if country == 'EN':
country = 'US'
-
ret_val['country'] = country
- # the combination (en-US, en-EN, de-DE, de-AU, fr-FR, fr-FR)
- lang_country = '%s-%s' % (language, country)
-
- # Accept-Language: fr-CH, fr;q=0.8, en;q=0.6, *;q=0.5
- ret_val['Accept-Language'] = ','.join([
- lang_country,
- language + ';q=0.8,',
- 'en;q=0.6',
- '*;q=0.5',
- ])
+ # subdomain ...
- # subdomain
ret_val['subdomain'] = 'www.' + google_domains.get(country.upper(), 'google.com')
+ # params & headers
+
+ lang_country = '%s-%s' % (language, country) # (en-US, en-EN, de-DE, de-AU, fr-FR ..)
+
# hl parameter:
# https://developers.google.com/custom-search/docs/xml_results#hlsp The
# Interface Language:
# https://developers.google.com/custom-search/docs/xml_results_appendices#interfaceLanguages
- ret_val['hl'] = lang_list.get(lang_country, language)
+ ret_val['params']['hl'] = lang_list.get(lang_country, language)
# lr parameter:
+ # The lr (language restrict) parameter restricts search results to
+ # documents written in a particular language.
# https://developers.google.com/custom-search/docs/xml_results#lrsp
- # Language Collection Values:
+ # Language Collection Values:
# https://developers.google.com/custom-search/docs/xml_results_appendices#languageCollections
- ret_val['lr'] = "lang_" + lang_list.get(lang_country, language)
+ if _any_language and supported_any_language:
+
+ # interpretation is left up to Google (based on whoogle)
+ #
+ # - add parameter ``source=lnt``
+ # - don't use parameter ``lr``
+ # - don't add a ``Accept-Language`` HTTP header.
+
+ ret_val['params']['source'] = 'lnt'
+
+ else:
+
+ # restricts search results to documents written in a particular
+ # language.
+ ret_val['params']['lr'] = "lang_" + lang_list.get(lang_country, language)
+
+ # Accept-Language: fr-CH, fr;q=0.8, en;q=0.6, *;q=0.5
+ ret_val['headers']['Accept-Language'] = ','.join([
+ lang_country,
+ language + ';q=0.8,',
+ 'en;q=0.6',
+ '*;q=0.5',
+ ])
return ret_val
@@ -198,14 +263,13 @@ def request(query, params):
lang_info = get_lang_info(
# pylint: disable=undefined-variable
- params, supported_languages, language_aliases
+ params, supported_languages, language_aliases, True
)
# https://www.google.de/search?q=corona&hl=de&lr=lang_de&start=0&tbs=qdr%3Ad&safe=medium
query_url = 'https://' + lang_info['subdomain'] + '/search' + "?" + urlencode({
'q': query,
- 'hl': lang_info['hl'],
- 'lr': lang_info['lr'],
+ **lang_info['params'],
'ie': "utf8",
'oe': "utf8",
'start': offset,
@@ -215,12 +279,9 @@ def request(query, params):
query_url += '&' + urlencode({'tbs': 'qdr:' + time_range_dict[params['time_range']]})
if params['safesearch']:
query_url += '&' + urlencode({'safe': filter_mapping[params['safesearch']]})
-
- logger.debug("query_url --> %s", query_url)
params['url'] = query_url
- logger.debug("HTTP header Accept-Language --> %s", lang_info['Accept-Language'])
- params['headers']['Accept-Language'] = lang_info['Accept-Language']
+ params['headers'].update(lang_info['headers'])
params['headers']['Accept'] = (
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
)
diff --git a/searx/engines/google_images.py b/searx/engines/google_images.py
index 919c99c63..e7382a6fe 100644
--- a/searx/engines/google_images.py
+++ b/searx/engines/google_images.py
@@ -101,14 +101,15 @@ def request(query, params):
lang_info = get_lang_info(
# pylint: disable=undefined-variable
- params, supported_languages, language_aliases
+ params, supported_languages, language_aliases, False
)
+ logger.debug(
+ "HTTP header Accept-Language --> %s", lang_info['headers']['Accept-Language'])
query_url = 'https://' + lang_info['subdomain'] + '/search' + "?" + urlencode({
'q': query,
'tbm': "isch",
- 'hl': lang_info['hl'],
- 'lr': lang_info['lr'],
+ **lang_info['params'],
'ie': "utf8",
'oe': "utf8",
'num': 30,
@@ -118,12 +119,9 @@ def request(query, params):
query_url += '&' + urlencode({'tbs': 'qdr:' + time_range_dict[params['time_range']]})
if params['safesearch']:
query_url += '&' + urlencode({'safe': filter_mapping[params['safesearch']]})
-
- logger.debug("query_url --> %s", query_url)
params['url'] = query_url
- logger.debug("HTTP header Accept-Language --> %s", lang_info['Accept-Language'])
- params['headers']['Accept-Language'] = lang_info['Accept-Language']
+ params['headers'].update(lang_info['headers'])
params['headers']['Accept'] = (
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
)
diff --git a/searx/engines/google_news.py b/searx/engines/google_news.py
index 355155de8..485d602bc 100644
--- a/searx/engines/google_news.py
+++ b/searx/engines/google_news.py
@@ -83,8 +83,10 @@ def request(query, params):
lang_info = get_lang_info(
# pylint: disable=undefined-variable
- params, supported_languages, language_aliases
+ params, supported_languages, language_aliases, False
)
+ logger.debug(
+ "HTTP header Accept-Language --> %s", lang_info['headers']['Accept-Language'])
# google news has only one domain
lang_info['subdomain'] = 'news.google.com'
@@ -102,18 +104,14 @@ def request(query, params):
query_url = 'https://' + lang_info['subdomain'] + '/search' + "?" + urlencode({
'q': query,
- 'hl': lang_info['hl'],
- 'lr': lang_info['lr'],
+ **lang_info['params'],
'ie': "utf8",
'oe': "utf8",
'gl': lang_info['country'],
}) + ('&ceid=%s' % ceid) # ceid includes a ':' character which must not be urlencoded
-
- logger.debug("query_url --> %s", query_url)
params['url'] = query_url
- logger.debug("HTTP header Accept-Language --> %s", lang_info['Accept-Language'])
- params['headers']['Accept-Language'] = lang_info['Accept-Language']
+ params['headers'].update(lang_info['headers'])
params['headers']['Accept'] = (
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
)
diff --git a/searx/engines/google_scholar.py b/searx/engines/google_scholar.py
index a0ca70e53..8442a7bfa 100644
--- a/searx/engines/google_scholar.py
+++ b/searx/engines/google_scholar.py
@@ -77,31 +77,26 @@ def request(query, params):
offset = (params['pageno'] - 1) * 10
lang_info = get_lang_info(
# pylint: disable=undefined-variable
-
-
- # params, {}, language_aliases
-
- params, supported_languages, language_aliases
+ params, supported_languages, language_aliases, False
)
+ logger.debug(
+ "HTTP header Accept-Language --> %s", lang_info['headers']['Accept-Language'])
+
# subdomain is: scholar.google.xy
lang_info['subdomain'] = lang_info['subdomain'].replace("www.", "scholar.")
query_url = 'https://'+ lang_info['subdomain'] + '/scholar' + "?" + urlencode({
'q': query,
- 'hl': lang_info['hl'],
- 'lr': lang_info['lr'],
+ **lang_info['params'],
'ie': "utf8",
'oe': "utf8",
'start' : offset,
})
query_url += time_range_url(params)
-
- logger.debug("query_url --> %s", query_url)
params['url'] = query_url
- logger.debug("HTTP header Accept-Language --> %s", lang_info['Accept-Language'])
- params['headers']['Accept-Language'] = lang_info['Accept-Language']
+ params['headers'].update(lang_info['headers'])
params['headers']['Accept'] = (
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
)
diff --git a/searx/engines/google_videos.py b/searx/engines/google_videos.py
index 3e3f5d6f1..c57db4e63 100644
--- a/searx/engines/google_videos.py
+++ b/searx/engines/google_videos.py
@@ -119,14 +119,15 @@ def request(query, params):
lang_info = get_lang_info(
# pylint: disable=undefined-variable
- params, supported_languages, language_aliases
+ params, supported_languages, language_aliases, False
)
+ logger.debug(
+ "HTTP header Accept-Language --> %s", lang_info['headers']['Accept-Language'])
query_url = 'https://' + lang_info['subdomain'] + '/search' + "?" + urlencode({
'q': query,
'tbm': "vid",
- 'hl': lang_info['hl'],
- 'lr': lang_info['lr'],
+ **lang_info['params'],
'ie': "utf8",
'oe': "utf8",
})
@@ -135,12 +136,9 @@ def request(query, params):
query_url += '&' + urlencode({'tbs': 'qdr:' + time_range_dict[params['time_range']]})
if params['safesearch']:
query_url += '&' + urlencode({'safe': filter_mapping[params['safesearch']]})
-
- logger.debug("query_url --> %s", query_url)
params['url'] = query_url
- logger.debug("HTTP header Accept-Language --> %s", lang_info['Accept-Language'])
- params['headers']['Accept-Language'] = lang_info['Accept-Language']
+ params['headers'].update(lang_info['headers'])
params['headers']['Accept'] = (
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
)
diff --git a/utils/templates/etc/searx/use_default_settings.yml b/utils/templates/etc/searx/use_default_settings.yml
index 845e3139f..f805373fe 100644
--- a/utils/templates/etc/searx/use_default_settings.yml
+++ b/utils/templates/etc/searx/use_default_settings.yml
@@ -1,23 +1,34 @@
-use_default_settings: True
+use_default_settings: true
general:
- debug : False # Debug mode, only for development
- instance_name : "searx" # displayed name
+ debug: false # Debug mode, only for development
+ instance_name: "searxng" # displayed name
+ contact_url: false # mailto:contact@example.com
search:
- safe_search : 0 # Filter results. 0: None, 1: Moderate, 2: Strict
- autocomplete : "" # Existing autocomplete backends: "dbpedia", "duckduckgo", "google", "startpage", "swisscows", "qwant", "wikipedia" - leave blank to turn it off by default
- default_lang : "" # Default search language - leave blank to detect from browser information or use codes from 'languages.py'
- formats: [html, csv, json, rss]
+ # Filter results. 0: None, 1: Moderate, 2: Strict
+ safe_search: 0
+ # Existing autocomplete backends: "dbpedia", "duckduckgo", "google",
+ # "startpage", "swisscows", "qwant", "wikipedia" - leave blank to turn it off
+ # by default.
+ autocomplete: ""
+ # Default search language - leave blank to detect from browser information or
+ # use codes from 'languages.py'
+ default_lang: ""
+ # remove format to deny access, use lower case.
+ formats: [html, csv, json, rss]
server:
- port : 8888
- bind_address : "127.0.0.1" # address to listen on
- secret_key : "ultrasecretkey" # change this!
- base_url : False # Set custom base_url. Possible values: False or "https://your.custom.host/location/"
- image_proxy : False # Proxying image results through searx
+ port: 8888
+ # address to listen on
+ bind_address: "127.0.0.1"
+ secret_key: "ultrasecretkey" # change this!
+ # Set custom base_url. Possible values:
+ # false or "https://your.custom.host/location/"
+ base_url: https://darmarit.org/searx
+ # Proxying image results through searx
+ image_proxy: false
-# uncomment below section if you have running morty proxy
-#result_proxy:
-# url : http://127.0.0.1:3000/
-# key : !!binary "your_morty_proxy_key"
+# result_proxy:
+# url: http://127.0.0.1:3000/
+# key: !!binary "your_morty_proxy_key"