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
66
internal/engines/arxiv_test.go
Normal file
66
internal/engines/arxiv_test.go
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
package engines
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/ashie/gosearch/internal/contracts"
|
||||
)
|
||||
|
||||
func TestArxivEngine_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 != "export.arxiv.org" || r.URL.Path != "/api/query" {
|
||||
return httpResponse(http.StatusNotFound, "", ""), nil
|
||||
}
|
||||
|
||||
q := r.URL.Query().Get("search_query")
|
||||
if q != "all:quantum" {
|
||||
return httpResponse(http.StatusBadRequest, "", ""), nil
|
||||
}
|
||||
|
||||
atom := `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<entry>
|
||||
<title>Quantum Test</title>
|
||||
<id>http://arxiv.org/abs/1234.5678</id>
|
||||
<summary>Abstract here</summary>
|
||||
<published>2024-06-03T00:00:00Z</published>
|
||||
</entry>
|
||||
</feed>`
|
||||
return httpResponse(http.StatusOK, atom, "application/atom+xml"), nil
|
||||
})
|
||||
|
||||
client := &http.Client{Transport: transport}
|
||||
engine := &ArxivEngine{client: client}
|
||||
|
||||
resp, err := engine.Search(context.Background(), contracts.SearchRequest{
|
||||
Query: "quantum",
|
||||
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 != "Quantum Test" {
|
||||
t.Fatalf("unexpected title: %q", r.Title)
|
||||
}
|
||||
if r.Content != "Abstract here" {
|
||||
t.Fatalf("unexpected content: %q", r.Content)
|
||||
}
|
||||
if r.URL == nil || !strings.Contains(*r.URL, "1234.5678") {
|
||||
t.Fatalf("unexpected url: %v", r.URL)
|
||||
}
|
||||
if r.Pubdate == nil || !strings.Contains(*r.Pubdate, "2024-06-03") {
|
||||
t.Fatalf("expected pubdate around 2024-06-03, got %v", r.Pubdate)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue