Version: 2023.2
public void AddNumber (string key, double value, int score, int documentIndex);

参数

key Key used to retrieve the value.
value Number value to store in the index.
score Relevance score of the word.
documentIndex Document where the indexed value was found.

描述

Adds a key-number value pair to the index. The key won't be added with variations.

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

static class Example_SearchIndexer_AddNumber
{
    [MenuItem("Examples/SearchIndexer/AddNumber")]
    public static void Run()
    {
        var si = new SearchIndexer();
        si.Start();

        // Add some documents and index a power value that can be searched.
        si.AddNumber("power", 4.4, score: 0, si.AddDocument("Weak"));
        si.AddNumber("power", 6.42, score: 0, si.AddDocument("Healthy"));
        si.AddNumber("power", 9.9, score: 0, si.AddDocument("Strong"));

        si.Finish(() => SearchPowerLevels(si));
    }

    private static void SearchPowerLevels(SearchIndexer si)
    {
        SearchPowerLevel(si, "power<5", 1);
        SearchPowerLevel(si, "power>=6", 2);
    }

    static void SearchPowerLevel(SearchIndexer si, string powerQuery, int expectedCount)
    {
        var results = si.Search(powerQuery).ToList();
        Debug.Assert(results.Count == expectedCount, "Invalid query");
        Debug.Log($"Document with {powerQuery}: {string.Join(", ", results.Select(r => r.id))}");
    }
}
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961