Beispiel #1
0
        private Query ParseNewQuery_EmptyTerm(string queryText)
        {
            var parser = new SnLucParser();
            var query  = parser.Parse(queryText);

            if (parser.ParseEmptyQuery)
            {
                var visitor = new EmptyTermVisitor();
                return(visitor.Visit(query));
            }
            return(query);
        }
Beispiel #2
0
        public static LucQuery Parse(string luceneQueryText)
        {
            var result = new LucQuery();

            result.TraceInfo.InputText = luceneQueryText;

            result.TraceInfo.BeginParsingTime();
            var   parser = new SnLucParser();
            Query query;

            try
            {
                var replacedText = LucQueryTemplateReplacer.ReplaceTemplates(luceneQueryText);
                query = parser.Parse(replacedText);
            }
            finally
            {
                result.TraceInfo.FinishParsingTime();
            }
            //Run EmptyTermVisitor if the parser created empty query term.
            if (parser.ParseEmptyQuery)
            {
                var visitor = new EmptyTermVisitor();
                result.Query = visitor.Visit(query);
            }
            else
            {
                result.Query = query;
            }

            var sortFields = new List <SortField>();

            foreach (var control in parser.Controls)
            {
                switch (control.Name)
                {
                case SnLucLexer.Keywords.Select:
                    result.Projection = control.Value;
                    break;

                case SnLucLexer.Keywords.Top:
                    result.Top = Convert.ToInt32(control.Value);
                    break;

                case SnLucLexer.Keywords.Skip:
                    result.Skip = Convert.ToInt32(control.Value);
                    break;

                case SnLucLexer.Keywords.Sort:
                    sortFields.Add(CreateSortField(control.Value, false));
                    break;

                case SnLucLexer.Keywords.ReverseSort:
                    sortFields.Add(CreateSortField(control.Value, true));
                    break;

                case SnLucLexer.Keywords.Autofilters:
                    result.EnableAutofilters = control.Value == SnLucLexer.Keywords.On ? FilterStatus.Enabled : FilterStatus.Disabled;
                    break;

                case SnLucLexer.Keywords.Lifespan:
                    result.EnableLifespanFilter = control.Value == SnLucLexer.Keywords.On ? FilterStatus.Enabled : FilterStatus.Disabled;
                    break;

                case SnLucLexer.Keywords.CountOnly:
                    result.CountOnly = true;
                    break;
                }
            }
            result.SortFields = sortFields.ToArray();
            result.FieldLevel = parser.FieldLevel;
            return(result);
        }