Class SearchService
Principal Quick Search API to initiate searches and fetch results.
Namespace: UnityEditor.Search
Syntax
public static class SearchService
Properties
OrderedProviders
Returns the list of providers sorted by priority.
Declaration
public static IEnumerable<SearchProvider> OrderedProviders { get; }
Property Value
Type | Description |
---|---|
IEnumerable<SearchProvider> |
Providers
Returns the list of all providers (active or not)
Declaration
public static List<SearchProvider> Providers { get; }
Property Value
Type | Description |
---|---|
List<SearchProvider> |
Methods
CreateContext(IEnumerable<String>, String, SearchFlags)
Create context from a list of provider id.
Declaration
public static SearchContext CreateContext(IEnumerable<string> providerIds, string searchText = "", SearchFlags flags = SearchFlags.Sorted)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<String> | providerIds | List of provider id |
String | searchText | Search Query |
SearchFlags | flags | Options defining how the query will be performed |
Returns
Type | Description |
---|---|
SearchContext | New SearchContext |
CreateContext(IEnumerable<SearchProvider>, String, SearchFlags)
Create context from a list of providers.
Declaration
public static SearchContext CreateContext(IEnumerable<SearchProvider> providers, string searchText = "", SearchFlags flags = SearchFlags.Sorted)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<SearchProvider> | providers | List of providers |
String | searchText | Search Query |
SearchFlags | flags | Options defining how the query will be performed |
Returns
Type | Description |
---|---|
SearchContext | New SearchContext |
CreateContext(String)
Declaration
public static SearchContext CreateContext(string searchText)
Parameters
Type | Name | Description |
---|---|---|
String | searchText |
Returns
Type | Description |
---|---|
SearchContext |
CreateContext(String, String, SearchFlags)
Create a search context for a single search provider.
Declaration
public static SearchContext CreateContext(string providerId, string searchText = "", SearchFlags flags = SearchFlags.Sorted)
Parameters
Type | Name | Description |
---|---|---|
String | providerId | Search provider ID string (such as asset, scene, find, etc.) |
String | searchText | Initial search text to be used to evaluate the query. |
SearchFlags | flags | Additional search options to be used for the query evaluation. |
Returns
Type | Description |
---|---|
SearchContext | The newly created search context. You need to call Dispose on the SearchContext when you are done using it for queries. |
CreateContext(String, SearchFlags)
Create a search context with all active providers.
Declaration
public static SearchContext CreateContext(string searchText, SearchFlags flags)
Parameters
Type | Name | Description |
---|---|---|
String | searchText | |
SearchFlags | flags |
Returns
Type | Description |
---|---|
SearchContext |
CreateContext(SearchProvider, String)
Create a search context with a single search provider.
Declaration
public static SearchContext CreateContext(SearchProvider provider, string searchText = "")
Parameters
Type | Name | Description |
---|---|---|
SearchProvider | provider | |
String | searchText |
Returns
Type | Description |
---|---|
SearchContext |
CreateIndex(in String, in IndexingOptions, IEnumerable<String>, IEnumerable<String>, IEnumerable<String>, Action<String, String, Action>)
Create a new index and callback user code to indicate that the indexing is finished.
Declaration
public static void CreateIndex(in string name, in IndexingOptions options, IEnumerable<string> roots, IEnumerable<string> includes, IEnumerable<string> excludes, Action<string, string, Action> onIndexReady)
Parameters
Type | Name | Description |
---|---|---|
String | name | Unique name of the index to be used. |
IndexingOptions | options | |
IEnumerable<String> | roots | |
IEnumerable<String> | includes | |
IEnumerable<String> | excludes | |
Action<String, String, Action> | onIndexReady | Callback invoked when the new search index is ready to be used. |
EnumerateDatabases()
Declaration
public static IEnumerable<ISearchDatabase> EnumerateDatabases()
Returns
Type | Description |
---|---|
IEnumerable<ISearchDatabase> |
GetAction(SearchProvider, String)
Returns the search action data for a given provider and search action id.
Declaration
public static SearchAction GetAction(SearchProvider provider, string actionId)
Parameters
Type | Name | Description |
---|---|---|
SearchProvider | provider | Provider to lookup |
String | actionId | Unique action ID within the provider. |
Returns
Type | Description |
---|---|
SearchAction | The matching action |
GetActiveProviders()
Declaration
public static IEnumerable<SearchProvider> GetActiveProviders()
Returns
Type | Description |
---|---|
IEnumerable<SearchProvider> |
GetItems(SearchContext, SearchFlags)
Initiate a search and return all search items matching the search context. Other items can be found later using the asynchronous searches.
Declaration
public static List<SearchItem> GetItems(SearchContext context, SearchFlags options = SearchFlags.Sorted)
Parameters
Type | Name | Description |
---|---|---|
SearchContext | context | The current search context |
SearchFlags | options | Options defining how the query will be performed |
Returns
Type | Description |
---|---|
List<SearchItem> | A list of search items matching the search query. |
GetProvider(String)
Returns the data of a search provider given its ID.
Declaration
public static SearchProvider GetProvider(string providerId)
Parameters
Type | Name | Description |
---|---|---|
String | providerId | Unique ID of the provider |
Returns
Type | Description |
---|---|
SearchProvider | The matching provider |
IsIndexReady(String)
Checks if a search index is ready to be used.
Declaration
public static bool IsIndexReady(string name)
Parameters
Type | Name | Description |
---|---|---|
String | name | Name or path of the search index to be checked. Pass null if you want to check all available indexes |
Returns
Type | Description |
---|---|
Boolean |
Refresh()
Clears everything and reloads all search providers.
Declaration
public static void Refresh()
Remarks
Use with care. Useful for unit tests.
RefreshWindows()
Refreshes all open windows.
Declaration
public static void RefreshWindows()
Request(String, Action<SearchContext, IEnumerable<SearchItem>>, Action<SearchContext>, SearchFlags)
Execute a search request and callback for every incoming items and when the search is completed. This will create a new search context that will be Disposed when the request is finished.
Declaration
public static void Request(string searchText, Action<SearchContext, IEnumerable<SearchItem>> onIncomingItems, Action<SearchContext> onSearchCompleted, SearchFlags options = SearchFlags.None)
Parameters
Type | Name | Description |
---|---|---|
String | searchText | |
Action<SearchContext, IEnumerable<SearchItem>> | onIncomingItems | |
Action<SearchContext> | onSearchCompleted | |
SearchFlags | options |
Request(String, Action<SearchContext, IList<SearchItem>>, SearchFlags)
Execute a search request and callback when the search is completed. This will create a new search context that will be Disposed when the request is finished.
Declaration
public static void Request(string searchText, Action<SearchContext, IList<SearchItem>> onSearchCompleted, SearchFlags options = SearchFlags.None)
Parameters
Type | Name | Description |
---|---|---|
String | searchText | |
Action<SearchContext, IList<SearchItem>> | onSearchCompleted | |
SearchFlags | options |
Request(String, SearchFlags)
Run a query on all active providers.
Declaration
public static ISearchList Request(string searchText, SearchFlags options = SearchFlags.None)
Parameters
Type | Name | Description |
---|---|---|
String | searchText | Search query to execute. |
SearchFlags | options |
Returns
Type | Description |
---|---|
ISearchList |
Request(SearchContext, Action<SearchContext, IEnumerable<SearchItem>>, Action<SearchContext>, SearchFlags)
Execute a search request and callback for every incoming items and when the search is completed. The user is responsible for disposing of the search context.
Declaration
public static void Request(SearchContext context, Action<SearchContext, IEnumerable<SearchItem>> onIncomingItems, Action<SearchContext> onSearchCompleted, SearchFlags options = SearchFlags.None)
Parameters
Type | Name | Description |
---|---|---|
SearchContext | context | |
Action<SearchContext, IEnumerable<SearchItem>> | onIncomingItems | |
Action<SearchContext> | onSearchCompleted | |
SearchFlags | options |
Request(SearchContext, Action<SearchContext, IList<SearchItem>>, SearchFlags)
Execute a search request and callback when the search is completed. The user is responsible for disposing of the search context.
Declaration
public static void Request(SearchContext context, Action<SearchContext, IList<SearchItem>> onSearchCompleted, SearchFlags options = SearchFlags.None)
Parameters
Type | Name | Description |
---|---|---|
SearchContext | context | |
Action<SearchContext, IList<SearchItem>> | onSearchCompleted | |
SearchFlags | options |
Request(SearchContext, SearchFlags)
Execute a search request that will fetch search results asynchronously.
Declaration
public static ISearchList Request(SearchContext context, SearchFlags options = SearchFlags.None)
Parameters
Type | Name | Description |
---|---|---|
SearchContext | context | Search context used to track asynchronous request. |
SearchFlags | options | Options defining how the query will be performed |
Returns
Type | Description |
---|---|
ISearchList | Asynchronous list of search items. |
SetActive(String, Boolean)
Activate or deactivate a search provider. Call Refresh after this to take effect on the next search.
Declaration
public static void SetActive(string providerId, bool active = true)
Parameters
Type | Name | Description |
---|---|---|
String | providerId | Provider id to activate or deactivate |
Boolean | active | Activation state |
ShowContextual(String[])
Open QuickSearch in contextual mode enabling only the providers specified.
Declaration
public static ISearchView ShowContextual(params string[] providerIds)
Parameters
Type | Name | Description |
---|---|---|
String[] | providerIds | List of provider ids to enabled for QuickSearch |
Returns
Type | Description |
---|---|
ISearchView | Returns the QuickSearch window. |
ShowObjectPicker(Action<Object, Boolean>, Action<Object>, String, String, Type, Single, Single, SearchFlags)
Use Quick Search to as an object picker to select any object based on the specified filter type.
Declaration
public static ISearchView ShowObjectPicker(Action<Object, bool> selectHandler, Action<Object> trackingHandler, string searchText, string typeName, Type filterType, float defaultWidth = 850F, float defaultHeight = 539F, SearchFlags flags = SearchFlags.None)
Parameters
Type | Name | Description |
---|---|---|
Action<Object, Boolean> | selectHandler | Callback to trigger when a user selects an item. |
Action<Object> | trackingHandler | Callback to trigger when the user is modifying QuickSearch selection (i.e. tracking the currently selected item) |
String | searchText | Initial search text for QuickSearch. |
String | typeName | Type name of the object to select. Can be used to replace filterType. |
Type | filterType | Type of the object to select. |
Single | defaultWidth | Initial width of the window. |
Single | defaultHeight | Initial height of the window. |
SearchFlags | flags | Options flags modifying how the Search window will be opened. |
Returns
Type | Description |
---|---|
ISearchView | Returns the QuickSearch window. |
ShowPicker(SearchContext, Action<SearchItem, Boolean>, Action<SearchItem>, Func<SearchItem, Boolean>, IEnumerable<SearchItem>, String, Single, Single, Single, SearchFlags)
Declaration
public static ISearchView ShowPicker(SearchContext context, Action<SearchItem, bool> selectHandler, Action<SearchItem> trackingHandler = null, Func<SearchItem, bool> filterHandler = null, IEnumerable<SearchItem> subset = null, string title = null, float itemSize = 64F, float defaultWidth = 850F, float defaultHeight = 539F, SearchFlags flags = SearchFlags.None)
Parameters
Type | Name | Description |
---|---|---|
SearchContext | context | |
Action<SearchItem, Boolean> | selectHandler | |
Action<SearchItem> | trackingHandler | |
Func<SearchItem, Boolean> | filterHandler | |
IEnumerable<SearchItem> | subset | |
String | title | |
Single | itemSize | |
Single | defaultWidth | |
Single | defaultHeight | |
SearchFlags | flags |
Returns
Type | Description |
---|---|
ISearchView |
ShowPicker(SearchViewState)
Open and show the Search Picker window.
Declaration
public static ISearchView ShowPicker(SearchViewState viewState)
Parameters
Type | Name | Description |
---|---|---|
SearchViewState | viewState | View parameters |
Returns
Type | Description |
---|---|
ISearchView | Returns the newly create search view instance. |
ShowWindow(SearchContext, String, Single, Single, Boolean, Boolean, Boolean, Boolean)
Creates and open a new instance of Quick Search
Declaration
public static ISearchView ShowWindow(SearchContext context = null, string topic = "Unity", float defaultWidth = 850F, float defaultHeight = 539F, bool saveFilters = true, bool reuseExisting = false, bool multiselect = true, bool dockable = true)
Parameters
Type | Name | Description |
---|---|---|
SearchContext | context | Initial search context of QuickSearch |
String | topic | QuickSearch search topic |
Single | defaultWidth | Initial width of the window. |
Single | defaultHeight | Initial height of the window. |
Boolean | saveFilters | True if user provider filters should be saved for next search session |
Boolean | reuseExisting | If true, try to reuse an already existing instance of QuickSearch. If false will create a new QuickSearch window. |
Boolean | multiselect | True if the search support multi-selection or not. |
Boolean | dockable | If true, creates a dockable QuickSearch Window (that will be closed when an item is activated). If false, it will create a DropDown (borderless, undockable and unmovable) version of QuickSearch. |
Returns
Type | Description |
---|---|
ISearchView | Returns the Quick Search editor window instance. |
ShowWindow(SearchViewState)
Show a search window.
Declaration
public static ISearchView ShowWindow(SearchViewState viewState)
Parameters
Type | Name | Description |
---|---|---|
SearchViewState | viewState | Defines search view parameters for creation |
Returns
Type | Description |
---|---|
ISearchView |