Skip to content

Commit d56a65e

Browse files
committed
Enable wildcard queries
1 parent 89e166d commit d56a65e

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

cmd/nix-search/main.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func root(c *cobra.Command, args []string) {
8888
name := formatPackageName(isTerminal, channel, pkg.AttrName)
8989
fmt.Print(name)
9090
if len(pkg.Programs) != 0 {
91-
programs := formatDependencies(isTerminal, query, pkg.Programs)
91+
programs := formatDependencies(isTerminal, input, pkg.Programs)
9292
fmt.Print(": ", programs)
9393
}
9494
fmt.Println()
@@ -145,13 +145,13 @@ func formatPackageName(isTerminal bool, channel, attrName string) string {
145145
return attrName
146146
}
147147

148-
func formatDependencies(isTerminal bool, query string, programs []string) string {
148+
func formatDependencies(isTerminal bool, input nixsearch.Input, programs []string) string {
149149
if isTerminal {
150150
var matches []string
151151
var others []string
152152
// Dim all the programs that aren't what you searched for
153153
for _, program := range programs {
154-
if isMatch(query, program) {
154+
if isMatch(input, program) {
155155
matches = append(matches, color.New(color.Bold).Sprint(program))
156156
} else {
157157
others = append(others, color.New(color.Faint).Sprint(program))
@@ -165,8 +165,11 @@ func formatDependencies(isTerminal bool, query string, programs []string) string
165165
return strings.Join(programs, " ")
166166
}
167167

168-
func isMatch(a, b string) bool {
169-
return a == b
168+
func isMatch(input nixsearch.Input, program string) bool {
169+
return (input.Program == program ||
170+
input.Advanced == program ||
171+
input.Name == program ||
172+
input.Default == program)
170173
}
171174

172175
func main() {

pkg/nixsearch/client.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ func ProgramQuery(query string) (string, error) {
167167
}
168168
return fmt.Sprintf(`
169169
{
170-
"match": {
170+
"wildcard": {
171171
"package_programs": {
172-
"fuzziness": 0,
173-
"query": %s
172+
"case_insensitive": true,
173+
"value": %s
174174
}
175175
}
176176
}
@@ -198,10 +198,10 @@ func AttrQuery(query string) (string, error) {
198198
}
199199
return fmt.Sprintf(`
200200
{
201-
"match": {
201+
"wildcard": {
202202
"package_attr_name": {
203-
"fuzziness": 0,
204-
"query": %s
203+
"case_insensitive": true,
204+
"value": %s
205205
}
206206
}
207207
}
@@ -248,9 +248,7 @@ func DefaultQuery(query string) (string, error) {
248248
"package_description^1.3",
249249
"package_description.*^0.78",
250250
"package_longDescription^1",
251-
"package_longDescription.*^0.6",
252-
"flake_name^0.5",
253-
"flake_name.*^0.3"
251+
"package_longDescription.*^0.6"
254252
]
255253
}
256254
},

0 commit comments

Comments
 (0)