Unity 6.3
0 онлайн 40 гостей 3 в системе
Вход

SearchIndexer.AddProperty

Declaration

public void AddProperty(string key, string value, int documentIndex);
public void AddProperty(string key, string value, int score, int documentIndex);
public void AddProperty(string key, string value, int documentIndex, bool saveKeyword);
public void AddProperty(string key, string value, int score, int documentIndex, bool saveKeyword);
Obsolete public void AddProperty(string key, string value, int documentIndex, bool saveKeyword, bool exact);
Obsolete public void AddProperty(string key, string value, int score, int documentIndex, bool saveKeyword, bool exact);
Obsolete public void AddProperty(string name, string value, int minVariations, int maxVariations, int score, int documentIndex, bool saveKeyword, bool exact);

Параметры

Параметр Описание
ключ Ключ, используемый для получения значения.
значение Строковое значение для хранения в индексе.
documentIndex Документ, в котором было найдено индексированное значение.
saveKeyword Показывает, хранится ли этот ключ в реестре ключевых слов индекса. См. SearchIndexer.GetKeywords.
точно Если true, index хранит точное соответствие для этого слова.
оценка Рейтинг релевантности слова.
имя Ключ, используемый для получения значения.
minVariations Минимальное число вариантов для вычисления для значения. Не может быть больше, чем длина слова.
maxVariations Максимальное число вариантов для вычисления для значения. Не может быть больше, чем длина слова.

Описание

Добавляет значение свойства в индекс. Свойство указывается с помощью ключа и строкового значения. Значение будет храниться с несколькими вариантами.

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}]"))}");
    }
}