/// <summary> /// This defines the ordering of results based on the kind of symbol and other heuristics /// </summary> private int SymbolSorter(DeclaredSymbolInfo left, DeclaredSymbolInfo right, Query query) { if (left == right) { return 0; } if (left == null || right == null) { return 1; } var comparison = left.MatchLevel.CompareTo(right.MatchLevel); if (comparison != 0) { return comparison; } comparison = left.KindRank.CompareTo(right.KindRank); if (comparison != 0) { return comparison; } if (left.Name != null && right.Name != null) { comparison = left.Name.CompareTo(right.Name); if (comparison != 0) { return comparison; } } comparison = left.AssemblyNumber.CompareTo(right.AssemblyNumber); if (comparison != 0) { return comparison; } comparison = StringComparer.Ordinal.Compare(left.Description, right.Description); return comparison; }
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); } }
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); } }
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); }
private void FindGuids(Query query) { string searchTerm = query.OriginalString; searchTerm = searchTerm.TrimStart('{', '('); searchTerm = searchTerm.TrimEnd('}', ')'); var result = FindInList(searchTerm, guids, defaultToAll: false); if (result != null && result.Any()) { query.AddResultGuids(result.ToList()); } }
private void FindMSBuildTasks(Query query, bool defaultToAll = false) { var result = FindInList(query.GetSearchTermForMSBuildSearch(), msbuildTasks, defaultToAll); if (result != null && result.Any()) { query.AddResultMSBuildTasks(result.ToList()); } }
public List<DeclaredSymbolInfo> FindSymbols(string queryString) { var query = new Query(queryString); FindSymbols(query); return query.ResultSymbols; }
public Query Get(string queryString) { if (!indexFinishedPopulating) { string message = "Index is being rebuilt... " + string.Format("{0:0%}", progress); if (loadErrorMessage != null) { message = message + "<br />" + loadErrorMessage; } return Query.Empty(message); } if (queryString.Length < 3) { return Query.Empty("Enter at least three characters for type or member name"); } var query = new Query(queryString); if (query.IsAssemblySearch()) { FindAssemblies(query, defaultToAll: true); } else if (query.SymbolKinds.Contains(SymbolKindText.MSBuildProperty)) { FindMSBuildProperties(query, defaultToAll: true); } else if (query.SymbolKinds.Contains(SymbolKindText.MSBuildItem)) { FindMSBuildItems(query, defaultToAll: true); } else if (query.SymbolKinds.Contains(SymbolKindText.MSBuildTarget)) { FindMSBuildTargets(query, defaultToAll: true); } else if (query.SymbolKinds.Contains(SymbolKindText.MSBuildTask)) { FindMSBuildTasks(query, defaultToAll: true); } else { FindSymbols(query); FindAssemblies(query); FindProjects(query); FindGuids(query); FindMSBuildProperties(query); FindMSBuildItems(query); FindMSBuildTargets(query); FindMSBuildTasks(query); } return query; }
private void AppendAffiliateLinks(Query query) { WriteLine(Markup.P("Try also searching on:")); var term = query.OriginalString; term = Markup.UrlEncodeAndHtmlEscape(term); WriteLine("<ul>"); AppendAffiliateLink("http://www.bing.com/search?q=" + term); AppendAffiliateLink("http://social.msdn.microsoft.com/Search/en-US?query=" + term); AppendAffiliateLink("http://stackoverflow.com/search?q=" + term); WriteLine("</ul>"); }
public void FindSymbols(Query query) { foreach (var interpretation in query.Interpretations) { FindSymbols(query, interpretation); } if (query.ResultSymbols.Any()) { query.ResultSymbols.Sort((l, r) => SymbolSorter(l, r, query)); } }
public ResultsHtmlGenerator(Query query) { this.query = query; }
public Query Get(string queryString) { if (System.Web.HttpContext.Current != null) { var trace = System.Web.HttpContext.Current.Trace; trace.Write("index RootPath=" + (RootPath ?? "-")); trace.Write("index ProjPath=" + (ProjPath ?? "-")); } if (ProjPath == null) { RootPath = SourceConfig.GetRootPath ?? RootPath; ProjPath = ""; } if (!indexFinishedPopulating) { var rootPath = Path.Combine(RootPath, ProjPath); if (Directory.Exists(rootPath)) IndexLoader.ReadIndex(this, rootPath); } if (!indexFinishedPopulating) { string message = "Index is being rebuilt... " + string.Format("{0:0%}", progress); if (queryString.Contains(@"\") || queryString.Contains("/")) { var ctx = System.Web.HttpContext.Current; var dir = Path.Combine(RootPath, queryString); if (Directory.Exists(dir)) { message = "#" + queryString + "SolutionExplorer.html"; ctx.Response.Redirect(message); return Query.Empty(message); } } if (loadErrorMessage != null) { message = message + "<br />" + loadErrorMessage; } return Query.Empty(message); } if (queryString.Length < 3) { return Query.Empty("Enter at least three characters for type or member name"); } var query = new Query(queryString); if (query.IsAssemblySearch()) { FindAssemblies(query, defaultToAll: true); } else if (query.SymbolKinds.Contains(SymbolKindText.MSBuildProperty)) { FindMSBuildProperties(query, defaultToAll: true); } else if (query.SymbolKinds.Contains(SymbolKindText.MSBuildItem)) { FindMSBuildItems(query, defaultToAll: true); } else if (query.SymbolKinds.Contains(SymbolKindText.MSBuildTarget)) { FindMSBuildTargets(query, defaultToAll: true); } else if (query.SymbolKinds.Contains(SymbolKindText.MSBuildTask)) { FindMSBuildTasks(query, defaultToAll: true); } else { FindSymbols(query); FindAssemblies(query); FindProjects(query); FindGuids(query); FindMSBuildProperties(query); FindMSBuildItems(query); FindMSBuildTargets(query); FindMSBuildTasks(query); } return query; }
public static Query Empty(string message) { var result = new Query(); result.AddDiagnostic(message); return result; }
public void TestAssemblies() { var index = ReadIndex(); var query = new Query("System.Collections.Generric"); index.FindSymbols(query); index.FindAssemblies(query); }
//[TestMethod] public void LoadIndex() { Index index = ReadIndex(); var matches = index.FindSymbols("Microsoft.CodeAnalysis.CSharp.Symbols.SourceNamedTypeSymbol"); var expected = new DeclaredSymbolInfo() { AssemblyName = "Microsoft.CodeAnalysis.CSharp", Description = "Microsoft.CodeAnalysis.CSharp.Symbols.SourceNamedTypeSymbol", Glyph = 1, ID = 6622120691603058343UL, // { 167, 174, 195, 250, 174, 127, 230, 91 } Kind = "class", Name = "SourceNamedTypeSymbol", ProjectFilePath = "Source\\Compilers\\CSharp\\Source\\CSharpCodeAnalysis.csproj" }; Verify(matches, expected); var query = new Query("System.Core"); index.FindAssemblies(query); Assert.AreEqual("System.Core", query.ResultAssemblies.First().AssemblyName); }