Library/PackageCache/com.unity.quicksearch@1.6.0-preview.8/Editor/SearchService.cs
/// <summary>
/// Initiate a search and return all search items matching the search context. Other items can be found later using the asynchronous searches.
/// </summary>
/// <param name="context">The current search context</param>
/// <param name="options">Options defining how the query will be performed</param>
/// <returns>A list of search items matching the search query.</returns>
Initiate a search and return all search items matching the search context. Other items can be found later using the asynchronous searches.
Initiate a search and return all search items matching the search context . Other items can be found later using the asynchronous searches .
public static List<SearchItem> GetItems(SearchContext context, SearchFlags options = SearchFlags.Default)
        {
            context.sessions.StopAllAsyncSearchSessions();
            context.searchFinishTime = context.searchStartTime = EditorApplication.timeSinceStartup;
            context.sessionEnded -= OnSearchEnded;
            context.sessionEnded += OnSearchEnded;
            #if SHOW_SEARCH_PROGRESS
            if (Progress.Exists(context.progressId))
                Progress.Finish(context.progressId, Progress.Status.Succeeded);
            context.progressId = Progress.Start($"Searching...", options: Progress.Options.Indefinite);
            #endif
            if (options.HasFlag(SearchFlags.WantsMore))
                context.wantsMore = true;
            int fetchProviderCount = 0;
            var allItems = new List<SearchItem>(3);
            #if QUICKSEARCH_DEBUG
            var debugProviderList = context.providers.ToList();
            using (new DebugTimer($"Search get items {String.Join(", ", debugProviderList.Select(p=>p.name.id))} -> {context.searchQuery}"));
            #endif
            foreach (var provider in context.providers)
            {
                try
                {
                    var watch = new System.Diagnostics.Stopwatch();
                    watch.Start();
                    fetchProviderCount++;
                    var iterator = provider.fetchItems(context, allItems, provider);
                    if (iterator != null && options.HasFlag(SearchFlags.Synchronous))
                    {
                        var stackedEnumerator = new StackedEnumerator<SearchItem>(iterator);
                        while (stackedEnumerator.MoveNext())
                        {
                            if (stackedEnumerator.Current != null)
                                allItems.Add(stackedEnumerator.Current);
                        }
                    }
                    else
                    {
                        var session = context.sessions.GetProviderSession(context, provider.name.id);
                        session.Reset(context, iterator, k_MaxFetchTimeMs);
                        session.Start();
                        var sessionEnded = !session.FetchSome(allItems, k_MaxFetchTimeMs);
                        if (options.HasFlag(SearchFlags.FirstBatchAsync))
                            session.SendItems(allItems);
                        if (sessionEnded)
                            session.Stop();
                    }
                    provider.RecordFetchTime(watch.Elapsed.TotalMilliseconds);
                }
                catch (Exception ex)
                {
                    UnityEngine.Debug.LogException(new Exception($"Failed to get fetch {provider.name.displayName} provider items.", ex));
                }
            }
            if (fetchProviderCount == 0)
            {
                OnSearchEnded(context);
                context.sessions.StopAllAsyncSearchSessions();
            }
            if (!options.HasFlag(SearchFlags.Sorted))
                return allItems;
            allItems.Sort(SortItemComparer);
            return allItems.GroupBy(i => i.id).Select(i => i.First()).ToList();
        }
public static List < SearchItem > GetItems ( SearchContext context , SearchFlags options = SearchFlags . Default ) { context . sessions . StopAllAsyncSearchSessions ( ) ; context . searchFinishTime = context . searchStartTime = EditorApplication . timeSinceStartup ; context . sessionEnded -= OnSearchEnded ; context . sessionEnded += OnSearchEnded ; if SHOW_SEARCH_PROGRESS if ( Progress . Exists ( context . progressId ) ) Progress . Finish ( context . progressId , Progress . Status . Succeeded ) ; context . progressId = Progress . Start ( $" Searching... " , options : Progress . Options . Indefinite ) ; endif if ( options . HasFlag ( SearchFlags . WantsMore ) ) context . wantsMore = true ; int fetchProviderCount = 0 ; var allItems = new List < SearchItem > ( 3 ) ; if QUICKSEARCH_DEBUG var debugProviderList = context . providers . ToList ( ) ; using ( new DebugTimer ( $" Search get items  { String . Join ( " " , debugProviderList . Select ( p => p . name . id ) ) }  ->  { context . searchQuery } " ) ) ; endif foreach ( var provider in context . providers ) { try { var watch = new System . Diagnostics . Stopwatch ( ) ; watch . Start ( ) ; fetchProviderCount ++ ; var iterator = provider . fetchItems ( context , allItems , provider ) ; if ( iterator != null && options . HasFlag ( SearchFlags . Synchronous ) ) { var stackedEnumerator = new StackedEnumerator < SearchItem > ( iterator ) ; while ( stackedEnumerator . MoveNext ( ) ) { if ( stackedEnumerator . Current != null ) allItems . Add ( stackedEnumerator . Current ) ; } } else { var session = context . sessions . GetProviderSession ( context , provider . name . id ) ; session . Reset ( context , iterator , k_MaxFetchTimeMs ) ; session . Start ( ) ; var sessionEnded = ! session . FetchSome ( allItems , k_MaxFetchTimeMs ) ; if ( options . HasFlag ( SearchFlags . FirstBatchAsync ) ) session . SendItems ( allItems ) ; if ( sessionEnded ) session . Stop ( ) ; } provider . RecordFetchTime ( watch . Elapsed . TotalMilliseconds ) ; } catch ( Exception ex ) { UnityEngine . Debug . LogException ( new Exception ( $" Failed to get fetch  { provider . name . displayName }  provider items. " , ex ) ) ; } } if ( fetchProviderCount == 0 ) { OnSearchEnded ( context ) ; context . sessions . StopAllAsyncSearchSessions ( ) ; } if ( ! options . HasFlag ( SearchFlags . Sorted ) ) return allItems ; allItems . Sort ( SortItemComparer ) ; return allItems . GroupBy ( i => i . id ) . Select ( i => i . First ( ) ) . ToList ( ) ; }
Initiate a search and return all search items matching the search context.
Initiate a search and return all search items matching the search context .
// Stop all search sessions every time there is a new search.
A list of search items matching the search query.
A list of search items matching the search query .
context
SearchContext
The current search context
The current search context
options
SearchFlags
Options defining how the query will be performed
Options defining how the query will be performed