示例#1
0
            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))));
                }
            }
示例#2
0
 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));
     }
 }
示例#3
0
    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");
    }
示例#4
0
        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));
            }));
        }
示例#5
0
            private static IEnumerable <SearchItem> 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));
                    }
                }

                var indexReady = fileIndexer.IsReady();

                if (indexReady)
                {
                    if (filter.IndexOfAny(k_InvalidIndexedChars) == -1)
                    {
                        foreach (var item in SearchIndex(fileIndexer, filter, searchPackages, provider))
                        {
                            yield return(item);
                        }
                        if (!context.wantsMore)
                        {
                            yield break;
                        }
                    }
                }

                if (!searchPackages)
                {
                    if (!filter.Contains("a:assets"))
                    {
                        filter = "a:assets " + filter;
                    }
                }

                foreach (var assetEntry in AssetDatabase.FindAssets(filter).Select(AssetDatabase.GUIDToAssetPath).Select(path => provider.CreateItem(path, Path.GetFileName(path))))
                {
                    yield return(assetEntry);
                }

                if (context.searchQuery.Contains('*'))
                {
                    var safeFilter = string.Join("_", context.searchQuery.Split(k_InvalidSearchFileChars));
                    foreach (var fileEntry in Directory.EnumerateFiles(Application.dataPath, safeFilter, SearchOption.AllDirectories)
                             .Select(path => provider.CreateItem(path.Replace(Application.dataPath, "Assets").Replace("\\", "/"),
                                                                 Path.GetFileName(path))))
                    {
                        yield return(fileEntry);
                    }
                }

                if (!indexReady)
                {
                    // Indicate to the user that we are still building the index.
                    while (!fileIndexer.IsReady())
                    {
                        yield return(null);
                    }

                    foreach (var item in SearchIndex(fileIndexer, filter, searchPackages, provider))
                    {
                        yield return(item);
                    }
                }
            }