Class SearchProvider
SearchProvider manages search for specific type of items and manages thumbnails, description and subfilters, etc.
Namespace: Unity.QuickSearch
Syntax
public class SearchProvider
Constructors
SearchProvider(String, String)
Declaration
public SearchProvider(string id, string displayName = null)
Parameters
Type | Name | Description |
---|---|---|
String | id | |
String | displayName |
Fields
active
Indicates if the provider is active or not. Inactive providers are completely ignored by the search service. The active state can be toggled in the search settings.
Declaration
public bool active
Field Value
Type | Description |
---|---|
Boolean |
fetchDescription
Handler to provider an async description for an item. Will be called when the item is about to be displayed. Allows a plugin provider to only fetch long description when they are needed.
Declaration
public Func<SearchItem, SearchContext, string> fetchDescription
Field Value
Type | Description |
---|---|
Func<SearchItem, SearchContext, String> |
fetchItems
MANDATORY: Handler to get items for a given search context. The return value is an object that can be of type IEnumerable or IEnumerator. The enumeration of those objects should return SearchItems.
Declaration
public Func<SearchContext, List<SearchItem>, SearchProvider, object> fetchItems
Field Value
Type | Description |
---|---|
Func<SearchContext, List<SearchItem>, SearchProvider, Object> |
fetchKeywords
Provider can return a list of words that will help the user complete his search query
Declaration
public Action<SearchContext, string, List<string>> fetchKeywords
Field Value
Type | Description |
---|---|
Action<SearchContext, String, List<String>> |
fetchLabel
Handler used to fetch and format the label of a search item.
Declaration
public Func<SearchItem, SearchContext, string> fetchLabel
Field Value
Type | Description |
---|---|
Func<SearchItem, SearchContext, String> |
fetchPreview
Similar to fetchThumbnail, fetchPreview usually returns a bigger preview. The QuickSearch UI will progressively show one preview each frame, preventing the UI to block if many preview needs to be generated at the same time.
Declaration
public Func<SearchItem, SearchContext, Vector2, FetchPreviewOptions, Texture2D> fetchPreview
Field Value
Type | Description |
---|---|
Func<SearchItem, SearchContext, Vector2, FetchPreviewOptions, Texture2D> |
fetchThumbnail
Handler to provider an async thumbnail for an item. Will be called when the item is about to be displayed. Compared to preview a thumbnail should be small and returned as fast as possible. Use fetchPreview if you want to generate a preview that is bigger and slower to return. Allows a plugin provider to only fetch/generate preview when they are needed.
Declaration
public Func<SearchItem, SearchContext, Texture2D> fetchThumbnail
Field Value
Type | Description |
---|---|
Func<SearchItem, SearchContext, Texture2D> |
filterId
Text token use to "filter" a provider (ex: "me:", "p:", "s:")
Declaration
public string filterId
Field Value
Type | Description |
---|---|
String |
isEnabledForContextualSearch
Called when quicksearch is invoked in "contextual mode". If you return true it means the provider is enabled for this search context.
Declaration
public Func<bool> isEnabledForContextualSearch
Field Value
Type | Description |
---|---|
Func<Boolean> |
isExplicitProvider
This provider is only active when specified explicitly using his filterId
Declaration
public bool isExplicitProvider
Field Value
Type | Description |
---|---|
Boolean |
name
Unique id of the provider.
Declaration
public NameEntry name
Field Value
Type | Description |
---|---|
NameEntry |
onDisable
Called when the QuickSearchWindow is closed. Allow the Provider to release cached resources.
Declaration
public Action onDisable
Field Value
Type | Description |
---|---|
Action |
onEnable
Called when the QuickSearchWindow is opened. Allow the Provider to perform some caching.
Declaration
public Action onEnable
Field Value
Type | Description |
---|---|
Action |
priority
Hint to sort the Provider. Affect the order of search results and the order in which provider are shown in the FilterWindow.
Declaration
public int priority
Field Value
Type | Description |
---|---|
Int32 |
showDetails
Indicates if the provider can show additional details or not.
Declaration
public bool showDetails
Field Value
Type | Description |
---|---|
Boolean |
startDrag
If implemented, it means the item supports drag. It is up to the SearchProvider to properly setup the DragAndDrop manager.
Declaration
public Action<SearchItem, SearchContext> startDrag
Field Value
Type | Description |
---|---|
Action<SearchItem, SearchContext> |
subCategories
List of subfilters that will be visible in the FilterWindow for a given SearchProvider (see AssetProvider for an example).
Declaration
public List<NameEntry> subCategories
Field Value
Type | Description |
---|---|
List<NameEntry> |
trackSelection
Called when the selection changed and can be tracked.
Declaration
public Action<SearchItem, SearchContext> trackSelection
Field Value
Type | Description |
---|---|
Action<SearchItem, SearchContext> |
Properties
avgTime
Average time it takes to query that provider.
Declaration
public double avgTime { get; }
Property Value
Type | Description |
---|---|
Double |
Methods
CreateItem(String, Int32, String, String, Texture2D, Object)
Helper function to create a new search item for the current provider.
Declaration
public SearchItem CreateItem(string id, int score, string label, string description, Texture2D thumbnail, object data)
Parameters
Type | Name | Description |
---|---|---|
String | id | Unique id of the search item. This is used to remove duplicates to the user view. |
Int32 | score | Score of the search item. The score is used to sort all the result per provider. Lower score are shown first. |
String | label | The search item label is displayed on the first line of the search item UI widget. |
String | description | The search item description is displayed on the second line of the search item UI widget. |
Texture2D | thumbnail | The search item thumbnail is displayed left to the item label and description as a preview. |
Object | data | User data used to recover more information about a search item. Generally used in fetchLabel, fetchDescription, etc. |
Returns
Type | Description |
---|---|
SearchItem | The newly created search item attached to the current search provider. |
CreateItem(String, String, String, Texture2D, Object)
Create a Search item that will be bound to the SeaechProvider.
Declaration
public SearchItem CreateItem(string id, string label = null, string description = null, Texture2D thumbnail = null, object data = null)
Parameters
Type | Name | Description |
---|---|---|
String | id | Unique id of the search item. This is used to remove duplicates to the user view. |
String | label | The search item label is displayed on the first line of the search item UI widget. |
String | description | The search item description is displayed on the second line of the search item UI widget. |
Texture2D | thumbnail | The search item thumbnail is displayed left to the item label and description as a preview. |
Object | data | User data used to recover more information about a search item. Generally used in fetchLabel, fetchDescription, etc. |
Returns
Type | Description |
---|---|
SearchItem | New SearchItem |
MatchSearchGroups(SearchContext, String, Boolean)
Helper function to match a string against the SearchContext. This will try to match the search query against each tokens of content (similar to the AddComponent menu workflow)
Declaration
public static bool MatchSearchGroups(SearchContext context, string content, bool useLowerTokens = false)
Parameters
Type | Name | Description |
---|---|---|
SearchContext | context | Search context containing the searchQuery that we try to match. |
String | content | String content that will be tokenized and use to match the search query. |
Boolean | useLowerTokens | Perform matching ignoring casing. |
Returns
Type | Description |
---|---|
Boolean | Has a match occurred. |