# Search

> Runs a search query in the index.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor.Search](/engine/6000.7/script-reference/unityeditor/search.md)
* **Assembly:** UnityEditor

## Search(string, int, int)

Runs a search query in the index.

```csharp
public virtual IEnumerable<SearchResult> Search(string query, int maxScore = 2147483647, int patternMatchLimit = 2999)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Search query to look for. If if matches any of the indexed variations, a result is returned.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Maximum match score of any matched Search Result. See [SearchResult.score](/engine/6000.7/script-reference/unityeditor/search/searchresult/score.md).**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Maximum number of matched Search Results that can be returned. See [SearchResult](/engine/6000.7/script-reference/unityeditor/search/searchresult.md).

### Returns

| Type                                                                                                          | Description                                                |
| ------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| [IEnumerable\<SearchResult>](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1) | Returns a collection of Search Results matching the query. |

### Examples

```csharp
using System.Linq;
using UnityEditor;
using UnityEditor.Search;
using UnityEngine;

static class Example_SearchIndexer_Search
{
    [MenuItem("Examples/SearchIndexer/Search")]
    public static void Run()
    {
        var si = new SearchIndexer("SearchIndexerExample", FileUtil.GetUniqueTempPathInProject());
        si.Start();

        // Index some documents and properties
        si.AddProperty("color", "red", si.AddDocument("RGB 55"));
        si.AddProperty("color", "reddish", si.AddDocument("RGB 45"));
        si.AddProperty("color", "yellow", si.AddDocument("RGB 66"));

        si.Finish(() =>
        {
            // Search document with property color=red*
            var results = si.Search("color:red").ToList();
            Debug.Assert(results.Count == 2);
            if (results.Count > 0)
                Debug.Log(string.Join(", ", results.Select(r => $"{r.id} [{r.score}]")));
            // Dispose of the SearchIndexer when you are done with it.
            si.Dispose();
        });
    }
}
```

## Search(SearchContext, SearchProvider, int, int)

Runs a search query in the index.

```csharp
public virtual IEnumerable<SearchResult> Search(SearchContext context, SearchProvider provider, int maxScore = 2147483647, int patternMatchLimit = 2999)
```

### Parameters

**** (\[SearchContext]\(/engine/6000.7/script-reference/unityeditor/search/searchcontext)): The search context on which the query is applied.**** (\[SearchProvider]\(/engine/6000.7/script-reference/unityeditor/search/searchprovider)): The search provider that initiated the search.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Maximum match score of any matched Search Result. See [SearchResult.score](/engine/6000.7/script-reference/unityeditor/search/searchresult/score.md).**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Maximum number of matched Search Results that can be returned. See [SearchResult](/engine/6000.7/script-reference/unityeditor/search/searchresult.md).

### Returns

| Type                                                                                                          | Description                                                |
| ------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| [IEnumerable\<SearchResult>](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1) | Returns a collection of Search Results matching the query. |

### Examples

```csharp
using System.Linq;
using UnityEditor;
using UnityEditor.Search;
using UnityEngine;

static class Example_SearchIndexer_Search
{
    [MenuItem("Examples/SearchIndexer/Search")]
    public static void Run()
    {
        var si = new SearchIndexer("SearchIndexerExample", FileUtil.GetUniqueTempPathInProject());
        si.Start();

        // Index some documents and properties
        si.AddProperty("color", "red", si.AddDocument("RGB 55"));
        si.AddProperty("color", "reddish", si.AddDocument("RGB 45"));
        si.AddProperty("color", "yellow", si.AddDocument("RGB 66"));

        si.Finish(() =>
        {
            // Search document with property color=red*
            var results = si.Search("color:red").ToList();
            Debug.Assert(results.Count == 2);
            if (results.Count > 0)
                Debug.Log(string.Join(", ", results.Select(r => $"{r.id} [{r.score}]")));
            // Dispose of the SearchIndexer when you are done with it.
            si.Dispose();
        });
    }
}
```

## Search(string, SearchContext, SearchProvider, int, int)

Runs a search query in the index.

```csharp
public virtual IEnumerable<SearchResult> Search(string query, SearchContext context, SearchProvider provider, int maxScore = 2147483647, int patternMatchLimit = 2999)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Search query to look for. If if matches any of the indexed variations, a result is returned.**** (\[SearchContext]\(/engine/6000.7/script-reference/unityeditor/search/searchcontext)): The search context on which the query is applied.**** (\[SearchProvider]\(/engine/6000.7/script-reference/unityeditor/search/searchprovider)): The search provider that initiated the search.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Maximum match score of any matched Search Result. See [SearchResult.score](/engine/6000.7/script-reference/unityeditor/search/searchresult/score.md).**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Maximum number of matched Search Results that can be returned. See [SearchResult](/engine/6000.7/script-reference/unityeditor/search/searchresult.md).

### Returns

| Type                                                                                                          | Description                                                |
| ------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| [IEnumerable\<SearchResult>](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1) | Returns a collection of Search Results matching the query. |

### Examples

```csharp
using System.Linq;
using UnityEditor;
using UnityEditor.Search;
using UnityEngine;

static class Example_SearchIndexer_Search
{
    [MenuItem("Examples/SearchIndexer/Search")]
    public static void Run()
    {
        var si = new SearchIndexer("SearchIndexerExample", FileUtil.GetUniqueTempPathInProject());
        si.Start();

        // Index some documents and properties
        si.AddProperty("color", "red", si.AddDocument("RGB 55"));
        si.AddProperty("color", "reddish", si.AddDocument("RGB 45"));
        si.AddProperty("color", "yellow", si.AddDocument("RGB 66"));

        si.Finish(() =>
        {
            // Search document with property color=red*
            var results = si.Search("color:red").ToList();
            Debug.Assert(results.Count == 2);
            if (results.Count > 0)
                Debug.Log(string.Join(", ", results.Select(r => $"{r.id} [{r.score}]")));
            // Dispose of the SearchIndexer when you are done with it.
            si.Dispose();
        });
    }
}
```
