Version: 2023.2

SearchIndexerConstructor

切换到手册
public SearchIndexer ();
public SearchIndexer (string name);

参数

name Name of the indexer.

描述

Creates a new default SearchIndexer.

using UnityEditor;
using UnityEditor.Search;
using UnityEngine;

static class Example_SearchIndexer
{
    [MenuItem("Examples/SearchIndexer/Class")]
    public static void Run()
    {
        // Create a search indexer
        var searchIndexer = new SearchIndexer("SearchIndexerExample");

        // Indicate that searchIndexer is about to index documents
        searchIndexer.Start();

        // Add some documents
        var unityDocumentIndex = searchIndexer.AddDocument("Unity Technologies");

        // Index some words
        var baseScore = 42;
        searchIndexer.AddWord("unity", baseScore, unityDocumentIndex);
        searchIndexer.AddWord("is", baseScore, unityDocumentIndex);
        searchIndexer.AddWord("awesome", baseScore, unityDocumentIndex);

        // Indicate that searchIndexer is finished indexing documents and is ready to search.
        searchIndexer.Finish();

        // Wait for the indexation to finish.
        while (!searchIndexer.IsReady())
            ;

        // Search the index
        foreach (var result in searchIndexer.Search("uni"))
            Debug.Log($"Found document [{result.index}] {result.id} ({result.score})");
    }
}
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961