Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/lib/stores/search.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SearchStore {
{ project: project || undefined, limit: 30 },
{ signal },
);
this.results = res.results;
this.results = res.results ?? [];
} catch (error: unknown) {
if (error instanceof DOMException
&& error.name === "AbortError") {
Expand Down
8 changes: 6 additions & 2 deletions internal/server/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ func (s *Server) handleSearch(
return
}

results := page.Results
if results == nil {
results = []db.SearchResult{}
}
writeJSON(w, http.StatusOK, searchResponse{
Query: query,
Results: page.Results,
Count: len(page.Results),
Results: results,
Count: len(results),
Next: page.NextCursor,
})
}
20 changes: 20 additions & 0 deletions internal/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,26 @@ func TestSearch_DeadlineExceeded(t *testing.T) {
assertTimeoutRace(t, w)
}

func TestSearch_ZeroResults(t *testing.T) {
te := setup(t)
if !te.db.HasFTS() {
t.Skip("skipping search test: no FTS support")
}
te.seedSession(t, "s1", "my-app", 1)
te.seedMessages(t, "s1", 1)

w := te.get(t, "/api/v1/search?q=spamalot")
assertStatus(t, w, http.StatusOK)

resp := decode[searchResponse](t, w)
if resp.Results == nil {
t.Fatal("results must be [] not null")
}
if resp.Count != 0 {
t.Fatalf("expected count=0, got %d", resp.Count)
}
}

func TestSearch_NotAvailable(t *testing.T) {
te := setup(t)
// Simulate missing FTS by dropping the virtual table.
Expand Down