mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-01 17:38:33 +00:00
feat(code search): replace fuzzy search with union search for indexer (#6947)
Fuzzy searching for code has been known to be problematic #5264 and in my personal opinion isn't very useful. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6947 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Shiny Nematoda <snematoda.751k2@aleeas.com> Co-committed-by: Shiny Nematoda <snematoda.751k2@aleeas.com>
This commit is contained in:
parent
cb46a036aa
commit
3816db68aa
10 changed files with 105 additions and 86 deletions
|
@ -82,19 +82,10 @@ func testSearchRepo(t *testing.T, indexer bool) {
|
|||
testSearch(t, "/user2/glob/search?q=loren&page=1", []string{"a.txt"}, indexer)
|
||||
testSearch(t, "/user2/glob/search?q=loren&page=1&mode=exact", []string{"a.txt"}, indexer)
|
||||
|
||||
if indexer {
|
||||
// fuzzy search: matches both file3 (x/b.txt) and file1 (a.txt)
|
||||
// when indexer is enabled
|
||||
testSearch(t, "/user2/glob/search?q=file3&mode=fuzzy&page=1", []string{"x/b.txt", "a.txt"}, indexer)
|
||||
testSearch(t, "/user2/glob/search?q=file4&mode=fuzzy&page=1", []string{"x/b.txt", "a.txt"}, indexer)
|
||||
testSearch(t, "/user2/glob/search?q=file5&mode=fuzzy&page=1", []string{"x/b.txt", "a.txt"}, indexer)
|
||||
} else {
|
||||
// fuzzy search: Union/OR of all the keywords
|
||||
// when indexer is disabled
|
||||
testSearch(t, "/user2/glob/search?q=file3+file1&mode=union&page=1", []string{"a.txt", "x/b.txt"}, indexer)
|
||||
testSearch(t, "/user2/glob/search?q=file4&mode=union&page=1", []string{}, indexer)
|
||||
testSearch(t, "/user2/glob/search?q=file5&mode=union&page=1", []string{}, indexer)
|
||||
}
|
||||
// union search: Union/OR of all the keywords
|
||||
testSearch(t, "/user2/glob/search?q=file3+file1&mode=union&page=1", []string{"a.txt", "x/b.txt"}, indexer)
|
||||
testSearch(t, "/user2/glob/search?q=file4&mode=union&page=1", []string{}, indexer)
|
||||
testSearch(t, "/user2/glob/search?q=file5&mode=union&page=1", []string{}, indexer)
|
||||
|
||||
testSearch(t, "/user2/glob/search?q=file3&page=1&mode=exact", []string{"x/b.txt"}, indexer)
|
||||
testSearch(t, "/user2/glob/search?q=file4&page=1&mode=exact", []string{}, indexer)
|
||||
|
@ -121,11 +112,11 @@ func testSearch(t *testing.T, url string, expected []string, indexer bool) {
|
|||
})
|
||||
|
||||
if indexer {
|
||||
assert.EqualValues(t, []string{"exact", "fuzzy"}, dropdownOptions)
|
||||
assert.EqualValues(t, []string{"exact", "union"}, dropdownOptions)
|
||||
} else {
|
||||
assert.EqualValues(t, []string{"exact", "union", "regexp"}, dropdownOptions)
|
||||
}
|
||||
|
||||
filenames := resultFilenames(t, doc)
|
||||
assert.EqualValues(t, expected, filenames)
|
||||
assert.ElementsMatch(t, expected, filenames)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue