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)
Create a new SearchProvider
Declaration
public SearchProvider(string id)
Parameters
Type | Name | Description |
---|---|---|
String | id | Search Provider unique id. |
SearchProvider(String, Func<SearchContext, List<SearchItem>, SearchProvider, Object>)
Create a new SearchProvider
Declaration
public SearchProvider(string id, Func<SearchContext, List<SearchItem>, SearchProvider, object> fetchItemsHandler)
Parameters
Type | Name | Description |
---|---|---|
String | id | Search Provider unique id. |
Func<SearchContext, List<SearchItem>, SearchProvider, Object> | fetchItemsHandler | Handler responsible to populate a list of SearchItems according to a query. |
SearchProvider(String, Func<SearchContext, SearchProvider, Object>)
Create a new SearchProvider
Declaration
public SearchProvider(string id, Func<SearchContext, SearchProvider, object> fetchItemsHandler)
Parameters
Type | Name | Description |
---|---|---|
String | id | Search Provider unique id. |
Func<SearchContext, SearchProvider, Object> | fetchItemsHandler | Handler responsible to populate a list of SearchItems according to a query. |
SearchProvider(String, String)
Create a new SearchProvider
Declaration
public SearchProvider(string id, string displayName)
Parameters
Type | Name | Description |
---|---|---|
String | id | Search Provider unique id. |
String | displayName | Provider pretty name, use to display in UI. |
SearchProvider(String, String, Func<SearchContext, List<SearchItem>, SearchProvider, Object>)
Create a new SearchProvider
Declaration
public SearchProvider(string id, string displayName, Func<SearchContext, List<SearchItem>, SearchProvider, object> fetchItemsHandler)
Parameters
Type | Name | Description |
---|---|---|
String | id | Search Provider unique id. |
String | displayName | Provider pretty name, use to display in UI. |
Func<SearchContext, List<SearchItem>, SearchProvider, Object> | fetchItemsHandler | Handler responsible to populate a list of SearchItems according to a query. |
SearchProvider(String, String, Func<SearchContext, SearchProvider, Object>)
Create a new SearchProvider
Declaration
public SearchProvider(string id, string displayName, Func<SearchContext, SearchProvider, object> fetchItemsHandler)
Parameters
Type | Name | Description |
---|---|---|
String | id | Search Provider unique id. |
String | displayName | Provider pretty name, use to display in UI. |
Func<SearchContext, SearchProvider, Object> | fetchItemsHandler | Handler responsible to populate a list of SearchItems according to a query. |
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 quick search 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 |
openContextual
This callback is used to open additional context for a given item.
Declaration
public Func<SearchSelection, Rect, bool> openContextual
Field Value
Type | Description |
---|---|
Func<SearchSelection, Rect, Boolean> |
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 |
showDetailsOptions
Explicitly define details options to be shown
Declaration
public ShowDetailsOptions showDetailsOptions
Field Value
Type | Description |
---|---|
ShowDetailsOptions |
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> |
toObject
Returns any valid Unity object held by the search item.
Declaration
public Func<SearchItem, Type, Object> toObject
Field Value
Type | Description |
---|---|
Func<SearchItem, Type, Object> |
trackSelection
Called when the selection changed and can be tracked.
Declaration
public Action<SearchItem, SearchContext> trackSelection
Field Value
Type | Description |
---|---|
Action<SearchItem, SearchContext> |
Methods
CreateItem(String)
Helper function to create a new search item for the current provider.
Declaration
public SearchItem CreateItem(string id)
Parameters
Type | Name | Description |
---|---|---|
String | id | Unique id of the search item. This is used to remove duplicates to the user view. |
Returns
Type | Description |
---|---|
SearchItem | The newly created search item attached to the current search provider. |
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)
Helper function to create a new search item for the current provider.
Declaration
public SearchItem CreateItem(string id, string label)
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. |
Returns
Type | Description |
---|---|
SearchItem | The newly created search item attached to the current search provider. |
CreateItem(String, String, String, Texture2D, Object)
Helper function to create a new search item for the current provider.
Declaration
public SearchItem CreateItem(string id, 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. |
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(SearchContext, String)
Helper function to create a new search item for the current provider.
Declaration
public SearchItem CreateItem(SearchContext context, string id)
Parameters
Type | Name | Description |
---|---|---|
SearchContext | context | Search context from the query that generates this item. |
String | id | Unique id of the search item. This is used to remove duplicates to the user view. |
Returns
Type | Description |
---|---|
SearchItem | The newly created search item attached to the current search provider. |
CreateItem(SearchContext, String, Int32, String, String, Texture2D, Object)
Helper function to create a new search item for the current provider.
Declaration
public SearchItem CreateItem(SearchContext context, string id, int score, string label, string description, Texture2D thumbnail, object data)
Parameters
Type | Name | Description |
---|---|---|
SearchContext | context | Search context from the query that generates this item. |
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(SearchContext, String, String, String, Texture2D, Object)
Create a Search item that will be bound to the SeaechProvider.
Declaration
public SearchItem CreateItem(SearchContext context, string id, string label, string description, Texture2D thumbnail, object data)
Parameters
Type | Name | Description |
---|---|---|
SearchContext | context | Search context from the query that generates this item. |
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 |