Example #1
0
 private void OnEvaluationEnded(SearchRequest exSearch)
 {
     m_Timer.Stop();
 }
 internal static IEnumerable <SearchItem> Path(SearchRequest selectRequest, SearchExpressionNode node, IEnumerable <SearchItem> items)
 {
     return(items.SelectMany(item => selectRequest.SelectPath(item)));
 }
 internal static IEnumerable <SearchItem> Default(SearchRequest selectRequest, SearchExpressionNode node, IEnumerable <SearchItem> items)
 {
     return(items);
 }
 internal static IEnumerable <SearchItem> Asset(SearchRequest selectRequest, SearchExpressionNode node, IEnumerable <SearchItem> items)
 {
     return(Object(selectRequest, node, items));
 }
Example #5
0
        private SearchRequest BuildSearchRequest(SearchExpressionNode node)
        {
            List <ExpressionVariable> dynamicVariables = new List <ExpressionVariable>();
            var searchQuery = Convert.ToString(node.value);

            // Replace constants
            if (node.variables != null)
            {
                foreach (var v in node.variables)
                {
                    if (v.type != ExpressionType.Value)
                    {
                        if (v.source != null)
                        {
                            dynamicVariables.Add(v);
                        }
                        continue;
                    }

                    var constantValue = Convert.ToString(v.source.value);
                    if (String.IsNullOrEmpty(constantValue))
                    {
                        UnityEngine.Debug.LogWarning($"Constant value is null for {v.source.id}");
                    }

                    searchQuery = searchQuery.Replace($"${v.name}", constantValue);
                }
            }

            if (dynamicVariables.Count == 0)
            {
                return(BuildFromSearchQuery(node, searchQuery));
            }

            var req = new SearchRequest(node.type);
            var varFetchResolved = new Dictionary <string, bool>();
            var varResults       = new Dictionary <string, HashSet <string> >();

            foreach (var v in dynamicVariables)
            {
                varFetchResolved[v.name] = false;
            }

            foreach (var v in dynamicVariables)
            {
                var varName    = v.name;
                var varRequest = BuildRequest(v.source);

                req.DependsOn(varRequest);
                varRequest.Resolve(items =>
                {
                    if (!varResults.TryGetValue(varName, out var results))
                    {
                        results             = new HashSet <string>();
                        varResults[varName] = results;
                    }

                    results.UnionWith(items.Select(i => i.id));
                }, r =>
                {
                    varFetchResolved[varName] = true;

                    if (varFetchResolved.All(kvp => kvp.Value))
                    {
                        var totalRequest = 1;
                        foreach (var vrs in varResults)
                        {
                            if (vrs.Value.Count == 0)
                            {
                                continue;
                            }
                            totalRequest *= vrs.Value.Count;
                        }

                        var queries = new string[totalRequest];
                        for (int i = 0; i < totalRequest; ++i)
                        {
                            queries[i] = searchQuery;
                        }

                        foreach (var vrs in varResults)
                        {
                            if (vrs.Value.Count == 0)
                            {
                                continue;
                            }

                            for (int i = 0; i < totalRequest;)
                            {
                                foreach (var varValue in vrs.Value)
                                {
                                    queries[i] = queries[i].Replace($"${vrs.Key}", varValue);
                                    ++i;
                                }
                            }
                        }

                        requestCount += totalRequest;
                        foreach (var q in queries)
                        {
                            BuildFromSearchQuery(node, q).TransferTo(req);
                        }
                    }
                });
            }

            return(req);
        }