yay/pkg/query/source.go
Jo d13bdb0ce1
feat(search): improve exact match for separate source (#2044)
* unify query builder

* remove uneeded code

* reorganize code
2023-04-02 00:23:02 +00:00

44 lines
702 B
Go

package query
import (
"context"
"github.com/Jguer/aur"
"github.com/hashicorp/go-multierror"
)
type SearchVerbosity int
// Verbosity settings for search.
const (
NumberMenu SearchVerbosity = iota
Detailed
Minimal
)
// queryAUR searches AUR and narrows based on subarguments.
func queryAUR(ctx context.Context,
aurClient aur.QueryClient,
pkgS []string, searchBy string,
) ([]aur.Pkg, error) {
var (
err error
by = getSearchBy(searchBy)
)
for _, word := range pkgS {
r, errM := aurClient.Get(ctx, &aur.Query{
Needles: []string{word},
By: by,
Contains: true,
})
if errM == nil {
return r, nil
}
err = multierror.Append(err, errM)
}
return nil, err
}