private static IEnumerable <SearchItem> FetchItems(SearchContext context, SearchProvider helpProvider) { var searchView = context.searchView; if (searchView != null) { searchView.itemIconSize = 1f; } foreach (var p in SearchService.OrderedProviders) { if (p.priority < 0) { continue; } var id = $"help_provider_{p.id}"; var label = p.isExplicitProvider ? $"Activate only <b>{p.name}</b>" : $"Search only <b>{p.name}</b>"; var description = p.isExplicitProvider ? $"Type <b>{p.filterId}</b> to activate <b>{p.name}</b>" : $"Type <b>{p.filterId}</b> to search <b>{p.name}</b>"; if (label.IndexOf(context.searchQuery, StringComparison.OrdinalIgnoreCase) == -1 && description.IndexOf(context.searchQuery, StringComparison.OrdinalIgnoreCase) == -1) { continue; } HelpHandler helpHandler = () => searchView.SetSearchText(p.filterId); yield return(helpProvider.CreateItem(context, id, p.priority, label, description, null, helpHandler)); } yield return(helpProvider.CreateItem(context, "help_open_pref", 9999, "Open Search Preferences", null, Icons.settings, (HelpHandler)OpenPreferences)); }
private static void SearchAssets(SearchContext context, List <SearchItem> items, SearchProvider provider, SearchIndexer fileIndexer) { var filter = context.searchQuery; var searchPackages = context.categories.Any(c => c.name.id == "packages" && c.isEnabled); var searchGuids = context.categories.Any(c => c.name.id == "guid" && c.isEnabled); if (searchGuids) { var gui2Path = AssetDatabase.GUIDToAssetPath(filter); if (!System.String.IsNullOrEmpty(gui2Path)) { items.Add(provider.CreateItem(gui2Path, -1, $"{Path.GetFileName(gui2Path)} ({filter})", null, null, null)); } } if (fileIndexer.IsReady()) { if (filter.IndexOfAny(k_InvalidIndexedChars) == -1) { items.AddRange(fileIndexer.Search(filter, searchPackages ? int.MaxValue : 100).Take(201) .Select(e => { var filename = Path.GetFileName(e.path); var filenameNoExt = Path.GetFileNameWithoutExtension(e.path); var itemScore = e.score; if (filenameNoExt.Equals(filter, StringComparison.InvariantCultureIgnoreCase)) { itemScore = SearchProvider.k_RecentUserScore + 1; } return(provider.CreateItem(e.path, itemScore, filename, null, null, null)); })); if (!context.wantsMore) { return; } } } if (!searchPackages) { if (!filter.Contains("a:assets")) { filter = "a:assets " + filter; } } items.AddRange(AssetDatabase.FindAssets(filter) .Select(AssetDatabase.GUIDToAssetPath) .Take(202) .Select(path => provider.CreateItem(path, Path.GetFileName(path)))); if (context.searchQuery.Contains('*')) { var safeFilter = string.Join("_", context.searchQuery.Split(k_InvalidSearchFileChars)); items.AddRange(Directory.EnumerateFiles(Application.dataPath, safeFilter, SearchOption.AllDirectories) .Select(path => provider.CreateItem(path.Replace(Application.dataPath, "Assets").Replace("\\", "/"), Path.GetFileName(path)))); } }
private static IEnumerable <SearchItem> SearchPackages(SearchContext context, SearchProvider provider) { if (string.IsNullOrEmpty(context.searchQuery)) { yield break; } s_ListRequest = s_ListRequest ?? PackageManager.Client.List(true); s_SearchRequest = s_SearchRequest ?? PackageManager.Client.SearchAll(); if (s_SearchRequest == null || s_ListRequest == null) { yield break; } while (!s_SearchRequest.IsCompleted || !s_ListRequest.IsCompleted) { yield return(null); } if (s_SearchRequest.Result == null || s_ListRequest.Result == null) { yield break; } foreach (var p in s_SearchRequest.Result) { if (p.keywords.Contains(context.searchQuery) || SearchUtils.MatchSearchGroups(context, p.description.ToLowerInvariant(), true) || SearchUtils.MatchSearchGroups(context, p.name.ToLowerInvariant(), true)) { yield return(provider.CreateItem(context, p.packageId, String.IsNullOrEmpty(p.resolvedPath) ? 0 : 1, FormatLabel(p), FormatDescription(p), null, p)); } } }
private static IEnumerable <SearchItem> FetchItems(SearchContext context, SearchProvider provider) { // Fetch all editor windows foreach (var win in s_AllEditorWindows) { if (!win) { continue; } // Query the UIElements DOM var allElements = win.rootVisualElement.Query(""); foreach (var element in allElements.ToList()) { // Check if match if (SearchProvider.MatchSearchGroups(context, GetName(element)) || SearchProvider.MatchSearchGroups(context, element.tooltip) || SearchProvider.MatchSearchGroups(context, GetTransformPath(element)) || (element is TextElement textElement && SearchProvider.MatchSearchGroups(context, textElement.text))) { // Return matching elements var info = new VisualElementInfo { window = win, element = element, hostWindowName = win.titleContent.text }; var item = provider.CreateItem($"uie_{element.GetHashCode()}", element.tabIndex, null, null, null, info); item.descriptionFormat |= SearchItemDescriptionFormat.Ellipsis | SearchItemDescriptionFormat.RightToLeft | SearchItemDescriptionFormat.FuzzyHighlight; yield return(item); }
private SearchItem MatchGOD(SearchContext context, SearchProvider provider, GOD god, int index, bool useFuzzySearch, string fuzzyMatchQuery, List <int> FuzzyMatches) { long score = -1; if (useFuzzySearch) { if (!FuzzySearch.FuzzyMatch(fuzzyMatchQuery, god.name, ref score, FuzzyMatches)) { return(null); } } else { if (!MatchSearchGroups(context, god.name, true)) { return(null); } } var item = provider.CreateItem(god.id, ~(int)score, null, null, //$"MatchGOD[{useFuzzySearch}]:{~(int)score} -> {String.Join(";", SceneSearchIndexer.SplitComponents(god.rawname))}", null, index); item.descriptionFormat = SearchItemDescriptionFormat.Ellipsis | SearchItemDescriptionFormat.RightToLeft; if (useFuzzySearch) { item.descriptionFormat |= SearchItemDescriptionFormat.FuzzyHighlight; } else { item.descriptionFormat |= SearchItemDescriptionFormat.Highlight; } return(item); }
public static SearchItem AddResult(SearchContext context, SearchProvider provider, GameObject go) { var instanceId = go.GetHashCode(); var item = provider.CreateItem(context, instanceId.ToString(), ~instanceId, null, null, null, new GameObjectData(go)); return(SetItemDescriptionFormat(item, useFuzzySearch: false)); }
private SearchItem MatchGOD(SearchContext context, SearchProvider provider, GOD god, int index, bool useFuzzySearch, string fuzzyMatchQuery, List <int> FuzzyMatches) { long score = -1; if (useFuzzySearch) { if (!FuzzySearch.FuzzyMatch(fuzzyMatchQuery, god.tokens, ref score, FuzzyMatches)) { return(null); } } else { if (!MatchSearchGroups(context, god.tokens, true)) { return(null); } } var item = provider.CreateItem(god.id, ~(int)score, null, null, null, index); item.descriptionFormat = SearchItemDescriptionFormat.Ellipsis | SearchItemDescriptionFormat.RightToLeft; if (useFuzzySearch) { item.descriptionFormat |= SearchItemDescriptionFormat.FuzzyHighlight; } else { item.descriptionFormat |= SearchItemDescriptionFormat.Highlight; } return(item); }
private static IEnumerable <SearchItem> FetchItems(SearchContext context, SearchProvider provider) { // Cache all available static APIs if (methods == null) { methods = FetchStaticAPIMethodInfo(); } var lowerCasePattern = context.searchQuery.ToLowerInvariant().Replace(" ", ""); var matches = new List <int>(); foreach (var m in methods) { if (!m.IsPublic && !context.options.HasFlag(SearchFlags.WantsMore)) { continue; } long score = 0; var fullName = $"{m.DeclaringType.FullName}.{m.Name}"; var fullNameLower = fullName.ToLowerInvariant(); if (FuzzySearch.FuzzyMatch(lowerCasePattern, fullNameLower, ref score, matches) && score > 300) { var visibilityString = m.IsPublic ? string.Empty : "(Non Public)"; yield return(provider.CreateItem(context, m.Name, m.IsPublic ? ~(int)score - 999 : ~(int)score, m.Name, $"{fullName} {visibilityString}", null, m)); } else { yield return(null); } } }
private static IEnumerable<SearchItem> SearchItems(SearchContext context, SearchProvider provider) { var focusedTokens = context.textFilters.Where(filter => filter.EndsWith(":", System.StringComparison.OrdinalIgnoreCase)).ToList(); var sanitizedSearchQuery = context.searchQuery; foreach (var focusedFilter in focusedTokens) { sanitizedSearchQuery = sanitizedSearchQuery.Replace(focusedFilter, ""); } if (focusedTokens.Count > 0) { var focusedFilters = focusedTokens.Select(token => token.Substring(0, token.Length - 1)).ToList(); var focusedMatchOperations = k_SubMatches.Where(subMatch => focusedFilters.Contains(subMatch.matchToken)); s_QueryEngine.SetSearchDataCallback(o => { return focusedMatchOperations.Select(matchOp => matchOp.matchWord(o)); }); } var query = s_QueryEngine.Parse(sanitizedSearchQuery); if (!query.valid) yield break; var allObjects = Resources.FindObjectsOfTypeAll(typeof(Object)); var filteredObjects = query.Apply(allObjects); foreach (var obj in filteredObjects) { yield return provider.CreateItem(obj.GetInstanceID().ToString(), $"{obj.name} [{obj.GetType()}] ({obj.GetInstanceID()})", null, null, obj.GetInstanceID()); } // Put back the default search callback if (focusedTokens.Count > 0) s_QueryEngine.SetSearchDataCallback(DefaultSearchDataCallback); }
private static IEnumerator SearchIndexes(SearchContext context, SearchProvider provider, AssetIndexer adbIndex) { var searchQuery = context.searchQuery; // Search index while (!adbIndex.IsReady()) { yield return(null); } yield return(adbIndex.Search(searchQuery.ToLowerInvariant()).Select(e => { var itemScore = e.score; var words = context.searchPhrase; var filenameNoExt = Path.GetFileNameWithoutExtension(e.id); if (filenameNoExt.Equals(words, StringComparison.OrdinalIgnoreCase)) { itemScore = SearchProvider.k_RecentUserScore - 1; } var filename = Path.GetFileName(e.id); string description = adbIndex.GetDebugIndexStrings(e.id); return provider.CreateItem(e.id, itemScore, filename, description, null, null); })); }
private static SearchItem AddResult(SearchProvider provider, string id, int score, bool useFuzzySearch) { string description = null; #if false description = $"F:{useFuzzySearch} {id} ({score})"; #endif var item = provider.CreateItem(id, score, null, description, null, null); return SetItemDescriptionFormat(item, useFuzzySearch); }
private IEnumerable <SearchItem> FetchItems(SearchContext context, SearchProvider provider) { if (m_GodBuilderEnumerator == null) { m_GodBuilderEnumerator = BuildGODS(context, provider); } while (m_GodBuilderEnumerator.MoveNext()) { yield return(m_GodBuilderEnumerator.Current); } if (indexer == null) { indexer = new SceneSearchIndexer(SceneManager.GetActiveScene().name, gods) { patternMatchCount = patternMatchCount }; indexer.Build(); yield return(null); } foreach (var item in SearchGODs(context, provider)) { yield return(item); } while (!indexer.IsReady()) { yield return(null); } foreach (var r in indexer.Search(context.searchQuery)) { if (r.index < 0 || r.index >= gods.Length) { continue; } var god = gods[r.index]; var gameObjectId = god.id; var gameObjectName = god.gameObject.name; var itemScore = r.score - 1000; if (gameObjectName.Equals(context.searchQuery, StringComparison.InvariantCultureIgnoreCase)) { itemScore *= 2; } var item = provider.CreateItem(gameObjectId, itemScore, null, null, //$"Index:{itemScore} -> {String.Join(";", SceneSearchIndexer.SplitComponents(god.rawname))}", null, r.index); item.descriptionFormat = SearchItemDescriptionFormat.Ellipsis | SearchItemDescriptionFormat.RightToLeft | SearchItemDescriptionFormat.Highlight; yield return(item); } }
private static IEnumerable <SearchItem> FetchItems(SearchContext context, SearchProvider provider, Func <string, IEnumerable <Type> > fetchHandler) { var sw = new System.Diagnostics.Stopwatch(); sw.Start(); foreach (var t in fetchHandler(context.searchQuery).Where(t => t != null)) { yield return(provider.CreateItem(context, t.AssemblyQualifiedName, 0, t.FullName, t.AssemblyQualifiedName, null, t)); } Debug.Log($"{provider.name.displayName} Searching {allTypes.Length} types with <b><i>{context.searchQuery}</i></b> took {sw.Elapsed.TotalMilliseconds,2:0.0} ms"); }
private static SearchItem SearchLogEntry(SearchContext context, SearchProvider provider, LogEntry logEntry) { if (!SearchUtils.MatchSearchGroups(context, logEntry.msgLowerCased, true)) { return(null); } var logItem = provider.CreateItem(context, logEntry.id, ~logEntry.lineNumber, logEntry.msg, null, null, logEntry); logItem.options = SearchItemOptions.Ellipsis | SearchItemOptions.RightToLeft | SearchItemOptions.Highlight; return(logItem); }
private static IEnumerator SearchAssets(SearchContext context, SearchProvider provider) { var searchQuery = context.searchQuery; var useIndexing = !context.options.HasFlag(SearchFlags.NoIndexing); if (!string.IsNullOrEmpty(searchQuery)) { // Search by GUID var guidPath = AssetDatabase.GUIDToAssetPath(searchQuery); if (!string.IsNullOrEmpty(guidPath)) { yield return(provider.CreateItem(context, guidPath, -1, $"{Path.GetFileName(guidPath)} ({searchQuery})", null, null, null)); } // Search indexes that are ready if (useIndexing) { foreach (var db in assetIndexes.Where(db => db.ready)) { yield return(SearchIndexes(context.searchQuery, context, provider, db)); } } // Perform a quick search on asset paths var findOptions = FindOptions.Words | FindOptions.Regex | FindOptions.Glob | (context.wantsMore ? FindOptions.Fuzzy : FindOptions.None); foreach (var e in FindProvider.Search(context, findOptions)) { yield return(CreateItem(context, provider, "Find", e.path, 998 + e.score)); } // Finally wait for indexes that are being built to end the search. if (useIndexing && !context.options.HasFlag(SearchFlags.Synchronous)) { foreach (var db in assetIndexes.Where(db => !db.ready)) { yield return(SearchIndexes(context.searchQuery, context, provider, db)); } } } if (context.wantsMore && context.filterType != null && string.IsNullOrEmpty(searchQuery)) { yield return(AssetDatabase.FindAssets($"t:{context.filterType.Name}") .Select(guid => AssetDatabase.GUIDToAssetPath(guid)) .Select(path => CreateItem(context, provider, "More", path, 999))); if (assetIndexes != null) { yield return(assetIndexes.Select(db => SearchIndexes($"has={context.filterType.Name}", context, provider, db))); } } }
private static IEnumerable <SearchItem> SearchIndex(SearchIndexer fileIndexer, string filter, bool searchPackages, SearchProvider provider) { return(fileIndexer.Search(filter, searchPackages ? int.MaxValue : 100).Select(e => { var filename = Path.GetFileName(e.path); var filenameNoExt = Path.GetFileNameWithoutExtension(e.path); var itemScore = e.score; if (filenameNoExt.Equals(filter, StringComparison.InvariantCultureIgnoreCase)) { itemScore = SearchProvider.k_RecentUserScore + 1; } return provider.CreateItem(e.path, itemScore, filename, null, null, null); })); }
internal static IEnumerable <SearchItem> Compute(SearchContext context, SearchProvider provider) { var expression = context.searchQuery; if (Evaluate(context.searchQuery, out var result)) { expression += " = " + result; } var calcItem = provider.CreateItem(context, result.ToString(), "compute", expression, null, null); calcItem.value = result; yield return(calcItem); }
static IEnumerable <SearchItem> GetRecentSearchItems(SearchProvider provider) { int recentIndex = 0; return(SearchService.s_RecentSearches .Where(search => !string.IsNullOrEmpty(search) && !string.IsNullOrWhiteSpace(search)) .Select(search => { var item = provider.CreateItem($"help_recent_{recentIndex}", $"Recent search: {search}", "Use Alt + Up/Down Arrow to cycle through recent searches"); item.thumbnail = Icons.quicksearch; item.score = m_StaticItemToAction.Count + recentIndex++; item.data = search; return item; })); }
private static IEnumerable <SearchItem> FetchItems(SearchContext context, SearchProvider provider) { var sw = new System.Diagnostics.Stopwatch(); sw.Start(); while (!index.IsReady()) { yield return(null); } foreach (var e in index.Search(context.searchQuery)) { yield return(provider.CreateItem(context, e.id, e.score, null, null, null, e.index)); } Debug.Log($"{provider.name.displayName} Searching dependencies with <b><i>{context.searchQuery}</i></b> took {sw.Elapsed.TotalMilliseconds,2:0.0} ms"); }
private static IEnumerator SearchIndexes(SearchContext context, SearchProvider provider, SearchIndexer index, int scoreModifier = 0) { var searchQuery = context.searchQuery; // Search index while (!index.IsReady()) { yield return(null); } yield return(index.Search(searchQuery.ToLowerInvariant()).Select(e => { var itemScore = e.score + scoreModifier; return provider.CreateItem(e.id, itemScore, null, null, null, index.GetDocument(e.index)); })); }
static IEnumerator SearchItems(SearchContext context, SearchProvider provider) { var query = s_QueryEngine.Parse(context.searchQuery); if (!query.valid) { yield break; } var filteredObjects = query.Apply(s_GameObjects); foreach (var filteredObject in filteredObjects) { yield return(provider.CreateItem(filteredObject.GetInstanceID().ToString(), null, null, null, filteredObject.GetInstanceID())); } }
private static IEnumerable <SearchItem> SearchFiles(string filter, bool searchPackages, SearchProvider provider) { UnityEngine.Assertions.Assert.IsNotNull(fileIndexer); return(fileIndexer.Search(filter, searchPackages ? int.MaxValue : 100).Select(e => { var filename = Path.GetFileName(e.id); var filenameNoExt = Path.GetFileNameWithoutExtension(e.id); var itemScore = e.score; if (filenameNoExt.Equals(filter, StringComparison.OrdinalIgnoreCase)) { itemScore = SearchProvider.k_RecentUserScore + 1; } return provider.CreateItem(e.id, itemScore, filename, null, null, null); })); }
static IEnumerator FetchItems(SearchContext context, SearchProvider provider) { if (string.IsNullOrEmpty(context.searchQuery)) { yield break; } var query = SettingsProviderCache.queryEngine.ParseQuery(context.searchQuery); if (!query.valid) { context.AddSearchQueryErrors(query.errors.Select(e => new SearchQueryError(e, context, provider))); yield break; } yield return(query.Apply(SettingsProviderCache.value).Select(spi => provider.CreateItem(context, spi.path, spi.label, spi.path, null, null))); }
private static SearchItem ProcessLine(string line, string searchQuery, SearchProvider provider) { line = line.Trim(); var m = essRx.Match(line); var filePath = m.Groups[1].Value.Replace("\\", "/"); var essmi = new ESSMatchInfo { path = filePath.Replace(Application.dataPath, "Assets").Replace("\\", "/"), lineNumber = int.Parse(m.Groups[2].Value), content = m.Groups[3].Value }; var fsq = searchQuery.Replace("*", ""); var content = Regex.Replace(essmi.content, fsq, "<color=#FFFF00>" + fsq + "</color>", RegexOptions.IgnoreCase); var description = $"{essmi.path} (<b>{essmi.lineNumber}</b>)"; return(provider.CreateItem(essmi.content.GetHashCode().ToString(), content, description, null, essmi)); }
private static SearchItem CreateItem(SearchContext context, SearchProvider provider, string dbName, string assetPath, int itemScore) { var words = context.searchPhrase; var filenameNoExt = Path.GetFileNameWithoutExtension(assetPath).ToLowerInvariant(); if (filenameNoExt.Equals(words, StringComparison.Ordinal)) { itemScore = k_ExactMatchScore; } var filename = Path.GetFileName(assetPath); if (context.options.HasFlag(SearchFlags.Debug) && !string.IsNullOrEmpty(dbName)) { filename += $" ({dbName}, {itemScore})"; } return(provider.CreateItem(context, assetPath, itemScore, filename, null, null, null)); }
static IEnumerable <SearchItem> FetchItems(SearchContext context, SearchProvider provider) { var options = FindOptions.Words | FindOptions.Regex | FindOptions.Glob; if (context.wantsMore) { options |= FindOptions.Packages | FindOptions.Fuzzy; } foreach (var e in Search(context, provider, options)) { yield return(provider.CreateItem(context, e.path, e.score, #if true//DEBUG_FIND_PROVIDER $"{e.path} ({(e.score & (int)FindOptions.CustomRange) >> 17}, {(FindOptions)(e.score & (int)FindOptions.All)})", #else null, #endif null, null, null)); } }
static IEnumerator SearchIndexes(string searchQuery, SearchContext context, SearchProvider provider, ImageDatabase db) { var query = s_QueryEngine.Parse(searchQuery); // var filterNodes = GetFilterNodes(query.evaluationGraph); var scoreModifiers = new List <Func <ImageData, int, ImageDatabase, int> >(); // foreach (var filterNode in filterNodes) // { // switch (filterNode.filterId) // { // case "color": // { // var paramColor = GetColorFromParameter(filterNode.paramValue); // scoreModifiers.Add(GetColorScoreModifier(paramColor)); // break; // } // case "hist": // { // var paramHist = GetHistogramFromParameter(filterNode.paramValue); // scoreModifiers.Add(GetHistogramScoreModifier(paramHist)); // break; // } // } // } var filteredImageData = query.Apply(db.imagesData); foreach (var data in filteredImageData) { var score = 0; foreach (var scoreModifier in scoreModifiers) { score = scoreModifier(data, score, db); } var assetPath = db.GetAssetPath(data.guid); var name = Path.GetFileNameWithoutExtension(assetPath); yield return(provider.CreateItem(context, assetPath, score, name, null, null, null)); } }
private static IEnumerator SearchIndexes(string searchQuery, SearchContext context, SearchProvider provider, SearchDatabase db, int scoreModifier = 0) { while (db.index == null) { yield return(null); } // Search index var index = db.index; while (!index.IsReady()) { yield return(null); } yield return(index.Search(searchQuery.ToLowerInvariant()).Select(e => { var itemScore = e.score + scoreModifier; return provider.CreateItem(context, e.id, itemScore, null, null, null, index.GetDocument(e.index)); })); }
static SearchItem CreateItem(SearchContext context, SearchProvider provider, AssetDocument doc, int score) { var label = doc.name_en_US; if (purchasePackageIds != null && purchasePackageIds.Contains(doc.id)) { label += " (Owned)"; } else if (doc.price_USD == 0) { label += " (Free)"; } var description = $"{doc.publisher} - {doc.category_slug}"; var item = provider.CreateItem(context, doc.id, score, label, description, null, doc); item.options &= ~SearchItemOptions.FuzzyHighlight; item.options &= ~SearchItemOptions.Highlight; doc.productDetail = null; doc.url = $"https://assetstore.unity.com/packages/{doc.category_slug}/{doc.id}"; return(item); }
static SearchItem CreateItem(SearchContext context, SearchProvider provider, AssetDocument doc, int score) { var priceStr = ""; if (purchasePackageIds != null && purchasePackageIds.Contains(doc.id)) { priceStr = "Owned"; } else { priceStr = doc.price_USD == 0 ? "Free" : $"{doc.price_USD:0.00}$"; } var description = $"{doc.publisher} - {doc.category_slug} - <color=#F6B93F>{priceStr}</color>"; #if QUICKSEARCH_DEBUG description += $" id: {doc.id}"; #endif var item = provider.CreateItem(context, doc.id, score, doc.name_en_US, description, null, doc); doc.productDetail = null; doc.url = $"https://assetstore.unity.com/packages/{doc.category_slug}/{doc.id}"; return(item); }