# AddProperty

> Adds a property value to the index. A property is specified with a key and a string value. The value will be stored with multiple variations.

## Definition

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

## AddProperty(string, string, int)

Adds a property value to the index. A property is specified with a key and a string value. The value will be stored with multiple variations.

```csharp
public void AddProperty(string key, string value, int documentIndex)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Key used to retrieve the value.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): String value to store in the index.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Document where the indexed value was found.

### Examples

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

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

        // Add properties.
        // These items are given a high score, so they will not be displayed first in the result list.
        si.AddProperty("is", "broken", score: 20, si.AddDocument("Bocument 1"));
        si.AddProperty("is", "broken", score: 30, si.AddDocument("Bocument 4"));
        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.AddProperty("is", "secret", score: -99, si.AddDocument("Top Secret"));

        si.Finish(() =>
        {
            SearchDocuments(si, "Broken documents (Invalid query)", "is=broke", 0);
            SearchDocuments(si, "Broken documents", "is=broken", 2);

            SearchDocuments(si, "Color documents", "color=red", 1);
            SearchDocuments(si, "Color documents", "color:red", 2);
            SearchDocuments(si, "Color documents", "color:yel", 1);

            SearchDocuments(si, "Top documents", "is:secr", 1);
            SearchDocuments(si, "Top documents", "is:secret", 1);
            SearchDocuments(si, "Top documents", "is=secret", 1);

            // Dispose of the SearchIndexer when you are done with it.
            si.Dispose();
        });
    }

    private static void SearchDocuments(SearchIndexer si, string label, string query, int expectedCount)
    {
        var results = si.Search(query).ToList();
        Debug.Assert(results.Count == expectedCount, $"Invalid {label} with {query}, expected {expectedCount} results but got {results.Count}");
        if (results.Count > 0)
            Debug.Log($"{label} ({query}): {string.Join(", ", results.Select(r => $"{r.id} [{r.score}]"))}");
    }
}
```

## AddProperty(string, string, int, int)

Adds a property value to the index. A property is specified with a key and a string value. The value will be stored with multiple variations.

```csharp
public void AddProperty(string key, string value, int score, int documentIndex)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Key used to retrieve the value.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): String value to store in the index.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Relevance score of the word.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Document where the indexed value was found.

### Examples

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

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

        // Add properties.
        // These items are given a high score, so they will not be displayed first in the result list.
        si.AddProperty("is", "broken", score: 20, si.AddDocument("Bocument 1"));
        si.AddProperty("is", "broken", score: 30, si.AddDocument("Bocument 4"));
        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.AddProperty("is", "secret", score: -99, si.AddDocument("Top Secret"));

        si.Finish(() =>
        {
            SearchDocuments(si, "Broken documents (Invalid query)", "is=broke", 0);
            SearchDocuments(si, "Broken documents", "is=broken", 2);

            SearchDocuments(si, "Color documents", "color=red", 1);
            SearchDocuments(si, "Color documents", "color:red", 2);
            SearchDocuments(si, "Color documents", "color:yel", 1);

            SearchDocuments(si, "Top documents", "is:secr", 1);
            SearchDocuments(si, "Top documents", "is:secret", 1);
            SearchDocuments(si, "Top documents", "is=secret", 1);

            // Dispose of the SearchIndexer when you are done with it.
            si.Dispose();
        });
    }

    private static void SearchDocuments(SearchIndexer si, string label, string query, int expectedCount)
    {
        var results = si.Search(query).ToList();
        Debug.Assert(results.Count == expectedCount, $"Invalid {label} with {query}, expected {expectedCount} results but got {results.Count}");
        if (results.Count > 0)
            Debug.Log($"{label} ({query}): {string.Join(", ", results.Select(r => $"{r.id} [{r.score}]"))}");
    }
}
```

## AddProperty(string, string, int, bool)

Adds a property value to the index. A property is specified with a key and a string value. The value will be stored with multiple variations.

```csharp
public void AddProperty(string key, string value, int documentIndex, bool saveKeyword)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Key used to retrieve the value.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): String value to store in the index.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Document where the indexed value was found.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Indicates if we store this key in the keyword registry of the index. See GetKeywords.

### Examples

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

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

        // Add properties.
        // These items are given a high score, so they will not be displayed first in the result list.
        si.AddProperty("is", "broken", score: 20, si.AddDocument("Bocument 1"));
        si.AddProperty("is", "broken", score: 30, si.AddDocument("Bocument 4"));
        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.AddProperty("is", "secret", score: -99, si.AddDocument("Top Secret"));

        si.Finish(() =>
        {
            SearchDocuments(si, "Broken documents (Invalid query)", "is=broke", 0);
            SearchDocuments(si, "Broken documents", "is=broken", 2);

            SearchDocuments(si, "Color documents", "color=red", 1);
            SearchDocuments(si, "Color documents", "color:red", 2);
            SearchDocuments(si, "Color documents", "color:yel", 1);

            SearchDocuments(si, "Top documents", "is:secr", 1);
            SearchDocuments(si, "Top documents", "is:secret", 1);
            SearchDocuments(si, "Top documents", "is=secret", 1);

            // Dispose of the SearchIndexer when you are done with it.
            si.Dispose();
        });
    }

    private static void SearchDocuments(SearchIndexer si, string label, string query, int expectedCount)
    {
        var results = si.Search(query).ToList();
        Debug.Assert(results.Count == expectedCount, $"Invalid {label} with {query}, expected {expectedCount} results but got {results.Count}");
        if (results.Count > 0)
            Debug.Log($"{label} ({query}): {string.Join(", ", results.Select(r => $"{r.id} [{r.score}]"))}");
    }
}
```

## AddProperty(string, string, int, int, bool)

Adds a property value to the index. A property is specified with a key and a string value. The value will be stored with multiple variations.

```csharp
public void AddProperty(string key, string value, int score, int documentIndex, bool saveKeyword)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Key used to retrieve the value.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): String value to store in the index.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Relevance score of the word.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Document where the indexed value was found.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Indicates if we store this key in the keyword registry of the index. See GetKeywords.

### Examples

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

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

        // Add properties.
        // These items are given a high score, so they will not be displayed first in the result list.
        si.AddProperty("is", "broken", score: 20, si.AddDocument("Bocument 1"));
        si.AddProperty("is", "broken", score: 30, si.AddDocument("Bocument 4"));
        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.AddProperty("is", "secret", score: -99, si.AddDocument("Top Secret"));

        si.Finish(() =>
        {
            SearchDocuments(si, "Broken documents (Invalid query)", "is=broke", 0);
            SearchDocuments(si, "Broken documents", "is=broken", 2);

            SearchDocuments(si, "Color documents", "color=red", 1);
            SearchDocuments(si, "Color documents", "color:red", 2);
            SearchDocuments(si, "Color documents", "color:yel", 1);

            SearchDocuments(si, "Top documents", "is:secr", 1);
            SearchDocuments(si, "Top documents", "is:secret", 1);
            SearchDocuments(si, "Top documents", "is=secret", 1);

            // Dispose of the SearchIndexer when you are done with it.
            si.Dispose();
        });
    }

    private static void SearchDocuments(SearchIndexer si, string label, string query, int expectedCount)
    {
        var results = si.Search(query).ToList();
        Debug.Assert(results.Count == expectedCount, $"Invalid {label} with {query}, expected {expectedCount} results but got {results.Count}");
        if (results.Count > 0)
            Debug.Log($"{label} ({query}): {string.Join(", ", results.Select(r => $"{r.id} [{r.score}]"))}");
    }
}
```

## AddProperty(string, string, int, bool, bool)

Adds a property value to the index. A property is specified with a key and a string value. The value will be stored with multiple variations.

> **Warning:**
>
> **Deprecated.** AddProperty with variations is no longer supported. Variations are handled automatically internally. Please use AddProperty(string name, string value, int score, int documentIndex, bool saveKeyword)

```csharp
public void AddProperty(string key, string value, int documentIndex, bool saveKeyword = false, bool exact = true)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Key used to retrieve the value.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): String value to store in the index.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Document where the indexed value was found.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Indicates if we store this key in the keyword registry of the index. See GetKeywords.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): If true, index stores an exact match entry for this word.

### Examples

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

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

        // Add properties.
        // These items are given a high score, so they will not be displayed first in the result list.
        si.AddProperty("is", "broken", score: 20, si.AddDocument("Bocument 1"));
        si.AddProperty("is", "broken", score: 30, si.AddDocument("Bocument 4"));
        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.AddProperty("is", "secret", score: -99, si.AddDocument("Top Secret"));

        si.Finish(() =>
        {
            SearchDocuments(si, "Broken documents (Invalid query)", "is=broke", 0);
            SearchDocuments(si, "Broken documents", "is=broken", 2);

            SearchDocuments(si, "Color documents", "color=red", 1);
            SearchDocuments(si, "Color documents", "color:red", 2);
            SearchDocuments(si, "Color documents", "color:yel", 1);

            SearchDocuments(si, "Top documents", "is:secr", 1);
            SearchDocuments(si, "Top documents", "is:secret", 1);
            SearchDocuments(si, "Top documents", "is=secret", 1);

            // Dispose of the SearchIndexer when you are done with it.
            si.Dispose();
        });
    }

    private static void SearchDocuments(SearchIndexer si, string label, string query, int expectedCount)
    {
        var results = si.Search(query).ToList();
        Debug.Assert(results.Count == expectedCount, $"Invalid {label} with {query}, expected {expectedCount} results but got {results.Count}");
        if (results.Count > 0)
            Debug.Log($"{label} ({query}): {string.Join(", ", results.Select(r => $"{r.id} [{r.score}]"))}");
    }
}
```

## AddProperty(string, string, int, int, bool, bool)

Adds a property value to the index. A property is specified with a key and a string value. The value will be stored with multiple variations.

> **Warning:**
>
> **Deprecated.** AddProperty with variations is no longer supported. Variations are handled automatically internally. Please use AddProperty(string name, string value, int score, int documentIndex, bool saveKeyword)

```csharp
public void AddProperty(string key, string value, int score, int documentIndex, bool saveKeyword = false, bool exact = true)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Key used to retrieve the value.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): String value to store in the index.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Relevance score of the word.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Document where the indexed value was found.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Indicates if we store this key in the keyword registry of the index. See GetKeywords.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): If true, index stores an exact match entry for this word.

### Examples

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

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

        // Add properties.
        // These items are given a high score, so they will not be displayed first in the result list.
        si.AddProperty("is", "broken", score: 20, si.AddDocument("Bocument 1"));
        si.AddProperty("is", "broken", score: 30, si.AddDocument("Bocument 4"));
        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.AddProperty("is", "secret", score: -99, si.AddDocument("Top Secret"));

        si.Finish(() =>
        {
            SearchDocuments(si, "Broken documents (Invalid query)", "is=broke", 0);
            SearchDocuments(si, "Broken documents", "is=broken", 2);

            SearchDocuments(si, "Color documents", "color=red", 1);
            SearchDocuments(si, "Color documents", "color:red", 2);
            SearchDocuments(si, "Color documents", "color:yel", 1);

            SearchDocuments(si, "Top documents", "is:secr", 1);
            SearchDocuments(si, "Top documents", "is:secret", 1);
            SearchDocuments(si, "Top documents", "is=secret", 1);

            // Dispose of the SearchIndexer when you are done with it.
            si.Dispose();
        });
    }

    private static void SearchDocuments(SearchIndexer si, string label, string query, int expectedCount)
    {
        var results = si.Search(query).ToList();
        Debug.Assert(results.Count == expectedCount, $"Invalid {label} with {query}, expected {expectedCount} results but got {results.Count}");
        if (results.Count > 0)
            Debug.Log($"{label} ({query}): {string.Join(", ", results.Select(r => $"{r.id} [{r.score}]"))}");
    }
}
```

## AddProperty(string, string, int, int, int, int, bool, bool)

Adds a property value to the index. A property is specified with a key and a string value. The value will be stored with multiple variations.

> **Warning:**
>
> **Deprecated.** AddProperty with variations is no longer supported. Variations are handled automatically internally. Please use AddProperty(string name, string value, int score, int documentIndex, bool saveKeyword)

```csharp
public void AddProperty(string name, string value, int minVariations, int maxVariations, int score, int documentIndex, bool saveKeyword = false, bool exact = true)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Key used to retrieve the value.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): String value to store in the index.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Minimum number of variations to compute for the value. Cannot be higher than the length of the word.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Maximum number of variations to compute for the value. Cannot be higher than the length of the word.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Relevance score of the word.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Document where the indexed value was found.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Indicates if we store this key in the keyword registry of the index. See GetKeywords.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): If true, index stores an exact match entry for this word.

### Examples

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

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

        // Add properties.
        // These items are given a high score, so they will not be displayed first in the result list.
        si.AddProperty("is", "broken", score: 20, si.AddDocument("Bocument 1"));
        si.AddProperty("is", "broken", score: 30, si.AddDocument("Bocument 4"));
        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.AddProperty("is", "secret", score: -99, si.AddDocument("Top Secret"));

        si.Finish(() =>
        {
            SearchDocuments(si, "Broken documents (Invalid query)", "is=broke", 0);
            SearchDocuments(si, "Broken documents", "is=broken", 2);

            SearchDocuments(si, "Color documents", "color=red", 1);
            SearchDocuments(si, "Color documents", "color:red", 2);
            SearchDocuments(si, "Color documents", "color:yel", 1);

            SearchDocuments(si, "Top documents", "is:secr", 1);
            SearchDocuments(si, "Top documents", "is:secret", 1);
            SearchDocuments(si, "Top documents", "is=secret", 1);

            // Dispose of the SearchIndexer when you are done with it.
            si.Dispose();
        });
    }

    private static void SearchDocuments(SearchIndexer si, string label, string query, int expectedCount)
    {
        var results = si.Search(query).ToList();
        Debug.Assert(results.Count == expectedCount, $"Invalid {label} with {query}, expected {expectedCount} results but got {results.Count}");
        if (results.Count > 0)
            Debug.Log($"{label} ({query}): {string.Join(", ", results.Select(r => $"{r.id} [{r.score}]"))}");
    }
}
```
