Skip to content

Commit d82bd40

Browse files
committed
Eliminated loop over qualifiers.
1 parent 13e85cf commit d82bd40

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

Diff for: commands/lib/search.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,24 @@ func matcherFromQueryString(query string) func(*librariesindex.Library) bool {
127127
matched := true
128128
for _, term := range queryTerms {
129129

130-
// Flag indicating whether the search term matched a known qualifier
131-
knownQualifier := false
132-
133-
for key, extractor := range qualifiers {
134-
if strings.HasPrefix(term, key+":") {
135-
target := strings.TrimPrefix(term, key+":")
136-
matched = (matched && utils.Match(extractor(lib), []string{target}))
137-
knownQualifier = true
138-
break
139-
} else if strings.HasPrefix(term, key+"=") {
140-
target := strings.TrimPrefix(term, key+"=")
141-
matched = (matched && strings.ToLower(extractor(lib)) == target)
142-
knownQualifier = true
143-
break
130+
if sepIdx := strings.IndexAny(term, "=:"); sepIdx != -1 {
131+
potentialKey := term[:sepIdx]
132+
separator := term[sepIdx]
133+
134+
extractor, ok := qualifiers[potentialKey]
135+
if ok {
136+
target := term[sepIdx+1:]
137+
if separator == ':' {
138+
matched = (matched && utils.Match(extractor(lib), []string{target}))
139+
} else { // "="
140+
matched = (matched && strings.ToLower(extractor(lib)) == target)
141+
}
142+
} else {
143+
// Unknown qualifier names revert to basic search terms.
144+
matched = (matched && utils.Match(defaultLibraryMatchExtractor(lib), []string{term}))
144145
}
145-
}
146-
147-
if !knownQualifier {
146+
} else {
147+
// Terms that do not use qv-syntax are handled as usual.
148148
matched = (matched && utils.Match(defaultLibraryMatchExtractor(lib), []string{term}))
149149
}
150150
}

0 commit comments

Comments
 (0)