feat: build Go-based SearXNG-compatible search service
Implement an API-first Go rewrite with local engine adapters, upstream fallback, and Nix-based tooling so searches can run without matching the original UI while preserving response compatibility. Made-with: Cursor
This commit is contained in:
parent
7783367c71
commit
dc44837219
32 changed files with 3330 additions and 0 deletions
71
internal/engines/crossref_test.go
Normal file
71
internal/engines/crossref_test.go
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
package engines
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/ashie/gosearch/internal/contracts"
|
||||
)
|
||||
|
||||
func TestCrossrefEngine_Search(t *testing.T) {
|
||||
transport := roundTripperFunc(func(r *http.Request) (*http.Response, error) {
|
||||
if r.Method != http.MethodGet {
|
||||
return httpResponse(http.StatusMethodNotAllowed, "", ""), nil
|
||||
}
|
||||
if r.URL.Host != "api.crossref.org" || r.URL.Path != "/works" {
|
||||
return httpResponse(http.StatusNotFound, "", ""), nil
|
||||
}
|
||||
q := r.URL.Query().Get("query")
|
||||
if q != "hugo" {
|
||||
return httpResponse(http.StatusBadRequest, "", ""), nil
|
||||
}
|
||||
|
||||
body := `{
|
||||
"message": {
|
||||
"items": [
|
||||
{
|
||||
"type": "journal-article",
|
||||
"title": ["Paper B"],
|
||||
"URL": "https://example.com/paperb",
|
||||
"abstract": "Abstract B",
|
||||
"DOI": "10.1234/b",
|
||||
"published": {
|
||||
"date-parts": [[2020, 5, 1]]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}`
|
||||
return httpResponse(http.StatusOK, body, "application/json"), nil
|
||||
})
|
||||
|
||||
client := &http.Client{Transport: transport}
|
||||
engine := &CrossrefEngine{client: client}
|
||||
|
||||
resp, err := engine.Search(context.Background(), contracts.SearchRequest{
|
||||
Query: "hugo",
|
||||
Pageno: 1,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if len(resp.Results) != 1 {
|
||||
t.Fatalf("expected 1 result, got %d", len(resp.Results))
|
||||
}
|
||||
|
||||
r := resp.Results[0]
|
||||
if r.Title != "Paper B" {
|
||||
t.Fatalf("expected title Paper B, got %q", r.Title)
|
||||
}
|
||||
if r.Content != "Abstract B" {
|
||||
t.Fatalf("expected content, got %q", r.Content)
|
||||
}
|
||||
if r.Pubdate == nil || *r.Pubdate == "" {
|
||||
t.Fatalf("expected pubdate, got nil/empty")
|
||||
}
|
||||
if r.Engine != "crossref" {
|
||||
t.Fatalf("expected engine crossref, got %q", r.Engine)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue