예제 #1
0
        private IEnumerable <string> FindInList(string searchTerm, List <string> list, bool defaultToAll)
        {
            if (string.IsNullOrEmpty(searchTerm))
            {
                if (defaultToAll)
                {
                    return(list);
                }
                else
                {
                    return(null);
                }
            }

            var search = new SortedSearch(i => list[i], list.Count);

            int low, high;

            search.FindBounds(searchTerm, out low, out high);
            if (high >= low)
            {
                var result = Enumerable
                             .Range(low, high - low + 1)
                             .Select(i => list[i])
                             .Take(MaxRawResults);
                return(result);
            }

            return(null);
        }
예제 #2
0
        private void FindSymbols(Query query, Interpretation interpretation)
        {
            string searchTerm = interpretation.CoreSearchTerm;

            var search = new SortedSearch(i => symbols[i].Name, symbols.Count);

            int low, high;

            search.FindBounds(searchTerm, out low, out high);

            if (high < low)
            {
                return;
            }

            query.PotentialRawResults = high - low + 1;

            var result = Enumerable
                         .Range(low, high - low + 1)
                         .Where(i => !interpretation.IsVerbatim || symbols[i].Name.Length == searchTerm.Length)
                         .Select(i => symbols[i].GetDeclaredSymbolInfo(huffman, assemblies, projects))
                         .Where(query.Filter)
                         .Where(interpretation.Filter)
                         .Take(MaxRawResults)
                         .ToList();

            foreach (var entry in result)
            {
                entry.MatchLevel = MatchLevel(entry.Name, searchTerm);
            }

            query.AddResultSymbols(result);
        }
예제 #3
0
        public void FindAssemblies(Query query, bool defaultToAll = false)
        {
            string assemblyName = query.GetSearchTermForAssemblySearch();

            if (assemblyName == null)
            {
                if (defaultToAll)
                {
                    query.AddResultAssemblies(GetAllListedAssemblies());
                }

                return;
            }

            bool isQuoted = false;

            assemblyName = Query.StripQuotes(assemblyName, out isQuoted);

            var search = new SortedSearch(i => this.assemblies[i].AssemblyName, this.assemblies.Count);
            int low, high;

            search.FindBounds(assemblyName, out low, out high);
            if (high >= low)
            {
                var result = Enumerable
                             .Range(low, high - low + 1)
                             .Where(i => !isQuoted || assemblies[i].AssemblyName.Length == assemblyName.Length)
                             .Select(i => assemblies[i])
                             .Where(a => a.ProjectKey != -1)
                             .Take(MaxRawResults)
                             .ToList();
                query.AddResultAssemblies(result);
            }
        }
예제 #4
0
        public static int FindItem <T>(IList <T> list, string word, Func <T, string> keySelector)
        {
            var search = new SortedSearch(i => keySelector(list[i]), list.Count);
            int low;
            int high;

            search.FindBounds(word, out low, out high);
            return(low);
        }
예제 #5
0
        private void FindSymbols(Query query, Interpretation interpretation)
        {
            string searchTerm = interpretation.CoreSearchTerm;

            List <DeclaredSymbolInfo> result = new List <DeclaredSymbolInfo>();

            bool wildCardsUsed = false;

            if (searchTerm.Contains('?') || searchTerm.Contains('*'))
            {
                wildCardsUsed = true;
                searchTerm    = WildCardToRegular(searchTerm);
            }

            if (wildCardsUsed)
            {
                Regex searchRegex = new Regex(searchTerm, RegexOptions.IgnoreCase | RegexOptions.Compiled);

                result = symbols.Where(_ => searchRegex.IsMatch(_.Name))
                         .Select(_ => _.GetDeclaredSymbolInfo(huffman, assemblies, projects))
                         .Where(query.Filter)
                         .Where(interpretation.Filter)
                         .Take(MaxRawResults)
                         .ToList();
            }
            else
            {
                var search = new SortedSearch(i => symbols[i].Name, symbols.Count);

                int low, high;
                search.FindBounds(searchTerm, out low, out high);

                if (high < low)
                {
                    return;
                }

                query.PotentialRawResults = high - low + 1;

                result = Enumerable
                         .Range(low, high - low + 1)
                         .Where(i => !interpretation.IsVerbatim || symbols[i].Name.Length == searchTerm.Length)
                         .Select(i => symbols[i].GetDeclaredSymbolInfo(huffman, assemblies, projects))
                         .Where(query.Filter)
                         .Where(interpretation.Filter)
                         .Take(MaxRawResults)
                         .ToList();
            }

            foreach (var entry in result)
            {
                entry.MatchLevel = MatchLevel(entry.Name, searchTerm);
            }

            query.AddResultSymbols(result);
        }
예제 #6
0
        public AssemblyInfo FindAssembly(string assemblyName)
        {
            int i = SortedSearch.FindItem(assemblies, assemblyName, a => a.AssemblyName);

            if (i == -1)
            {
                return(default(AssemblyInfo));
            }

            return(assemblies[i]);
        }
예제 #7
0
        private void FindProjects(Query query)
        {
            string searchTerm = query.GetSearchTermForProjectSearch();

            if (searchTerm == null)
            {
                return;
            }

            var search = new SortedSearch(i => projects[i], projects.Count);

            int low, high;

            search.FindBounds(searchTerm, out low, out high);
            if (high >= low)
            {
                var result = Enumerable
                             .Range(low, high - low + 1)
                             .Select(i => assemblies[projectToAssemblyIndexMap[projects[i]]])
                             .Take(MaxRawResults)
                             .ToList();
                query.AddResultProjects(result);
            }
        }
예제 #8
0
        public AssemblyInfo FindAssembly(string assemblyName)
        {
            int i = SortedSearch.FindItem(assemblies, assemblyName, a => a.AssemblyName);

            return(assemblies[i]);
        }