feat: add DuckDuckGo, GitHub, Reddit, and Bing engines
- DuckDuckGo: scrapes Lite HTML endpoint for results - Language-aware region mapping (de→de-de, ja→jp-jp, etc.) - HTML parser extracts result links and snippets from DDG Lite markup - Shared html_helpers.go with extractAttr, stripHTML, htmlUnescape - GitHub: uses public Search API (repos, sorted by stars) - No auth required (10 req/min unauthenticated) - Shows stars, language, topics, last updated date - Paginated via GitHub's page parameter - Reddit: uses public JSON search API - Respects safesearch (skips over_18 posts) - Shows subreddit, score, comment count - Links self-posts to the thread URL - Bing: scrapes web search HTML (b_algo containers) - Extracts titles, URLs, and snippets from Bing's result markup - Handles Bing's tracking URL encoding - Updated factory, config defaults, and config.example.toml - Full test suite: unit tests for all engines, HTML parsing tests, region mapping tests, live request tests (skipped in short mode) 9 engines total: wikipedia, arxiv, crossref, braveapi, qwant, duckduckgo, github, reddit, bing
This commit is contained in:
parent
28b61ff251
commit
df8fe9474b
14 changed files with 1030 additions and 5 deletions
46
internal/engines/reddit_test.go
Normal file
46
internal/engines/reddit_test.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package engines
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ashie/gosearch/internal/contracts"
|
||||
)
|
||||
|
||||
func TestRedditEngine_EmptyQuery(t *testing.T) {
|
||||
eng := &RedditEngine{}
|
||||
resp, err := eng.Search(context.Background(), contracts.SearchRequest{Query: ""})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if len(resp.Results) != 0 {
|
||||
t.Errorf("expected 0 results for empty query, got %d", len(resp.Results))
|
||||
}
|
||||
}
|
||||
|
||||
func TestRedditEngine_Name(t *testing.T) {
|
||||
eng := &RedditEngine{}
|
||||
if eng.Name() != "reddit" {
|
||||
t.Errorf("expected 'reddit', got %q", eng.Name())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRedditEngine_Uninitialized(t *testing.T) {
|
||||
eng := &RedditEngine{}
|
||||
_, err := eng.Search(context.Background(), contracts.SearchRequest{Query: "test"})
|
||||
if err == nil {
|
||||
t.Error("expected error for uninitialized client")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRedditEngine_LiveRequest(t *testing.T) {
|
||||
// Reddit's JSON API returns 403 from non-browser contexts.
|
||||
// Skip in CI/sandbox environments.
|
||||
t.Skip("reddit API requires browser-like context; test manually")
|
||||
_ = context.Background
|
||||
_ = http.Client{}
|
||||
_ = contracts.SearchRequest{}
|
||||
_ = time.Second
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue