Skip to content
Back to top
View this page
Edit this page

# Hostnames

During the initialization phase, the plugin checks whether a `hostnames:` configuration exists. If this is not the case, the plugin is not included in the PluginStorage (it is not available for selection).

- `hostnames.replace`: A mapping of regular expressions to hostnames to be replaced by other hostnames.

      hostnames:
        replace:
          '(.*\.)?youtube\.com$': 'invidious.example.com'
          '(.*\.)?youtu\.be$': 'invidious.example.com'
          ...

- `hostnames.remove`: A list of regular expressions of the hostnames whose results should be taken from the results list.

      hostnames:
        remove:
          - '(.*\.)?facebook.com$'
          - ...

- `hostnames.high_priority`: A list of regular expressions for hostnames whose result should be given higher priority. The results from these hosts are arranged higher in the results list.

      hostnames:
        high_priority:
          - '(.*\.)?wikipedia.org$'
          - ...

- `hostnames.lower_priority`: A list of regular expressions for hostnames whose result should be given lower priority. The results from these hosts are arranged lower in the results list.

      hostnames:
        low_priority:
          - '(.*\.)?google(\..*)?$'
          - ...

If the URL matches the pattern of `high_priority` AND `low_priority`, the higher priority wins over the lower priority.

Alternatively, you can also specify a file name for the mappings or lists to load these from an external file:

    hostnames:
      replace: 'rewrite-hosts.yml'
      remove:
        - '(.*\.)?facebook.com$'
        - ...
      low_priority:
        - '(.*\.)?google(\..*)?$'
        - ...
      high_priority:
        - '(.*\.)?wikipedia.org$'
        - ...

The `rewrite-hosts.yml` from the example above must be in the folder in which the `settings.yml` file is already located (`/etc/searxng`). The file then only contains the lists or the mapping tables without further information on the namespaces. In the example above, this would be a mapping table that looks something like this:

    '(.*\.)?youtube\.com$': 'invidious.example.com'
    '(.*\.)?youtu\.be$': 'invidious.example.com'

class searx.plugins.hostnames.SXNGPlugin(plg_cfg: PluginCfg )

  Rewrite hostnames, remove results or prioritize them.

  id: str = 'hostnames'

    The ID (suffix) in the HTML form.

  on_result(request: SXNG_Request, search: SearchWithPlugins, result: Result ) → bool

    Runs for each result of each engine and returns a boolean:

    - `True` to keep the result

    - `False` to remove the result from the result list

    The `result` can be modified to the needs.

    Hint

    If `Result.url` is modified, `Result.parsed_url` must be changed accordingly:

        result["parsed_url"] = urlparse(result["url"])

  init(app: flask.Flask ) → bool

    Initialization of the plugin, the return value decides whether this plugin is active or not. Initialization only takes place once, at the time the WEB application is set up. The base method always returns `True`, the method can be overwritten in the inheritances,

    - `True` plugin is active

    - `False` plugin is inactive

searx.plugins.hostnames.filter_url_field(result: Result | LegacyResult, field_name: str, url_src: str ) → bool | str

  Returns bool `True` to use URL unchanged (`False` to ignore URL). If URL should be modified, the returned string is the new URL to use.