Replaced the Title filter with a general search, run by the backend
GET /api/opportunities/search?q= returns the UUIDs of the matching opportunities, and the frontend filters its list by them. Words without a prompt search the title and description; title:, buyer:, buyer_id: and cpv: search only their own field, and a leading ! leaves out what a term matches. Repeats of one prompt are OR, everything else AND. CPV terms are checked per code: cpv:72 !cpv:7221 needs a code starting 72 that doesn't start 7221. Unknown prompts are reported, and every response carries the help that the search box's "?" panel shows. Migration 00011 adds the description and buyer name to the full-text index, and indexes CPV descriptions.
This commit is contained in:
1 parent
0a777792d8
commit
b0230e6847
29 files changed
+1913
-43
No files matched your search
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -402,3 +403,67 @@ func TestMigration10MergesCPVDuplicates(t *testing.T) {
|
||||
t.Error("a second row for a CPV code was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
// Migration 11 indexes the description, buyer name and classification
|
||||
// descriptions of rows already stored, and its Down leaves the title
|
||||
// index working.
|
||||
func TestMigration11IndexesStoredRows(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
m, db := newMigrator(t)
|
||||
if _, err := m.UpTo(ctx, 10); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
setup := []string{
|
||||
`INSERT INTO opportunities (uuid, uuid_type, title, status,
|
||||
description, buyer_name, latest_release_date)
|
||||
VALUES ('a', 'ocid', 'Cloud', 'active', 'Servers', 'Leeds',
|
||||
'2026-10-01')`,
|
||||
`INSERT INTO classification_codes (id, is_cpv, code, classification)
|
||||
VALUES (1, 1, '15800000', 'Miscellaneous food products')`,
|
||||
}
|
||||
for _, statement := range setup {
|
||||
if _, err := db.ExecContext(ctx, statement); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := m.UpTo(ctx, 11); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
count := func(query string) int {
|
||||
t.Helper()
|
||||
var n int
|
||||
if err := db.QueryRowContext(ctx, query).Scan(&n); err != nil {
|
||||
t.Fatalf("%s: %v", query, err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
matches := []struct {
|
||||
table, match string
|
||||
want int
|
||||
}{
|
||||
{"opportunities_fts", "description : servers", 1},
|
||||
{"opportunities_fts", "buyer_name : leeds", 1},
|
||||
{"opportunities_fts", "title : servers", 0},
|
||||
{"classification_codes_fts", "food", 1},
|
||||
}
|
||||
for _, tc := range matches {
|
||||
got := count(fmt.Sprintf(
|
||||
"SELECT count(*) FROM %s WHERE %[1]s MATCH '%s'", tc.table, tc.match,
|
||||
))
|
||||
if got != tc.want {
|
||||
t.Errorf("%s MATCH %q: %d; want %d", tc.table, tc.match, got, tc.want)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := m.DownTo(ctx, 10); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := count(`SELECT count(*) FROM opportunities_fts
|
||||
WHERE opportunities_fts MATCH 'cloud'`)
|
||||
if got != 1 {
|
||||
t.Errorf("title search after Down: %d; want 1", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user