Пример #1
0
    private static void Build()
    {
        allTypes = TypeCache.GetTypesDerivedFrom <UnityEngine.Object>().ToArray();

        var sw = new System.Diagnostics.Stopwatch();

        sw.Start();

        QE = new QueryEngine <Type>();
        QE.AddFilter("m", t => t.GetMethods().Length);
        QE.AddFilter("id", t => t.FullName);
        QE.AddFilter("asm", t => Path.GetFileNameWithoutExtension(t.Assembly.Location).ToLowerInvariant());
        QE.SetSearchDataCallback(t => new[] { t.Name });
        Debug.Log($"QuerEngine initialization took {sw.Elapsed.TotalMilliseconds,3:0.##} ms");

        sw.Restart();
        index = new SearchIndexer();
        index.Start();
        foreach (var t in allTypes)
        {
            var di = index.AddDocument(t.AssemblyQualifiedName, false);
            index.AddWord(t.Name.ToLowerInvariant(), 0, di);
            index.AddNumber("m", t.GetMethods().Length, 0, di);
            index.AddProperty("id", t.FullName.ToLowerInvariant(),
                              minVariations: t.FullName.Length, maxVariations: t.FullName.Length,
                              score: 0, documentIndex: di,
                              saveKeyword: false, exact: true);
            index.AddProperty("asm", Path.GetFileNameWithoutExtension(t.Assembly.Location).ToLowerInvariant(), di);
        }
        index.Finish(() => Debug.Log($"Type indexing took {sw.Elapsed.TotalMilliseconds,3:0.##} ms"));
    }
Пример #2
0
    private static int AddGuid(string guid)
    {
        if (guidToDocMap.TryGetValue(guid, out var di))
        {
            return(di);
        }

        di = index.AddDocument(guid);
        guidToDocMap.Add(guid, di);
        return(di);
    }
Пример #3
0
        private IEnumerator BuildIndex(SearchContext context, SearchProvider provider, GameObject[] objects, SearchIndexer indexer)
        {
            #if DEBUG_TIMING
            using (new DebugTimer($"Build scene index ({objects.Length})"))
            #endif
            {
                var useFuzzySearch = context.IsFilterEnabled("fuzzy");

                indexer.Start();
                for (int i = 0; i < objects.Length; ++i)
                {
                    var gameObject = objects[i];
                    var id = objects[i].GetInstanceID();
                    var name = CleanName(gameObject.name);
                    var path = CleanName(GetTransformPath(gameObject.transform));

                    var documentId = id.ToString();
                    int docIndex = indexer.AddDocument(documentId, false);

                    int scoreIndex = 1;
                    var parts =  SearchUtils.SplitEntryComponents(name, indexer.entrySeparators, 2, indexer.maxIndexCharVariation)
                                     .Concat(SplitWords(path, indexer.entrySeparators, indexer.maxIndexCharVariation))
                                     .Distinct().Take(10).ToArray();
                    //UnityEngine.Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, gameObject, $"{path} (<b>{parts.Length}</b>) = {String.Join(",", parts)}");
                    foreach (var word in parts)
                        indexer.AddWord(word, indexer.minIndexCharVariation, indexer.maxIndexCharVariation, scoreIndex++, docIndex);

                    name = name.ToLowerInvariant();
                    indexer.AddExactWord(name, 0, docIndex);
                    if (name.Length > indexer.maxIndexCharVariation)
                        indexer.AddWord(name, indexer.maxIndexCharVariation+1, name.Length, 1, docIndex);

                    var keywords = buildKeywordComponents(objects[i]);
                    if (keywords != null)
                    {
                        foreach (var keyword in keywords)
                            foreach (var word in SplitWords(keyword, indexer.entrySeparators, indexer.maxIndexCharVariation))
                                indexer.AddWord(word, scoreIndex++, docIndex);
                    }

                    var ptype = PrefabUtility.GetPrefabAssetType(gameObject);
                    if (ptype != PrefabAssetType.NotAPrefab)
                        indexer.AddProperty("t", "prefab", 6, 6, 30, docIndex);

                    var gocs = gameObject.GetComponents<Component>();
                    for (int componentIndex = 1; componentIndex < gocs.Length; ++componentIndex)
                    {
                        var c = gocs[componentIndex];
                        if (!c || c.hideFlags.HasFlag(HideFlags.HideInInspector))
                            continue;

                        indexer.AddProperty("t", c.GetType().Name.ToLowerInvariant(), 40 + componentIndex, docIndex);
                    }

                    // While we are building the scene, lets search for objects name
                    yield return MatchItem(context, provider, documentId, name, useFuzzySearch);
                }

                indexer.Finish(true);
            }
        }
Пример #4
0
        private IEnumerator BuildIndex(SearchContext context, SearchProvider provider, GameObject[] objects, SearchIndexer indexer)
        {
            #if DEBUG_TIMING
            using (new DebugTimer("Build scene index"))
            #endif
            {
                var useFuzzySearch  = context.IsFilterEnabled("fuzzy");
                var indexComponents = context.IsFilterEnabled("components");

                indexer.Start();
                for (int i = 0; i < objects.Length; ++i)
                {
                    var gameObject = objects[i];
                    var id         = objects[i].GetInstanceID();
                    var name       = gameObject.name;
                    var path       = GetTransformPath(gameObject.transform);
                    var keywords   = buildKeywordComponents(objects[i]);

                    var documentId = id.ToString();
                    int docIndex   = indexer.AddDocument(documentId, false);

                    int scoreIndex = 1;
                    foreach (var word in SearchUtils.SplitEntryComponents(name, indexer.entrySeparators, 2, 12))
                    {
                        indexer.AddWord(word, scoreIndex++, docIndex);
                    }
                    foreach (var word in SplitWords(path, indexer.entrySeparators, 8))
                    {
                        indexer.AddWord(word, scoreIndex++, docIndex);
                    }

                    name = name.ToLowerInvariant();
                    indexer.AddWord(name, name.Length, 0, docIndex);
                    indexer.AddExactWord(name.ToLowerInvariant(), 0, docIndex);

                    var ptype   = PrefabUtility.GetPrefabAssetType(gameObject);
                    var pstatus = PrefabUtility.GetPrefabInstanceStatus(gameObject);

                    if (ptype != PrefabAssetType.NotAPrefab)
                    {
                        indexer.AddProperty("prefab", ptype.ToString().ToLowerInvariant(), 30, docIndex);
                    }
                    if (pstatus != PrefabInstanceStatus.NotAPrefab)
                    {
                        indexer.AddProperty("prefab", pstatus.ToString().ToLowerInvariant(), 30, docIndex);
                    }

                    if (keywords != null)
                    {
                        foreach (var keyword in keywords)
                        {
                            foreach (var word in SplitWords(keyword, indexer.entrySeparators, 8))
                            {
                                indexer.AddWord(word, scoreIndex++, docIndex);
                            }
                        }
                    }

                    if (indexComponents)
                    {
                        var gocs = gameObject.GetComponents <Component>();
                        for (int componentIndex = 1; componentIndex < gocs.Length; ++componentIndex)
                        {
                            var c = gocs[componentIndex];
                            if (!c || c.hideFlags == HideFlags.HideInInspector)
                            {
                                continue;
                            }

                            indexer.AddProperty("c", c.GetType().Name.ToLowerInvariant(), 2, docIndex);
                        }
                    }

                    // While we are building the scene, lets search for objects name
                    yield return(MatchItem(context, provider, documentId, name, useFuzzySearch));
                }

                indexer.Finish(true);
            }
        }