Esempio n. 1
0
        public IEnumerable<SearchResult> Search(SearchQuery query, FileManager fileManager)
        {
            var repos = from dir in fileManager.DirectoryInfo.EnumerateDirectories()
                        let repoInfo = GitUtilities.GetRepoInfo(dir.FullName)
                        where repoInfo.IsGitRepo
                        select repoInfo;

            foreach (var repo in repos)
            {
                if (query.Terms.All(t => repo.Name.IndexOf(t, StringComparison.OrdinalIgnoreCase) != -1 || repo.Description.IndexOf(t, StringComparison.OrdinalIgnoreCase) != -1))
                {
                    yield return new SearchResult
                    {
                        LinkText = repo.Name,
                        ActionName = "ViewRepo",
                        ControllerName = "Browse",
                        RouteValues = new { repo = repo.Name },
                        Lines = new List<SearchLine>
                        {
                            new SearchLine { Line = repo.Description },
                        },
                    };
                }
            }
        }
Esempio n. 2
0
        private IEnumerable<SearchResult> Search(SearchQuery query, RepoInfo repo, bool includeRepoName = false)
        {
            TreeView tree;

            try
            {
                tree = GitUtilities.GetTreeInfo(repo.RepoPath, "HEAD", recurse: true);
            }
            catch (GitErrorException)
            {
                yield break;
            }

            foreach (var item in tree.Objects)
            {
                var name = item.Name.Substring(item.Name.LastIndexOf('/') + 1);

                if (query.Terms.All(t => name.IndexOf(t, StringComparison.OrdinalIgnoreCase) != -1))
                {
                    var linkText = (includeRepoName ? repo.Name + " " : string.Empty) + "/" + item.Name;

                    switch (item.ObjectType)
                    {
                        case ObjectType.Tree:
                            yield return new SearchResult
                            {
                                LinkText = linkText + "/",
                                ActionName = "ViewTree",
                                ControllerName = "Browse",
                                RouteValues = new { repo = repo.Name, @object = tree.Tree, path = tree.Path + item.Name + "/" },
                                Lines = new List<SearchLine>(),
                            };
                            break;

                        case ObjectType.Blob:
                            yield return new SearchResult
                            {
                                LinkText = linkText,
                                ActionName = "ViewBlob",
                                ControllerName = "Browse",
                                RouteValues = new { repo = repo.Name, @object = tree.Tree, path = tree.Path + item.Name },
                                Lines = new List<SearchLine>(),
                            };
                            break;

                        case ObjectType.Commit:
                            yield return new SearchResult
                            {
                                LinkText = linkText + "/",
                                ActionName = "ViewTree",
                                ControllerName = "Browse",
                                RouteValues = new { repo = repo.Name, @object = tree.Tree, path = tree.Path + item.Name + "/" },
                                Lines = new List<SearchLine>(),
                            };
                            break;
                    }
                }
            }
        }
Esempio n. 3
0
        public IEnumerable<SearchResult> Search(SearchQuery query, FileManager fileManager)
        {
            var repos = from dir in fileManager.DirectoryInfo.EnumerateDirectories()
                        let repoInfo = GitUtilities.GetRepoInfo(dir.FullName)
                        where repoInfo.IsGitRepo
                        select repoInfo;

            return from repo in repos
                   from searchResult in Search(query, repo, includeRepoName: true)
                   select searchResult;
        }
Esempio n. 4
0
 public Task<IList<SearchResult>> Search(SearchQuery query, FileManager fileManager, RepoInfo repository, int skip, int count)
 {
     if (repository != null)
     {
         return Task.Factory.StartNew(() => (IList<SearchResult>)Search(query, repository).Skip(skip).Take(count).ToList());
     }
     else
     {
         return Task.Factory.StartNew(() => (IList<SearchResult>)Search(query, fileManager).Skip(skip).Take(count).ToList());
     }
 }
Esempio n. 5
0
        private ActionResult Search(string q, RepoInfo repoInfo)
        {
            var searchProviders = container.ResolveAll<ISearchProvider>();

            var query = new SearchQuery(q);

            var results = (from p in searchProviders
                           select p.Search(query, this.FileManager, repoInfo, 0, 100)).ToArray();

            Task.WaitAll(results);

            return View("Search", results.Select(r => r.Result).SelectMany(r => r));
        }