mirror of
https://github.com/Hopiu/micro.git
synced 2026-04-06 16:00:58 +00:00
better plugin search
This commit is contained in:
parent
759c00098b
commit
2a7a55eca4
1 changed files with 13 additions and 5 deletions
|
|
@ -9,7 +9,6 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
|
@ -240,11 +239,20 @@ func (s PluginVersions) Less(i, j int) bool {
|
|||
|
||||
// Match returns true if the package matches a given search text
|
||||
func (pp PluginPackage) Match(text string) bool {
|
||||
// ToDo: improve matching.
|
||||
text = "(?i)" + text
|
||||
if r, err := regexp.Compile(text); err == nil {
|
||||
return r.MatchString(pp.Name)
|
||||
text = strings.ToLower(text)
|
||||
for _, t := range pp.Tags {
|
||||
if strings.ToLower(t) == text {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if strings.Contains(strings.ToLower(pp.Name), text) {
|
||||
return true
|
||||
}
|
||||
|
||||
if strings.Contains(strings.ToLower(pp.Description), text) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue