From 9c211a99644989aa2e1e4bef5d5fe97da5b54975 Mon Sep 17 00:00:00 2001 From: Zach Vonler Date: Fri, 20 Oct 2023 18:09:51 -0500 Subject: [PATCH] Update commands/lib/search_matcher.go Co-authored-by: Alessio Perugini --- commands/lib/search_matcher.go | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/commands/lib/search_matcher.go b/commands/lib/search_matcher.go index 69c1b776802..df856536c53 100644 --- a/commands/lib/search_matcher.go +++ b/commands/lib/search_matcher.go @@ -110,27 +110,23 @@ func MatcherFromQueryString(query string) func(*librariesindex.Library) bool { return func(lib *librariesindex.Library) bool { matched := true for _, term := range queryTerms { - - if sepIdx := strings.IndexAny(term, "=:"); sepIdx != -1 { - potentialKey := term[:sepIdx] - separator := term[sepIdx] - - extractor, ok := qualifiers[potentialKey] - if ok { - target := term[sepIdx+1:] - if separator == ':' { + if sepIdx := strings.IndexAny(term, ":="); sepIdx != -1 { + qualifier, separator, target := term[:sepIdx], term[sepIdx], term[sepIdx+1:] + if extractor, ok := qualifiers[qualifier]; ok { + switch separator { + case ':': matched = (matched && utils.Match(extractor(lib), []string{target})) - } else { // "=" + continue + case '=': matched = (matched && strings.ToLower(extractor(lib)) == target) + continue } - } else { - // Unknown qualifier names revert to basic search terms. - matched = (matched && utils.Match(defaultLibraryMatchExtractor(lib), []string{term})) } - } else { - // Terms that do not use qv-syntax are handled as usual. - matched = (matched && utils.Match(defaultLibraryMatchExtractor(lib), []string{term})) } + // We perform the usual match in the following cases: + // 1. Unknown qualifier names revert to basic search terms. + // 2. Terms that do not use qv-syntax. + matched = (matched && utils.Match(defaultLibraryMatchExtractor(lib), []string{term})) } return matched }