mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-04-29 11:00:07 -05:00
test: adjust ParadeDB search tests for fuzzy prefix match broadening
ParadeDB fuzzy(1, prefix=true) returns more results than ILIKE due to edit-distance tolerance on tokenized terms. Adjust assertions to check containment rather than exact result sets when ParadeDB is active.
This commit is contained in:
@@ -531,9 +531,22 @@ func TestProject_ReadAll(t *testing.T) {
|
||||
|
||||
require.NoError(t, err)
|
||||
ls := projects3.([]*Project)
|
||||
require.Len(t, ls, 2)
|
||||
assert.Equal(t, int64(10), ls[0].ID)
|
||||
assert.Equal(t, int64(-1), ls[1].ID)
|
||||
|
||||
if db.ParadeDBAvailable() {
|
||||
// ParadeDB fuzzy prefix matching returns more results
|
||||
// (e.g. "TEST10" also matches "test1", "test11", etc.)
|
||||
require.Greater(t, len(ls), 0)
|
||||
projectIDs := make([]int64, len(ls))
|
||||
for i, p := range ls {
|
||||
projectIDs[i] = p.ID
|
||||
}
|
||||
assert.Contains(t, projectIDs, int64(10))
|
||||
assert.Contains(t, projectIDs, int64(-1))
|
||||
} else {
|
||||
require.Len(t, ls, 2)
|
||||
assert.Equal(t, int64(10), ls[0].ID)
|
||||
assert.Equal(t, int64(-1), ls[1].ID)
|
||||
}
|
||||
})
|
||||
t.Run("search returns filters as well", func(t *testing.T) {
|
||||
db.LoadAndAssertFixtures(t)
|
||||
|
||||
@@ -1766,7 +1766,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
|
||||
// Here we're explicitly testing search with and without paradeDB. Both return different results but that's
|
||||
// expected - paradeDB returns more results than other databases with a naive like-search.
|
||||
|
||||
if db.ParadeDBAvailable() {
|
||||
if !db.ParadeDBAvailable() {
|
||||
tests = append(tests, testcase{
|
||||
name: "search for task index",
|
||||
fields: fields{},
|
||||
@@ -1776,24 +1776,30 @@ func TestTaskCollection_ReadAll(t *testing.T) {
|
||||
page: 0,
|
||||
},
|
||||
want: []*Task{
|
||||
task17, // has the text #17 in the title
|
||||
task33, // has the index 17
|
||||
},
|
||||
wantErr: false,
|
||||
})
|
||||
} else {
|
||||
tests = append(tests, testcase{
|
||||
name: "search for task index",
|
||||
fields: fields{},
|
||||
args: args{
|
||||
search: "number #17",
|
||||
a: &user.User{ID: 1},
|
||||
page: 0,
|
||||
},
|
||||
want: []*Task{
|
||||
task33, // has the index 17
|
||||
},
|
||||
wantErr: false,
|
||||
}
|
||||
|
||||
if db.ParadeDBAvailable() {
|
||||
// ParadeDB fuzzy prefix matching returns more results than ILIKE,
|
||||
// so we only check that expected tasks are contained in results.
|
||||
t.Run("search for task index", func(t *testing.T) {
|
||||
db.LoadAndAssertFixtures(t)
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
lt := &TaskCollection{}
|
||||
got, _, _, err := lt.ReadAll(s, &user.User{ID: 1}, "number #17", 0, 50)
|
||||
require.NoError(t, err)
|
||||
gotTasks := got.([]*Task)
|
||||
gotIDs := make([]int64, len(gotTasks))
|
||||
for i, tsk := range gotTasks {
|
||||
gotIDs[i] = tsk.ID
|
||||
}
|
||||
assert.Contains(t, gotIDs, task17.ID, "should contain task #17 (has #17 in title)")
|
||||
assert.Contains(t, gotIDs, task33.ID, "should contain task #33 (has index 17)")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user