Skip to content

Commit

Permalink
Use alpm's built in searching for -Ss
Browse files Browse the repository at this point in the history
This allows us to support the usage option in pacman.conf
This also speeds up the searching
  • Loading branch information
Morganamilo committed Jul 26, 2018
1 parent 2f975c7 commit 3180c66
Showing 1 changed file with 13 additions and 36 deletions.
49 changes: 13 additions & 36 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,46 +260,23 @@ func queryRepo(pkgInputN []string) (s repoQuery, n int, err error) {
return
}

// BottomUp functions
initL := func(len int) int {
if config.SortMode == TopDown {
return 0
}
return len - 1
}
compL := func(len int, i int) bool {
if config.SortMode == TopDown {
return i < len
}
return i > -1
}
finalL := func(i int) int {
if config.SortMode == TopDown {
return i + 1
dbList.ForEach(func(db alpm.Db) error {
if len(pkgInputN) == 0 {
pkgs := db.PkgCache()
s = append(s, pkgs.Slice()...)
} else {
pkgs := db.Search(pkgInputN)
s = append(s, pkgs.Slice()...)
}
return i - 1
}

dbS := dbList.Slice()
lenDbs := len(dbS)
for f := initL(lenDbs); compL(lenDbs, f); f = finalL(f) {
pkgS := dbS[f].PkgCache().Slice()
lenPkgs := len(pkgS)
for i := initL(lenPkgs); compL(lenPkgs, i); i = finalL(i) {
match := true
for _, pkgN := range pkgInputN {
if !(strings.Contains(pkgS[i].Name(), pkgN) || strings.Contains(strings.ToLower(pkgS[i].Description()), pkgN)) {
match = false
break
}
}
return nil
})

if match {
n++
s = append(s, pkgS[i])
}
if config.SortMode == BottomUp {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
}

return
}

Expand Down

0 comments on commit 3180c66

Please sign in to comment.