# SearchItem

> Search items are returned by the search provider to show to the user after a search is performed. The search item holds all the data that is used to sort and present the search results. Some members of a SearchItem can be specified in an asynchronous callback (see fetchThumbnail, fetchDescription, etc).

## Definition

* **Type:** Class
* **Namespace:** [UnityEditor.Search](/engine/6000.6/script-reference/unityeditor/search.md)
* **Assembly:** UnityEditor
* **Implements:** [IEquatable\<SearchItem>](https://learn.microsoft.com/dotnet/api/system.iequatable-1), [IComparable\<SearchItem>](https://learn.microsoft.com/dotnet/api/system.icomparable-1), [IComparable](https://learn.microsoft.com/dotnet/api/system.icomparable)

```csharp
public class SearchItem : IEquatable<SearchItem>, IComparable<SearchItem>, IComparable
```

## Remarks

SearchItems are generally created using the [SearchProvider.CreateItem](/engine/6000.6/script-reference/unityeditor/search/searchprovider/createitem.md) function. This example shows how to create a SearchItem with all the members.

## Examples

```csharp
[SearchItemProvider]
internal static SearchProvider CreateProvider()
{
    return new SearchProvider(id, name)
    {
        filterId = "hex:",
        priority = 99999, // put example provider at a low priority
        showDetailsOptions = ShowDetailsOptions.Description | ShowDetailsOptions.Preview,
        fetchItems = (context, items, provider) => FetchItems(context, provider),
        fetchPreview = (item, context, size, options) =>
        {
            return CreateTextureFromColor(item.id, (int)size.x, (int)size.y);
        },
    };
}
```

## Fields

| Value                                                                                       | Description                                                                                                                                      |
| ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| [context](/engine/6000.6/script-reference/unityeditor/search/searchitem/context.md)         | Context used to create that item.                                                                                                                |
| [data](/engine/6000.6/script-reference/unityeditor/search/searchitem/data.md)               | Search provider defined content. It can be used to transport any data to custom search provider handlers (i.e. `fetchDescription`).              |
| [description](/engine/6000.6/script-reference/unityeditor/search/searchitem/description.md) | If no description is provided, SearchProvider.fetchDescription will be called when the item is first displayed.                                  |
| [id](/engine/6000.6/script-reference/unityeditor/search/searchitem/id.md)                   | Unique ID of the search item for the search provider.                                                                                            |
| [label](/engine/6000.6/script-reference/unityeditor/search/searchitem/label.md)             | Display name of the search item.                                                                                                                 |
| [options](/engine/6000.6/script-reference/unityeditor/search/searchitem/options.md)         | Flags that dictate how the search item is displayed and used.                                                                                    |
| [preview](/engine/6000.6/script-reference/unityeditor/search/searchitem/preview.md)         | Large preview of the search item. Usually cached by fetchPreview.                                                                                |
| [provider](/engine/6000.6/script-reference/unityeditor/search/searchitem/provider.md)       | Back pointer to the search provider.                                                                                                             |
| [score](/engine/6000.6/script-reference/unityeditor/search/searchitem/score.md)             | The item relevance score will affect how the item gets sorted by the search provider. Lower scored items have more relevance and are prioritzed. |
| [thumbnail](/engine/6000.6/script-reference/unityeditor/search/searchitem/thumbnail.md)     | If no thumbnail is provided, SearchProvider.fetchThumbnail is called when the item is first displayed.                                           |

## Constructors

| Constructor                                                                                        | Description                                                                                         |
| -------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| [SearchItem(System.String)](/engine/6000.6/script-reference/unityeditor/search/searchitem/ctor.md) | Construct a search item. A search item needs to have at least a unique ID for a given search query. |

## Properties

| Property                                                                          | Description                                                      |
| --------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| [this\[\]](/engine/6000.6/script-reference/unityeditor/search/searchitem/item.md) | Operator used to get an item field value.                        |
| [value](/engine/6000.6/script-reference/unityeditor/search/searchitem/value.md)   | Value set by the search expression system when selecting fields. |

## Static Properties

| Property                                                                        | Description                                                           |
| ------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| [clear](/engine/6000.6/script-reference/unityeditor/search/searchitem/clear.md) | A search item representing none, usually used to clear the selection. |

## Methods

| Method                                                                                            | Description                                                                                                                                                                                                                              |
| ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [CompareTo](/engine/6000.6/script-reference/unityeditor/search/searchitem/compareto.md)           | Check if two SearchItems have the same ID.                                                                                                                                                                                               |
| [Equals](/engine/6000.6/script-reference/unityeditor/search/searchitem/equals.md)                 | Check if two SearchItems have the same ID.                                                                                                                                                                                               |
| [GetDescription](/engine/6000.6/script-reference/unityeditor/search/searchitem/getdescription.md) | Fetch and format description.                                                                                                                                                                                                            |
| [GetFieldCount](/engine/6000.6/script-reference/unityeditor/search/searchitem/getfieldcount.md)   | Returns the amount of field stored in the search item.                                                                                                                                                                                   |
| [GetFieldNames](/engine/6000.6/script-reference/unityeditor/search/searchitem/getfieldnames.md)   | Returns a list of all field names.                                                                                                                                                                                                       |
| [GetFields](/engine/6000.6/script-reference/unityeditor/search/searchitem/getfields.md)           | Enumerate all search items fields.                                                                                                                                                                                                       |
| [GetHashCode](/engine/6000.6/script-reference/unityeditor/search/searchitem/gethashcode.md)       | Default Hash of a SearchItem.                                                                                                                                                                                                            |
| [GetLabel](/engine/6000.6/script-reference/unityeditor/search/searchitem/getlabel.md)             | Fetch and format label.                                                                                                                                                                                                                  |
| [GetPreview](/engine/6000.6/script-reference/unityeditor/search/searchitem/getpreview.md)         | Gets the search item preview if available, otherwise the preview is fetched at this time.                                                                                                                                                |
| [GetThumbnail](/engine/6000.6/script-reference/unityeditor/search/searchitem/getthumbnail.md)     | Gets the search item thumbnail if available, otherwise the thumbnail is fetched at this time. The thumbnail is usually used in list view compared to the grid view.                                                                      |
| [GetValue](/engine/6000.6/script-reference/unityeditor/search/searchitem/getvalue.md)             | Get the default search item value of a given field.                                                                                                                                                                                      |
| [RemoveField](/engine/6000.6/script-reference/unityeditor/search/searchitem/removefield.md)       | Removes an item field.                                                                                                                                                                                                                   |
| [SetField](/engine/6000.6/script-reference/unityeditor/search/searchitem/setfield.md)             | Sets a field value and alias.                                                                                                                                                                                                            |
| [ToObject](/engine/6000.6/script-reference/unityeditor/search/searchitem/toobject.md)             | Returns any valid Unity Object held by the search item.                                                                                                                                                                                  |
| [TryGetField](/engine/6000.6/script-reference/unityeditor/search/searchitem/trygetfield.md)       | Returns an item field if available.                                                                                                                                                                                                      |
| [TryGetValue](/engine/6000.6/script-reference/unityeditor/search/searchitem/trygetvalue.md)       | Returns' a field's value if any. Compared to [SearchItem.TryGetField](/engine/6000.6/script-reference/unityeditor/search/searchitem/trygetfield.md) this method also resolved built-in field such as id, label, description, value, etc. |
