Tencent/WeKnora · error
query is empty
Error message
query is empty
What it means
Search() validates the query string before issuing any HTTP work and refuses blank queries (whitespace-only counts as empty via strings.TrimSpace). SearXNG cannot serve a meaningful result set for an empty query, so the provider fails fast with a clear client-side error instead of a remote 4xx.
Source
Thrown at internal/infrastructure/web_search/searxng.go:99
// EmptyResultDiagnostics explains why the most recent search returned no
// usable results. Used by the settings "test connection" flow.
func (p *SearxngProvider) EmptyResultDiagnostics() string {
if detail := formatUnresponsiveEngines(p.lastUnresponsive); detail != "" {
return detail + "; check that upstream search engines can reach the internet"
}
return "verify the instance URL is reachable and JSON format is enabled in settings.yml"
}
// Search performs a metasearch query against the configured SearXNG instance.
// SearXNG must have `search.formats: [json]` enabled in settings.yml.
func (p *SearxngProvider) Search(
ctx context.Context,
query string,
maxResults int,
includeDate bool,
) ([]*types.WebSearchResult, error) {
if strings.TrimSpace(query) == "" {
return nil, fmt.Errorf("query is empty")
}
if maxResults <= 0 {
maxResults = 5
}
q := url.Values{}
q.Set("q", query)
q.Set("format", "json")
// Use "all" (SearXNG's documented value for "no language filter") instead
// of "auto", which is a UI-side default and not a valid /search parameter.
// safesearch is intentionally not set here so the value configured in the
// instance's settings.yml is honored.
q.Set("language", "all")
reqURL := p.baseURL + "/search?" + q.Encode()
logger.Infof(ctx, "[WebSearch][SearXNG] query=%q maxResults=%d url=%s", query, maxResults, p.baseURL)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, reqURL, nil)View on GitHub (pinned to 988cbb0330)
Solutions
- Trim and check the query before calling Search; skip the search step entirely for blank input
- Fix the upstream code that derives the query (e.g. keyword extraction) so it never yields empty strings
- Return a graceful 'no results' result to the caller instead of treating it as an error path
Example fix
// before
results, err := provider.Search(ctx, query, 5, false)
// after
query = strings.TrimSpace(query)
if query == "" {
return nil, nil // or handle empty-query case
}
results, err := provider.Search(ctx, query, 5, false) Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(query) == "" {
return nil, nil // skip search
} Prevention
- Always TrimSpace queries before calling any Search provider
- Skip the web-search step entirely when the derived query is blank
- Add an upstream guard where the query is produced (keyword extraction/user input)
When it happens
Trigger: Calling Search(ctx, "", n, false) or Search(ctx, " \t ", n, false) on a SearxngProvider.
Common situations: Upstream pipeline produced an empty query (e.g. empty extracted keywords from a document chunk, blank user input passed through, or a template variable that never got filled).
Related errors
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/3eb170bb0166acaa.
Report an issue: GitHub.