mirror of
https://github.com/Jguer/yay
synced 2024-08-31 05:39:29 +00:00
Resolves #3 (again). Filtering is now faster and happens in AUR and Pacman
This commit is contained in:
parent
14b46a7461
commit
1ebe472123
|
@ -26,6 +26,9 @@ Yay was created with a few objectives in mind and based on the design of yaourt
|
|||
|
||||
### Changelog
|
||||
|
||||
#### 1.101
|
||||
- Search speed and quality improved [#3](https://github.com/Jguer/yay/issues/3)
|
||||
|
||||
#### 1.100
|
||||
- Added manpage
|
||||
- Improved search [#3](https://github.com/Jguer/yay/issues/3)
|
||||
|
|
63
actions.go
63
actions.go
|
@ -14,50 +14,15 @@ import (
|
|||
"github.com/jguer/yay/util"
|
||||
)
|
||||
|
||||
// NarrowSearch removes terms that don't contain narrow terms in the description or name.
|
||||
func narrowSearch(aq aur.Query, pq pac.Query, narrow []string) (raq aur.Query, rpq pac.Query) {
|
||||
for _, pr := range pq {
|
||||
match := false
|
||||
for _, narrowS := range narrow {
|
||||
if strings.Contains(strings.ToUpper(pr.Name), strings.ToUpper(narrowS)) || strings.Contains(strings.ToUpper(pr.Description), strings.ToUpper(narrowS)) {
|
||||
match = true
|
||||
} else {
|
||||
match = false
|
||||
}
|
||||
}
|
||||
|
||||
if match {
|
||||
rpq = append(rpq, pr)
|
||||
}
|
||||
}
|
||||
|
||||
for _, ar := range aq {
|
||||
match := false
|
||||
for _, narrowS := range narrow {
|
||||
if strings.Contains(strings.ToUpper(ar.Name), strings.ToUpper(narrowS)) || strings.Contains(strings.ToUpper(ar.Description), strings.ToUpper(narrowS)) {
|
||||
match = true
|
||||
} else {
|
||||
match = false
|
||||
}
|
||||
}
|
||||
|
||||
if match {
|
||||
raq = append(raq, ar)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// NumberMenu presents a CLI for selecting packages to install.
|
||||
func NumberMenu(pkgName string, narrow []string, flags []string) (err error) {
|
||||
func NumberMenu(pkgS []string, flags []string) (err error) {
|
||||
var num int
|
||||
|
||||
aq, numaq, err := aur.Search(pkgName, true)
|
||||
aq, numaq, err := aur.Search(pkgS, true)
|
||||
if err != nil {
|
||||
fmt.Println("Error during AUR search:", err)
|
||||
}
|
||||
pq, numpq, err := pac.Search(pkgName)
|
||||
pq, numpq, err := pac.Search(pkgS)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -66,12 +31,6 @@ func NumberMenu(pkgName string, narrow []string, flags []string) (err error) {
|
|||
return fmt.Errorf("no packages match search")
|
||||
}
|
||||
|
||||
if len(narrow) != 0 {
|
||||
aq, pq = narrowSearch(aq, pq, narrow)
|
||||
numaq = len(aq)
|
||||
numpq = len(pq)
|
||||
}
|
||||
|
||||
if util.SortMode == util.BottomUp {
|
||||
aq.PrintSearch(numpq)
|
||||
pq.PrintSearch()
|
||||
|
@ -188,21 +147,17 @@ func Upgrade(flags []string) error {
|
|||
return erra
|
||||
}
|
||||
|
||||
// Search presents a query to the local repos and to the AUR.
|
||||
func Search(pkg string, narrow []string) (err error) {
|
||||
aq, _, err := aur.Search(pkg, true)
|
||||
// SyncSearch presents a query to the local repos and to the AUR.
|
||||
func SyncSearch(pkgS []string) (err error) {
|
||||
aq, _, err := aur.Search(pkgS, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pq, _, err := pac.Search(pkg)
|
||||
pq, _, err := pac.Search(pkgS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(narrow) != 0 {
|
||||
aq, pq = narrowSearch(aq, pq, narrow)
|
||||
}
|
||||
|
||||
if util.SortMode == util.BottomUp {
|
||||
aq.PrintSearch(0)
|
||||
pq.PrintSearch()
|
||||
|
@ -214,8 +169,8 @@ func Search(pkg string, narrow []string) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
// SingleSearch serves as a pacman -Si for repo packages and AUR packages.
|
||||
func SingleSearch(pkgS []string, flags []string) (err error) {
|
||||
// SyncInfo serves as a pacman -Si for repo packages and AUR packages.
|
||||
func SyncInfo(pkgS []string, flags []string) (err error) {
|
||||
aurS, repoS, err := pac.PackageSlices(pkgS)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
func TestSearch(t *testing.T) {
|
||||
|
||||
eN := "yay"
|
||||
result, _, err := Search("yay", true)
|
||||
result, _, err := Search([]string{"yay"}, true)
|
||||
if err != nil {
|
||||
t.Fatalf("Expected err to be nil but it was %s", err)
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ func TestSearch(t *testing.T) {
|
|||
func benchmarkSearch(search string, sort bool, b *testing.B) {
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
Search(search, sort)
|
||||
Search([]string{search}, sort)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
43
aur/query.go
43
aur/query.go
|
@ -3,6 +3,7 @@ package aur
|
|||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/jguer/yay/pacman"
|
||||
"github.com/jguer/yay/util"
|
||||
|
@ -91,27 +92,45 @@ func MultiInfo(pkgS []string) (Query, int, error) {
|
|||
}
|
||||
|
||||
// Search returns an AUR search
|
||||
func Search(pkg string, sortS bool) (Query, int, error) {
|
||||
func Search(pkgS []string, sortS bool) (Query, int, error) {
|
||||
type returned struct {
|
||||
Results Query `json:"results"`
|
||||
ResultCount int `json:"resultcount"`
|
||||
}
|
||||
r := returned{}
|
||||
err := getJSON("https://aur.archlinux.org/rpc/?v=5&type=search&arg="+pkg, &r)
|
||||
err := getJSON("https://aur.archlinux.org/rpc/?v=5&type=search&arg="+pkgS[0], &r)
|
||||
|
||||
var aq Query
|
||||
n := 0
|
||||
setter := pacman.PFactory(pFSetTrue)
|
||||
var fri int
|
||||
|
||||
for _, res := range r.Results {
|
||||
match := true
|
||||
for _, pkgN := range pkgS[1:] {
|
||||
if !(strings.Contains(res.Name, pkgN) || strings.Contains(strings.ToLower(res.Description), pkgN)) {
|
||||
match = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if match {
|
||||
n++
|
||||
aq = append(aq, res)
|
||||
fri = len(aq) - 1
|
||||
setter(aq[fri].Name, &aq[fri], false)
|
||||
}
|
||||
}
|
||||
|
||||
if aq != nil {
|
||||
setter(aq[fri].Name, &aq[fri], true)
|
||||
}
|
||||
|
||||
if sortS {
|
||||
sort.Sort(r.Results)
|
||||
sort.Sort(aq)
|
||||
}
|
||||
setter := pacman.PFactory(pFSetTrue)
|
||||
|
||||
for i, res := range r.Results {
|
||||
if i == len(r.Results)-1 {
|
||||
setter(res.Name, &r.Results[i], true)
|
||||
continue
|
||||
}
|
||||
setter(res.Name, &r.Results[i], false)
|
||||
}
|
||||
return r.Results, r.ResultCount, err
|
||||
return aq, n, err
|
||||
}
|
||||
|
||||
// This is very dirty but it works so good.
|
||||
|
|
|
@ -105,20 +105,17 @@ func main() {
|
|||
}
|
||||
|
||||
if pkgs != nil {
|
||||
err = yay.Search(pkgs[0], pkgs[1:])
|
||||
err = yay.SyncSearch(pkgs)
|
||||
}
|
||||
case "-S":
|
||||
err = yay.Install(pkgs, options)
|
||||
case "-Syu", "-Suy":
|
||||
err = yay.Upgrade(options)
|
||||
case "-Si":
|
||||
err = yay.SingleSearch(pkgs, options)
|
||||
err = yay.SyncInfo(pkgs, options)
|
||||
case "yogurt":
|
||||
util.SearchVerbosity = util.NumberMenu
|
||||
|
||||
if pkgs != nil {
|
||||
err = yay.NumberMenu(pkgs[0], pkgs[1:], options)
|
||||
}
|
||||
err = yay.NumberMenu(pkgs, options)
|
||||
default:
|
||||
err = yay.PassToPacman(op, pkgs, options)
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ func UpdatePackages(flags []string) error {
|
|||
}
|
||||
|
||||
// Search handles repo searches. Creates a RepoSearch struct.
|
||||
func Search(pkgName string) (s Query, n int, err error) {
|
||||
func Search(pkgInputN []string) (s Query, n int, err error) {
|
||||
h, err := conf.CreateHandle()
|
||||
defer h.Release()
|
||||
if err != nil {
|
||||
|
@ -108,12 +108,20 @@ func Search(pkgName string) (s Query, n int, err error) {
|
|||
|
||||
for i := initL(lenPkgs); compL(lenPkgs, i); i = finalL(i) {
|
||||
|
||||
if strings.Contains(pkgS[i].Name(), pkgName) || strings.Contains(strings.ToLower(pkgS[i].Description()), pkgName) {
|
||||
match := true
|
||||
for _, pkgN := range pkgInputN {
|
||||
if !(strings.Contains(pkgS[i].Name(), pkgN) || strings.Contains(strings.ToLower(pkgS[i].Description()), pkgN)) {
|
||||
match = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if match {
|
||||
installed = false
|
||||
if r, _ := localDb.PkgByName(pkgS[i].Name()); r != nil {
|
||||
installed = true
|
||||
} else {
|
||||
installed = false
|
||||
}
|
||||
n++
|
||||
|
||||
s = append(s, Result{
|
||||
Name: pkgS[i].Name(),
|
||||
|
@ -123,7 +131,6 @@ func Search(pkgName string) (s Query, n int, err error) {
|
|||
Group: strings.Join(pkgS[i].Groups().Slice(), ","),
|
||||
Installed: installed,
|
||||
})
|
||||
n++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ func benchmarkPrintSearch(search string, b *testing.B) {
|
|||
os.Stdout = w
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
res, _, _ := Search(search)
|
||||
res, _, _ := Search(append([]string{}, search))
|
||||
res.PrintSearch()
|
||||
}
|
||||
os.Stdout = old
|
||||
|
@ -36,7 +36,7 @@ func BenchmarkPrintSearchComplexBottomUp(b *testing.B) {
|
|||
|
||||
func benchmarkSearch(search string, b *testing.B) {
|
||||
for n := 0; n < b.N; n++ {
|
||||
Search(search)
|
||||
Search(append([]string{}, search))
|
||||
}
|
||||
}
|
||||
func BenchmarkSearchSimpleTopDown(b *testing.B) {
|
||||
|
|
Loading…
Reference in a new issue