Exemplo n.º 1
0
        private static void AddTopColumnValues(IntelliSenseResult result, TermExpression lastTerm, IntelliSenseGuidance guidance, List <IntelliSenseItem> suggestions, Table singleTable, ColumnDetails singleColumn)
        {
            // Lame, to turn single terms into AllQuery [normally they return nothing]
            string completeQuery = QueryParser.Parse(result.Complete).ToString();

            // Recommend the top ten values in the column with the prefix typed so far
            DistinctResult topValues = singleTable.Query(new DistinctQueryTop(singleColumn.Name, completeQuery, 10));
            int            total     = (int)topValues.Total;

            if (topValues.Total == 0)
            {
                return;
            }

            // Walk values in order for ==, :, ::, backwards with inverse percentages for !=
            bool isNotEquals = lastTerm.Operator == Operator.NotEquals;
            int  start       = isNotEquals ? topValues.Values.RowCount - 1 : 0;
            int  end         = isNotEquals ? -1 : topValues.Values.RowCount;
            int  step        = isNotEquals ? -1 : 1;

            for (int i = start; i != end; i += step)
            {
                string value         = topValues.Values[i, 0].ToString();
                int    countForValue = (int)topValues.Values[i, 1];
                if (isNotEquals)
                {
                    countForValue = (int)topValues.Total - countForValue;
                }
                double frequency = (double)countForValue / (double)(topValues.Total);

                if ((countForValue > 1 || total <= 10) && value.StartsWith(guidance.Value, StringComparison.OrdinalIgnoreCase))
                {
                    string hint = (countForValue == topValues.Total ? "all" : frequency.ToString("P0"));
                    suggestions.Add(new IntelliSenseItem(QueryTokenCategory.Value, QueryScanner.WrapValue(value), hint));
                }
            }
        }
Exemplo n.º 2
0
 private QueryParser(TextReader reader)
 {
     _scanner = new QueryScanner(reader);
     _scanner.Next();
 }