# CreateContext

> Creates context from a list of search provider IDs.

## Definition

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

## CreateContext(IEnumerable\<string>, string, SearchFlags)

Creates context from a list of search provider IDs.

```csharp
public static SearchContext CreateContext(IEnumerable<string> providerIds, string searchText = "", SearchFlags flags = SearchFlags.Default)
```

### Parameters

**** (\[IEnumerable\<string>]\(https\://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1)): List of search provider IDs.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Search Query.**** (\[SearchFlags]\(/engine/6000.7/script-reference/unityeditor/search/searchflags)): Options defining how the query is performed.

### Returns

| Type                                                                                 | Description                  |
| ------------------------------------------------------------------------------------ | ---------------------------- |
| [SearchContext](/engine/6000.7/script-reference/unityeditor/search/searchcontext.md) | Returns a new SearchContext. |

### Examples

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

static class Example_SearchService_CreateContext
{
    [MenuItem("Examples/SearchService/CreateContext")]
    public static void Run()
    {
        using var searchContext = SearchService.CreateContext("scene", "camera");
        using var results = SearchService.Request(searchContext, SearchFlags.Synchronous);
        {
            foreach (var label in results.Select(r => r.GetLabel(searchContext)))
                Debug.Log(label);
        }
    }
}
```

## CreateContext(IEnumerable\<SearchProvider>, string, SearchFlags)

Creates context from a list of search provider IDs.

```csharp
public static SearchContext CreateContext(IEnumerable<SearchProvider> providers, string searchText = "", SearchFlags flags = SearchFlags.Default)
```

### Parameters

**** (\[IEnumerable\<SearchProvider>]\(https\://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1)): List of search providers.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Search Query.**** (\[SearchFlags]\(/engine/6000.7/script-reference/unityeditor/search/searchflags)): Options defining how the query is performed.

### Returns

| Type                                                                                 | Description                  |
| ------------------------------------------------------------------------------------ | ---------------------------- |
| [SearchContext](/engine/6000.7/script-reference/unityeditor/search/searchcontext.md) | Returns a new SearchContext. |

### Examples

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

static class Example_SearchService_CreateContext
{
    [MenuItem("Examples/SearchService/CreateContext")]
    public static void Run()
    {
        using var searchContext = SearchService.CreateContext("scene", "camera");
        using var results = SearchService.Request(searchContext, SearchFlags.Synchronous);
        {
            foreach (var label in results.Select(r => r.GetLabel(searchContext)))
                Debug.Log(label);
        }
    }
}
```

## CreateContext(SearchProvider, string)

Creates context from a list of search provider IDs.

```csharp
public static SearchContext CreateContext(SearchProvider provider, string searchText = "")
```

### Parameters

**** (\[SearchProvider]\(/engine/6000.7/script-reference/unityeditor/search/searchprovider)): Search provider (This search provider does not need to be active or registered).**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Search Query.

### Returns

| Type                                                                                 | Description                  |
| ------------------------------------------------------------------------------------ | ---------------------------- |
| [SearchContext](/engine/6000.7/script-reference/unityeditor/search/searchcontext.md) | Returns a new SearchContext. |

### Examples

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

static class Example_SearchService_CreateContext
{
    [MenuItem("Examples/SearchService/CreateContext")]
    public static void Run()
    {
        using var searchContext = SearchService.CreateContext("scene", "camera");
        using var results = SearchService.Request(searchContext, SearchFlags.Synchronous);
        {
            foreach (var label in results.Select(r => r.GetLabel(searchContext)))
                Debug.Log(label);
        }
    }
}
```

## CreateContext(string, string, SearchFlags)

Creates context from a list of search provider IDs.

```csharp
public static SearchContext CreateContext(string providerId, string searchText = "", SearchFlags flags = SearchFlags.Default)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Unique search provider ID string (i.e. asset, scene, find, etc.)**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Search Query.**** (\[SearchFlags]\(/engine/6000.7/script-reference/unityeditor/search/searchflags)): Options defining how the query is performed.

### Returns

| Type                                                                                 | Description                  |
| ------------------------------------------------------------------------------------ | ---------------------------- |
| [SearchContext](/engine/6000.7/script-reference/unityeditor/search/searchcontext.md) | Returns a new SearchContext. |

### Examples

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

static class Example_SearchService_CreateContext
{
    [MenuItem("Examples/SearchService/CreateContext")]
    public static void Run()
    {
        using var searchContext = SearchService.CreateContext("scene", "camera");
        using var results = SearchService.Request(searchContext, SearchFlags.Synchronous);
        {
            foreach (var label in results.Select(r => r.GetLabel(searchContext)))
                Debug.Log(label);
        }
    }
}
```

## CreateContext(string, SearchFlags)

Creates context from a list of search provider IDs.

```csharp
public static SearchContext CreateContext(string searchText, SearchFlags flags)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Search Query.**** (\[SearchFlags]\(/engine/6000.7/script-reference/unityeditor/search/searchflags)): Options defining how the query is performed.

### Returns

| Type                                                                                 | Description                  |
| ------------------------------------------------------------------------------------ | ---------------------------- |
| [SearchContext](/engine/6000.7/script-reference/unityeditor/search/searchcontext.md) | Returns a new SearchContext. |

### Examples

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

static class Example_SearchService_CreateContext
{
    [MenuItem("Examples/SearchService/CreateContext")]
    public static void Run()
    {
        using var searchContext = SearchService.CreateContext("scene", "camera");
        using var results = SearchService.Request(searchContext, SearchFlags.Synchronous);
        {
            foreach (var label in results.Select(r => r.GetLabel(searchContext)))
                Debug.Log(label);
        }
    }
}
```

## CreateContext(string)

Creates context from a list of search provider IDs.

```csharp
public static SearchContext CreateContext(string searchText)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Search Query.

### Returns

| Type                                                                                 | Description                  |
| ------------------------------------------------------------------------------------ | ---------------------------- |
| [SearchContext](/engine/6000.7/script-reference/unityeditor/search/searchcontext.md) | Returns a new SearchContext. |

### Examples

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

static class Example_SearchService_CreateContext
{
    [MenuItem("Examples/SearchService/CreateContext")]
    public static void Run()
    {
        using var searchContext = SearchService.CreateContext("scene", "camera");
        using var results = SearchService.Request(searchContext, SearchFlags.Synchronous);
        {
            foreach (var label in results.Select(r => r.GetLabel(searchContext)))
                Debug.Log(label);
        }
    }
}
```
