Sign inSign up

fviolence/searxng-query-corrector

By fviolence

Updated about 1 month ago

Basic query corrector for SearXNG server based on LanguageTool

Image
0

632

fviolence/searxng-query-corrector repository overview

Custom SearXNG query-corrector shim

A conservative compatibility service between the custom SearXNG query_corrector engine and a self-hosted LanguageTool server.

Behavior

The shim:

  • accepts POST /v1/correct with query and optional language;
  • calls LanguageTool's POST /v2/check;
  • considers only matches with rule.issueType == "misspelling";
  • rejects case-only changes, technical-looking tokens, SearXNG query-syntax tokens, unsafe control characters, whitespace replacements by default, excessive edit distances, genuinely overlapping edits, and queries requiring too many edits;
  • deduplicates repeated LanguageTool matches that refer to the same source span;
  • caches LanguageTool-supported languages through /readyz and falls back to auto-detection for unsupported language codes;
  • permits the zero-width joiner and non-joiner characters that SearXNG accepts for scripts that require them;
  • returns {"correction": null} whenever it cannot make a conservative correction;
  • exposes /healthz and /readyz.

Chosen LanguageTool image

image: docker.io/erikvl87/languagetool:6.8

Compose integration

Merge the languagetool and query-corrector services from compose.example.yml into the existing SearXNG Compose file.

No host ports are required. Docker Compose DNS makes these internal addresses available:

  • http://languagetool:8010
  • http://query-corrector:8000

Then configure SearXNG:

use_default_settings: true

engines:
  - name: query corrector
    base_url: http://query-corrector:8000
    enable_http: true
    timeout: 1.0
    inactive: false
    disabled: false

The engine rejects plain HTTP unless enable_http: true is set. This is appropriate for the private Docker network shown above; use HTTPS for a remote service.

The bundled SearXNG engine timeout is 250 ms, so start with 1.0 second for this LanguageTool sidecar and tune after observing real latency.

Keep LANGUAGETOOL_TIMEOUT below the SearXNG engine timeout so the shim can return cleanly before SearXNG cancels its request. The initial LanguageTool request and the optional language=auto retry share this single timeout budget.

The Docker health check deliberately calls /readyz, not /healthz. The container is therefore marked unhealthy while LanguageTool is unavailable, even when the shim process itself is still serving requests.

Environment variables

VariableDefaultPurpose
LANGUAGETOOL_URLhttp://languagetool:8010LanguageTool base URL
LANGUAGETOOL_TIMEOUT0.8Upstream timeout in seconds
DEFAULT_LANGUAGEautoUsed when SearXNG sends no language
PREFERRED_VARIANTSen-US,de-DE,pt-PTLanguageTool auto-detection variants
LANGUAGE_VARIANTSen:en-US,de:de-DE,pt:pt-PTVariantless-language mappings
IGNORED_WORDSemptyComma-separated technical terms
MAX_QUERY_LENGTH80Maximum accepted query length
MAX_CORRECTION_LENGTH256Maximum returned correction length
MAX_EDITS2Maximum spelling edits per query
MAX_TOKEN_EDIT_DISTANCE2Maximum edit distance per token
MIN_TOKEN_LENGTH3Ignore shorter tokens
ALLOW_WHITESPACE_REPLACEMENTSfalsePermit multiword suggestions while still requiring every part to be a plain word
LOG_LEVELWARNINGShim log level: CRITICAL, ERROR, WARNING, INFO, or DEBUG

GitHub repo: https://github.com/fviolence/query-corrector

Tag summary

Content type

Image

Digest

sha256:1d564d958

Size

47.6 MB

Last updated

about 1 month ago

docker pull fviolence/searxng-query-corrector