mirror of
https://github.com/ddworken/hishtory.git
synced 2024-12-23 23:39:02 +01:00
Ignore a single dash as a token to improve search behavior for queries like 'ls -' to improve #67
This commit is contained in:
parent
0231203aad
commit
f2298def32
@ -1098,6 +1098,11 @@ func MakeWhereQueryFromSearch(ctx *context.Context, db *gorm.DB, query string) (
|
||||
tx := db.Model(&data.HistoryEntry{}).Where("true")
|
||||
for _, token := range tokens {
|
||||
if strings.HasPrefix(token, "-") {
|
||||
if token == "-" {
|
||||
// The entire token is a -, just ignore this token. Otherwise we end up
|
||||
// interpreting "-" as exluding literally all results which is pretty useless.
|
||||
continue
|
||||
}
|
||||
if containsUnescaped(token, ":") {
|
||||
query, v1, v2, err := parseAtomizedToken(ctx, token[1:])
|
||||
if err != nil {
|
||||
|
@ -274,6 +274,13 @@ func TestSearch(t *testing.T) {
|
||||
if len(results) != 1 {
|
||||
t.Fatalf("Search() returned %d results, expected 1, results=%#v", len(results), results)
|
||||
}
|
||||
|
||||
// A malformed search query, but we should just ignore the dash since this is a common enough thing
|
||||
results, err = Search(ctx, db, "ls -", 5)
|
||||
testutils.Check(t, err)
|
||||
if len(results) != 3 {
|
||||
t.Fatalf("Search() returned %d results, expected 3, results=%#v", len(results), results)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddToDbIfNew(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user