SearchIndexer.Read

Declaration

public bool Read(Stream stream, bool checkVersionOnly);

Parameters

stream The stream to read the index from.
checkVersionOnly If true, verifies the version of the index.

Returns

bool Returns false if the version of the index is not supported.

Description

Reads a stream and populates the index from it.

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

static class Example_SearchIndexer_Read
{
    [MenuItem("Examples/SearchIndexer/Read")]
    public static void Run()
    {
        var si = new SearchIndexer();
        si.Start();
        si.AddDocument("document 1");
        si.AddDocument("document 2");
        si.Finish();
        while (!si.IsReady())
            return;

        File.WriteAllBytes("Temp/Read.index", si.SaveBytes());

        // Stream the index from disk but only check if the stream is valid.
        using (var fileStream = new FileStream("Temp/Read.index", FileMode.Open, FileAccess.Read, FileShare.Read))
        {
            var copyIndex = new SearchIndexer();
            Debug.Assert(copyIndex.Read(fileStream, checkVersionOnly: true));
        }

        // Completely stream the index from disk.
        using (var fileStream = new FileStream("Temp/Read.index", FileMode.Open, FileAccess.Read, FileShare.Read))
        {
            var copyIndex = new SearchIndexer();
            Debug.Assert(copyIndex.Read(fileStream, checkVersionOnly: false));
            Debug.Assert(copyIndex.GetDocument(0).id == "document 1");
        }
    }
}

对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961