document | 唯一的文档 ID。 |
name | 文档的名称或路径。 |
source | 文档的来源。例如,如果文档是嵌套对象,则来源应为容器资源路径。 |
checkIfExists | 如果此文档有可能已经存在,则传递 true。 |
flags | 描述文档性质的标志。 |
int 用于添加新索引条目的文档索引/句柄。
添加一个新的待索引文档。
using System.Linq; using UnityEditor; using UnityEditor.Search; using UnityEngine; static class Example_SearchIndexer_AddDocument { [MenuItem("Examples/SearchIndexer/AddDocument")] public static void Run() { var si = new SearchIndexer(); si.Start(); // The most efficient way of adding a document is by not checking if the // document ID was already added if you are sure that all your document IDs are unique. var di = si.AddDocument("document1", checkIfExists: false); // You can set `checkIfExists=true` to check for existing document IDs, and the system // will return an index of any existing document IDs. Debug.Assert(di == si.AddDocument("document1", checkIfExists: true)); // Once you have added a new document, you need to use the returned handle to index words, numbers and properties. si.AddWord("unity", 0, di); si.AddProperty("is", "awesome", di); si.AddNumber("version", 3.0, score: 0, di); si.Finish(() => Debug.Assert(si.Search("unity version>=3").Count() == 1, "No result were found")); } }