Merge pull request #766 from ywk253100/search

Search refactor and bug fix
This commit is contained in:
Wenkai Yin 2016-09-06 17:01:03 +08:00 committed by GitHub
commit 8788963f88
2 changed files with 12 additions and 7 deletions

View File

@ -22,7 +22,6 @@ import (
"github.com/vmware/harbor/dao"
"github.com/vmware/harbor/models"
"github.com/vmware/harbor/service/cache"
"github.com/vmware/harbor/utils"
"github.com/vmware/harbor/utils/log"
)
@ -85,11 +84,17 @@ func (s *SearchAPI) Get() {
}
}
repositories, err2 := cache.GetRepoFromCache()
if err2 != nil {
log.Errorf("Failed to get repos from cache, error: %v", err2)
s.CustomAbort(http.StatusInternalServerError, "Failed to get repositories search result")
repos, err := dao.GetAllRepositories()
if err != nil {
log.Errorf("failed to list repositories: %v", err)
s.CustomAbort(http.StatusInternalServerError, "")
}
repositories := []string{}
for _, repo := range repos {
repositories = append(repositories, repo.Name)
}
sort.Strings(repositories)
repositoryResult := filterRepositories(repositories, projects, keyword)
result := &searchResult{Project: projectResult, Repository: repositoryResult}

View File

@ -477,10 +477,10 @@ func getReposByProject(name string, keyword ...string) ([]string, error) {
}
needMatchKeyword := len(keyword) > 0 && len(keyword[0]) != 0
for _, repo := range repos {
if needMatchKeyword &&
strings.Contains(repo.Name, keyword[0]) {
repositories = append(repositories, repo.Name)
!strings.Contains(repo.Name, keyword[0]) {
continue
}