{"record":{"id":"3eb170bb0166acaa","repo":"Tencent/WeKnora","slug":"query-is-empty-3eb170","errorCode":null,"errorMessage":"query is empty","messagePattern":"query is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/searxng.go","lineNumber":99,"sourceCode":"// EmptyResultDiagnostics explains why the most recent search returned no\n// usable results. Used by the settings \"test connection\" flow.\nfunc (p *SearxngProvider) EmptyResultDiagnostics() string {\n\tif detail := formatUnresponsiveEngines(p.lastUnresponsive); detail != \"\" {\n\t\treturn detail + \"; check that upstream search engines can reach the internet\"\n\t}\n\treturn \"verify the instance URL is reachable and JSON format is enabled in settings.yml\"\n}\n\n// Search performs a metasearch query against the configured SearXNG instance.\n// SearXNG must have `search.formats: [json]` enabled in settings.yml.\nfunc (p *SearxngProvider) Search(\n\tctx context.Context,\n\tquery string,\n\tmaxResults int,\n\tincludeDate bool,\n) ([]*types.WebSearchResult, error) {\n\tif strings.TrimSpace(query) == \"\" {\n\t\treturn nil, fmt.Errorf(\"query is empty\")\n\t}\n\tif maxResults <= 0 {\n\t\tmaxResults = 5\n\t}\n\n\tq := url.Values{}\n\tq.Set(\"q\", query)\n\tq.Set(\"format\", \"json\")\n\t// Use \"all\" (SearXNG's documented value for \"no language filter\") instead\n\t// of \"auto\", which is a UI-side default and not a valid /search parameter.\n\t// safesearch is intentionally not set here so the value configured in the\n\t// instance's settings.yml is honored.\n\tq.Set(\"language\", \"all\")\n\n\treqURL := p.baseURL + \"/search?\" + q.Encode()\n\tlogger.Infof(ctx, \"[WebSearch][SearXNG] query=%q maxResults=%d url=%s\", query, maxResults, p.baseURL)\n\n\treq, err := http.NewRequestWithContext(ctx, http.MethodGet, reqURL, nil)","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/searxng.go#L81-L117","documentation":"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.","triggerScenarios":"Calling Search(ctx, \"\", n, false) or Search(ctx, \"   \\t \", n, false) on a SearxngProvider.","commonSituations":"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).","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"],"exampleFix":"// before\nresults, err := provider.Search(ctx, query, 5, false)\n// after\nquery = strings.TrimSpace(query)\nif query == \"\" {\n    return nil, nil // or handle empty-query case\n}\nresults, err := provider.Search(ctx, query, 5, false)","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(query) == \"\" {\n    return nil, nil // skip search\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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)"],"tags":["validation","input-validation","searxng","empty-input"],"backgroundTag":"empty-query-parameter","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}