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 <Type> IDX_FetchItems(string searchQuery) { while (!index.IsReady()) { yield return(null); } foreach (var e in index.Search(searchQuery)) { yield return(Type.GetType(e.id)); } }
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); })); }
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)); })); }