From faaddab417543969a916720bd8322bc8f20d5cc6 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Thu, 21 Nov 2024 10:51:14 +0100 Subject: [PATCH] Add a few missing comparators to the list --- components/ResultsTable.go | 74 +++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/components/ResultsTable.go b/components/ResultsTable.go index 4b3866e..2526e91 100644 --- a/components/ResultsTable.go +++ b/components/ResultsTable.go @@ -1220,48 +1220,56 @@ func (table *ResultsTable) search() { table.Filter.Input.SetAutocompleteFunc(func(currentText string) []string { split := strings.Split(currentText, " ") - comparators := []string{"=", "!=", ">", "<", ">=", "<=", "LIKE", "NOT LIKE", "IN", "NOT IN", "IS", "IS NOT", "BETWEEN", "NOT BETWEEN"} + comparators := []string{ + "=", "!=", + ">", "<", + ">=", "<=", + "between", "not between", + "ilike", "not ilike", + "in", "not in", + "is", "is not", + "like", "not like", + "regexp", "not regexp", + } - if len(split) == 1 { - columns := table.GetColumns() + switch len(split) { + case 1: columnNames := []string{} - - for i, col := range columns { - if i > 0 { - columnNames = append(columnNames, col[0]) - } + for _, col := range table.GetColumns()[1:] { + columnNames = append(columnNames, col[0]) } - return columnNames - } else if len(split) == 2 { - for i, comparator := range comparators { - comparators[i] = fmt.Sprintf("%s %s", split[0], strings.ToLower(comparator)) + case 2: + matches := []string{} + for _, comparator := range comparators { + if strings.HasPrefix(comparator, split[1]) { + matches = append(matches, fmt.Sprintf("%s %s", split[0], comparator)) + } } + return matches - return comparators - } else if len(split) == 3 { - - ret := true + case 3: + matches := []string{} switch split[1] { case "not": - comparators = []string{"between", "in", "like"} + comparators = []string{"between", "ilike", "in", "like", "regexp"} case "is": comparators = []string{"not", "null"} default: - ret = false + return matches } - if ret { - for i, comparator := range comparators { - comparators[i] = fmt.Sprintf("%s %s %s", split[0], split[1], strings.ToLower(comparator)) + for _, comparator := range comparators { + if strings.HasPrefix(comparator, split[2]) { + matches = append(matches, fmt.Sprintf("%s %s %s", split[0], split[1], comparator)) } - return comparators } + return matches - } else if len(split) == 4 { - ret := true + case 4: + matches := []string{} switch split[2] { case "not": @@ -1269,19 +1277,21 @@ func (table *ResultsTable) search() { case "is": comparators = []string{"not", "null"} default: - ret = false + return matches } - if ret { - for i, comparator := range comparators { - comparators[i] = fmt.Sprintf("%s %s %s %s", split[0], split[1], split[2], strings.ToLower(comparator)) + for _, comparator := range comparators { + if strings.HasPrefix(comparator, split[3]) { + matches = append(matches, + fmt.Sprintf("%s %s %s %s", split[0], split[1], split[2], comparator), + ) } - - return comparators } - } + return matches - return []string{} + default: + return []string{} + } }) table.Filter.Input.SetAutocompletedFunc(func(text string, _ int, source int) bool {