public OmniboxFilterResult(float distance, FilterSyntax syntax, DynamicQuery.QueryToken queryToken, OmniboxMatch[] omniboxMatch)
 {
     this.Distance          = distance;
     this.Syntax            = syntax;
     this.QueryToken        = queryToken;
     this.QueryTokenMatches = omniboxMatch;
 }
Esempio n. 2
0
        protected IEnumerable <OmniboxFilterResult> GetFilterQueries(string rawQuery, QueryDescription queryDescription, FilterSyntax syntax, List <OmniboxToken> tokens)
        {
            List <OmniboxFilterResult> result = new List <OmniboxFilterResult>();

            int operatorIndex = syntax.Index + syntax.TokenLength;

            List <(QueryToken token, ImmutableStack <OmniboxMatch> stack)> ambiguousTokens = GetAmbiguousTokens(null, ImmutableStack <OmniboxMatch> .Empty,
                                                                                                                queryDescription, tokens, syntax.Index, operatorIndex).ToList();

            foreach ((QueryToken token, ImmutableStack <OmniboxMatch> stack)pair in ambiguousTokens)
            {
                var distance     = pair.stack.Sum(a => a.Distance);
                var tokenMatches = pair.stack.Reverse().ToArray();
                var token        = pair.token;

                if (syntax.Completion == FilterSyntaxCompletion.Token)
                {
                    if (tokens[operatorIndex - 1].Next(rawQuery) == '.' && pair.stack.All(a => ((QueryToken)a.Value).ToString().ToOmniboxPascal() == a.Text))
                    {
                        foreach (var qt in QueryUtils.SubTokens(pair.token, queryDescription, SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement))
                        {
                            result.Add(new OmniboxFilterResult(distance, syntax, qt, tokenMatches));
                        }
                    }
                    else
                    {
                        result.Add(new OmniboxFilterResult(distance, syntax, token, tokenMatches));
                    }
                }
                else
                {
                    string?canFilter = QueryUtils.CanFilter(pair.token);

                    if (canFilter.HasText())
                    {
                        result.Add(new OmniboxFilterResult(distance, syntax, token, tokenMatches)
                        {
                            CanFilter = canFilter,
                        });
                    }
                    else
                    {
                        FilterOperation operation = FilterValueConverter.ParseOperation(tokens[operatorIndex].Value);

                        if (syntax.Completion == FilterSyntaxCompletion.Operation)
                        {
                            var suggested = SugestedValues(pair.token);

                            if (suggested == null)
                            {
                                result.Add(new OmniboxFilterResult(distance, syntax, token, tokenMatches)
                                {
                                    Operation = operation,
                                });
                            }
                            else
                            {
                                foreach (var item in suggested)
                                {
                                    result.Add(new OmniboxFilterResult(distance, syntax, token, tokenMatches)
                                    {
                                        Operation = operation,
                                        Value     = item.Value
                                    });
                                }
                            }
                        }
                        else
                        {
                            var values = GetValues(pair.token, tokens[operatorIndex + 1]);

                            foreach (var value in values)
                            {
                                result.Add(new OmniboxFilterResult(distance, syntax, token, tokenMatches)
                                {
                                    Operation  = operation,
                                    Value      = value.Value,
                                    ValueMatch = value.Match,
                                });
                            }
                        }
                    }
                }
            }

            return(result);
        }