| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -9,7 +9,6 @@ import ( | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						"strings" | 
					 | 
					 | 
					 | 
						"strings" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						"github.com/go-xorm/builder" | 
					 | 
					 | 
					 | 
						"github.com/go-xorm/builder" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						"github.com/go-xorm/xorm" | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					) | 
					 | 
					 | 
					 | 
					) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// RepositoryList contains a list of repositories
 | 
					 | 
					 | 
					 | 
					// RepositoryList contains a list of repositories
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -102,6 +101,7 @@ type SearchRepoOptions struct { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						Searcher    *User  `json:"-"` //ID of the person who's seeking
 | 
					 | 
					 | 
					 | 
						Searcher    *User  `json:"-"` //ID of the person who's seeking
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						OrderBy     string `json:"-"` | 
					 | 
					 | 
					 | 
						OrderBy     string `json:"-"` | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						Private     bool   `json:"-"` // Include private repositories in results
 | 
					 | 
					 | 
					 | 
						Private     bool   `json:"-"` // Include private repositories in results
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						Collaborate bool   `json:"-"` // Include collaborative repositories
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						Starred     bool   `json:"-"` | 
					 | 
					 | 
					 | 
						Starred     bool   `json:"-"` | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						Page        int    `json:"-"` | 
					 | 
					 | 
					 | 
						Page        int    `json:"-"` | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						IsProfile   bool   `json:"-"` | 
					 | 
					 | 
					 | 
						IsProfile   bool   `json:"-"` | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -115,25 +115,21 @@ type SearchRepoOptions struct { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// SearchRepositoryByName takes keyword and part of repository name to search,
 | 
					 | 
					 | 
					 | 
					// SearchRepositoryByName takes keyword and part of repository name to search,
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// it returns results in given range and number of total results.
 | 
					 | 
					 | 
					 | 
					// it returns results in given range and number of total results.
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, count int64, err error) { | 
					 | 
					 | 
					 | 
					func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, count int64, err error) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						var ( | 
					 | 
					 | 
					 | 
						var cond = builder.NewCond() | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							sess *xorm.Session | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							cond = builder.NewCond() | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						opts.Keyword = strings.ToLower(opts.Keyword) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						if opts.Page <= 0 { | 
					 | 
					 | 
					 | 
						if opts.Page <= 0 { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							opts.Page = 1 | 
					 | 
					 | 
					 | 
							opts.Page = 1 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						repos = make([]*Repository, 0, opts.PageSize) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						if opts.Starred && opts.OwnerID > 0 { | 
					 | 
					 | 
					 | 
						if opts.Starred && opts.OwnerID > 0 { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							cond = builder.Eq{ | 
					 | 
					 | 
					 | 
							cond = builder.Eq{ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								"star.uid": opts.OwnerID, | 
					 | 
					 | 
					 | 
								"star.uid": opts.OwnerID, | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						opts.Keyword = strings.ToLower(opts.Keyword) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						if opts.Keyword != "" { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							cond = cond.And(builder.Like{"lower_name", opts.Keyword}) | 
					 | 
					 | 
					 | 
							cond = cond.And(builder.Like{"lower_name", opts.Keyword}) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						// Append conditions
 | 
					 | 
					 | 
					 | 
						// Append conditions
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						if !opts.Starred && opts.OwnerID > 0 { | 
					 | 
					 | 
					 | 
						if !opts.Starred && opts.OwnerID > 0 { | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -157,27 +153,33 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								ownerIds = append(ownerIds, org.ID) | 
					 | 
					 | 
					 | 
								ownerIds = append(ownerIds, org.ID) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							cond = cond.Or(builder.And(builder.Like{"lower_name", opts.Keyword}, builder.In("owner_id", ownerIds))) | 
					 | 
					 | 
					 | 
							searcherReposCond := builder.In("owner_id", ownerIds) | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							if opts.Collaborate { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
								searcherReposCond = searcherReposCond.Or(builder.Expr(`id IN (SELECT repo_id FROM "access" WHERE access.user_id = ? AND owner_id != ?)`, | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
									opts.Searcher.ID, opts.Searcher.ID)) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							cond = cond.And(searcherReposCond) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						if len(opts.OrderBy) == 0 { | 
					 | 
					 | 
					 | 
						if len(opts.OrderBy) == 0 { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							opts.OrderBy = "name ASC" | 
					 | 
					 | 
					 | 
							opts.OrderBy = "name ASC" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						sess := x.NewSession() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						defer sess.Close() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						if opts.Starred && opts.OwnerID > 0 { | 
					 | 
					 | 
					 | 
						if opts.Starred && opts.OwnerID > 0 { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							sess = x. | 
					 | 
					 | 
					 | 
							count, err = sess. | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								Join("INNER", "star", "star.repo_id = repository.id"). | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								Where(cond) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							count, err = x. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								Join("INNER", "star", "star.repo_id = repository.id"). | 
					 | 
					 | 
					 | 
								Join("INNER", "star", "star.repo_id = repository.id"). | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								Where(cond). | 
					 | 
					 | 
					 | 
								Where(cond). | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								Count(new(Repository)) | 
					 | 
					 | 
					 | 
								Count(new(Repository)) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if err != nil { | 
					 | 
					 | 
					 | 
							if err != nil { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								return nil, 0, fmt.Errorf("Count: %v", err) | 
					 | 
					 | 
					 | 
								return nil, 0, fmt.Errorf("Count: %v", err) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							sess.Join("INNER", "star", "star.repo_id = repository.id") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} else { | 
					 | 
					 | 
					 | 
						} else { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							sess = x.Where(cond) | 
					 | 
					 | 
					 | 
							count, err = sess. | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							count, err = x. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								Where(cond). | 
					 | 
					 | 
					 | 
								Where(cond). | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								Count(new(Repository)) | 
					 | 
					 | 
					 | 
								Count(new(Repository)) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if err != nil { | 
					 | 
					 | 
					 | 
							if err != nil { | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -185,7 +187,9 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						repos = make([]*Repository, 0, opts.PageSize) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						if err = sess. | 
					 | 
					 | 
					 | 
						if err = sess. | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							Where(cond). | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							Limit(opts.PageSize, (opts.Page-1)*opts.PageSize). | 
					 | 
					 | 
					 | 
							Limit(opts.PageSize, (opts.Page-1)*opts.PageSize). | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							OrderBy(opts.OrderBy). | 
					 | 
					 | 
					 | 
							OrderBy(opts.OrderBy). | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							Find(&repos); err != nil { | 
					 | 
					 | 
					 | 
							Find(&repos); err != nil { | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -193,7 +197,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						if !opts.IsProfile { | 
					 | 
					 | 
					 | 
						if !opts.IsProfile { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if err = repos.loadAttributes(x); err != nil { | 
					 | 
					 | 
					 | 
							if err = repos.loadAttributes(sess); err != nil { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								return nil, 0, fmt.Errorf("LoadAttributes: %v", err) | 
					 | 
					 | 
					 | 
								return nil, 0, fmt.Errorf("LoadAttributes: %v", err) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |