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")); }
public static void IndexWordComponents(int documentIndex, string word) { foreach (var c in SearchUtils.SplitFileEntryComponents(word, SearchUtils.entrySeparators)) { index.AddWord(c.ToLowerInvariant(), 0, documentIndex); } }
private static void RunThreadIndexing() { var sw = new System.Diagnostics.Stopwatch(); sw.Start(); index = new SearchIndexer(); index.Start(); int completed = 0; var metaFiles = Directory.GetFiles("Assets", "*.meta", SearchOption.AllDirectories); var progressId = Progress.Start($"Scanning dependencies ({metaFiles.Length} assets)"); var exclude = new[] { ".unity", ".prefab" }; Parallel.ForEach(metaFiles, mf => { Progress.Report(progressId, completed / (float)metaFiles.Length, mf); var assetPath = mf.Replace("\\", "/").Substring(0, mf.Length - 5).ToLowerInvariant(); if (!File.Exists(assetPath)) { return; } var extension = Path.GetExtension(assetPath); if (exclude.Contains(extension)) { return; } var guid = ToGuid(assetPath); Progress.Report(progressId, completed / (float)metaFiles.Length, assetPath); TrackGuid(guid); pathToGuidMap.TryAdd(assetPath, guid); guidToPathMap.TryAdd(guid, assetPath); var mfc = File.ReadAllText(mf); ScanDependencies(guid, mfc); using (var file = new StreamReader(assetPath)) { var header = new char[5]; if (file.ReadBlock(header, 0, header.Length) == header.Length && header[0] == '%' && header[1] == 'Y' && header[2] == 'A' && header[3] == 'M' && header[4] == 'L') { var ac = file.ReadToEnd(); ScanDependencies(guid, ac); } } Progress.Report(progressId, ++completed / (float)metaFiles.Length); }); Progress.Finish(progressId, Progress.Status.Succeeded); completed = 0; var total = pathToGuidMap.Count + guidToRefsMap.Count + guidFromRefsMap.Count; progressId = Progress.Start($"Indexing {total} dependencies"); foreach (var kvp in pathToGuidMap) { var guid = kvp.Value; var path = kvp.Key; var ext = Path.GetExtension(path); if (ext.Length > 0 && ext[0] == '.') { ext = ext.Substring(1); } Progress.Report(progressId, completed++ / (float)total, path); var di = AddGuid(guid); index.AddExactWord("all", 0, di); AddStaticProperty("id", guid, di); AddStaticProperty("path", path, di); AddStaticProperty("t", GetExtension(path), di); index.AddWord(guid, guid.Length, 0, di); index.AddWord(Path.GetFileNameWithoutExtension(path), 0, di); } foreach (var kvp in guidToRefsMap) { var guid = kvp.Key; var refs = kvp.Value.Keys; var di = AddGuid(guid); Progress.Report(progressId, completed++ / (float)total, guid); index.AddNumber("count", refs.Count, 0, di); foreach (var r in refs) { AddStaticProperty("to", r, di); } } foreach (var kvp in guidFromRefsMap) { var guid = kvp.Key; var refs = kvp.Value.Keys; var di = AddGuid(guid); Progress.Report(progressId, completed++ / (float)total, guid); index.AddNumber("in", refs.Count, 0, di); foreach (var r in refs) { AddStaticProperty("from", r, di); if (guidToPathMap.TryGetValue(r, out var rp)) { AddStaticProperty("t", GetExtension(rp), di); } } if (guidToPathMap.TryGetValue(guid, out var path)) { AddStaticProperty("is", "valid", di); } else { AddStaticProperty("is", "broken", di); var refString = string.Join(", ", refs.Select(r => { if (guidToPathMap.TryGetValue(r, out var rp)) { return(rp); } return(r); })); index.GetDocument(di).metadata = $"Refered by {refString}"; } } Progress.SetDescription(progressId, $"Saving dependency index at {dependencyIndexLibraryPath}"); index.Finish((bytes) => { File.WriteAllBytes(dependencyIndexLibraryPath, bytes); Progress.Finish(progressId, Progress.Status.Succeeded); Debug.Log($"Dependency indexing took {sw.Elapsed.TotalMilliseconds,3:0.##} ms " + $"and was saved at {dependencyIndexLibraryPath} ({EditorUtility.FormatBytes(bytes.Length)} bytes)"); }, removedDocuments: null); }
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); } }
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); } }