feat: add Stack Overflow search engine
Uses the Stack Exchange API v3 (/search/advanced) to find questions sorted by relevance. No API key required (300 req/day); optionally configure via STACKOVERFLOW_KEY env var or [engines.stackoverflow]. Results include score, answer count, view count, and tags in the snippet. Assigned to the 'it' category, triggered by the IT category tab or explicit engine selection. 6 tests covering parsing, edge cases, and helpers.
This commit is contained in:
parent
e96040ef35
commit
df67492602
5 changed files with 440 additions and 7 deletions
|
|
@ -73,9 +73,18 @@ func NewDefaultPortedEngines(client *http.Client, cfg *config.Config) map[string
|
|||
apiKey: youtubeAPIKey,
|
||||
baseURL: "https://www.googleapis.com",
|
||||
},
|
||||
"stackoverflow": &StackOverflowEngine{client: client, apiKey: stackoverflowAPIKey(cfg)},
|
||||
// Image engines
|
||||
"bing_images": &BingImagesEngine{client: client},
|
||||
"ddg_images": &DuckDuckGoImagesEngine{client: client},
|
||||
"qwant_images": &QwantImagesEngine{client: client},
|
||||
}
|
||||
}
|
||||
|
||||
// stackoverflowAPIKey returns the Stack Overflow API key from config or env var.
|
||||
func stackoverflowAPIKey(cfg *config.Config) string {
|
||||
if cfg != nil && cfg.Engines.StackOverflow != nil && cfg.Engines.StackOverflow.APIKey != "" {
|
||||
return cfg.Engines.StackOverflow.APIKey
|
||||
}
|
||||
return os.Getenv("STACKOVERFLOW_KEY")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue