Ejemplo n.º 1
0
        public static LucQuery Create(NodeQuery nodeQuery)
        {
            NodeQueryParameter[] parameters;
            var result = new LucQuery();

            SortField[] sortFields;
            string      oldQueryText;

            var compiler          = new SnLucCompiler();
            var compiledQueryText = compiler.Compile(nodeQuery, out parameters);

            sortFields = (from order in nodeQuery.Orders
                          select new SortField(
                              GetFieldNameByPropertyName(order.PropertyName),
                              GetSortType(order.PropertyName),
                              order.Direction == OrderDirection.Desc)).ToArray();

            oldQueryText = compiler.CompiledQuery.ToString();
            oldQueryText = oldQueryText.Replace("[*", "[ ").Replace("*]", " ]").Replace("{*", "{ ").Replace("*}", " }");

            var newQuery = new SnLucParser().Parse(oldQueryText);

            result.Query                = newQuery; // compiler.CompiledQuery,
            result.User                 = nodeQuery.User;
            result.SortFields           = sortFields;
            result.StartIndex           = nodeQuery.Skip;
            result.PageSize             = nodeQuery.PageSize;
            result.Top                  = nodeQuery.Top;
            result.EnableAutofilters    = FilterStatus.Disabled;
            result.EnableLifespanFilter = FilterStatus.Disabled;
            //TODO: QUICK: route through NodeQuery
            result.QueryExecutionMode = QueryExecutionMode.Default;

            return(result);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        private void Parser_QueryParser_AndOperatorDump(string queryText, StringBuilder dump, StringBuilder msg)
        {
            QueryParser parser;
            SnLucParser snParser;

            parser = new QueryParser(SenseNet.Search.Indexing.LuceneManager.LuceneVersion, LucObject.FieldName.AllText, IndexManager.GetAnalyzer());
            var lucQueryOr = parser.Parse(queryText);

            parser = new QueryParser(SenseNet.Search.Indexing.LuceneManager.LuceneVersion, LucObject.FieldName.AllText, IndexManager.GetAnalyzer());
            parser.SetDefaultOperator(QueryParser.Operator.AND);
            var LucQueryAnd = parser.Parse(queryText);

            snParser = new SnLucParser();
            var snQueryOr = snParser.Parse(queryText);

            //snQueryOr = snQueryOr.Rewrite(IndexManager.GetIndexReader());

            snParser = new SnLucParser();
            var snQueryAnd = snParser.Parse(queryText, SnLucParser.DefaultOperator.And);

            //snQueryAnd = snQueryAnd.Rewrite(IndexManager.GetIndexReader());

            dump.Append(queryText);
            dump.Append('\t');
            dump.Append(lucQueryOr.ToString());
            dump.Append('\t');
            dump.Append(LucQueryAnd.ToString());
            dump.Append('\t');
            dump.Append(snQueryOr.ToString());
            dump.Append('\t');
            dump.Append(snQueryAnd.ToString());
            dump.AppendLine();

            var lucQueryOrString  = lucQueryOr.ToString();
            var LucQueryAndString = LucQueryAnd.ToString();
            var snQueryOrString   = snQueryOr.ToString();
            var snQueryAndString  = snQueryAnd.ToString();

            if (lucQueryOrString != snQueryOrString)
            {
                msg.Append("Error with  OR operator. Query: '").Append(queryText)
                .Append("'. Expected: '").Append(lucQueryOrString)
                .Append("'.   Actual: '").AppendLine(snQueryOrString);
            }

            if (LucQueryAndString != snQueryAndString)
            {
                msg.Append("Error with AND operator. Query: '").Append(queryText)
                .Append("'. Expected: '").Append(LucQueryAndString)
                .Append("'.   Actual: '").AppendLine(snQueryAndString);
            }
        }
Ejemplo n.º 4
0
        public static LucQuery Create(NodeQuery nodeQuery)
        {
            NodeQueryParameter[] parameters;
            var result = new LucQuery();

            result.TraceInfo.BeginCrossCompilingTime();

            SortField[] sortFields;
            string      oldQueryText;

            try
            {
                var compiler          = new SnLucCompiler();
                var compiledQueryText = compiler.Compile(nodeQuery, out parameters);

                sortFields = (from order in nodeQuery.Orders
                              select new SortField(
                                  GetFieldNameByPropertyName(order.PropertyName),
                                  GetSortType(order.PropertyName), //SortField.STRING,
                                  order.Direction == OrderDirection.Desc)).ToArray();

                oldQueryText = compiler.CompiledQuery.ToString();
                oldQueryText = oldQueryText.Replace("[*", "[ ").Replace("*]", " ]").Replace("{*", "{ ").Replace("*}", " }");
                result.TraceInfo.InputText = oldQueryText;
            }
            finally
            {
                result.TraceInfo.FinishCrossCompilingTime();
            }
            result.TraceInfo.BeginParsingTime();
            Query newQuery;

            try
            {
                newQuery = new SnLucParser().Parse(oldQueryText);
            }
            finally
            {
                result.TraceInfo.FinishParsingTime();
            }
            result.Query                = newQuery; // compiler.CompiledQuery,
            result.User                 = nodeQuery.User;
            result.SortFields           = sortFields;
            result.StartIndex           = nodeQuery.Skip;
            result.PageSize             = nodeQuery.PageSize;
            result.Top                  = nodeQuery.Top;
            result.EnableAutofilters    = FilterStatus.Disabled;
            result.EnableLifespanFilter = FilterStatus.Disabled;

            return(result);
        }
Ejemplo n.º 5
0
        public void TextSplitter()
        {
            var parser      = new SnLucParser();
            var query       = parser.Parse("Default_Skin");
            var phraseQuery = query as PhraseQuery;

            Assert.IsNotNull(phraseQuery, "query is not PhraseQuery");
            var terms = phraseQuery.GetTerms();

            Assert.IsTrue(terms.Length == 2, String.Concat("terms.Length is ", terms.Length, ", expected 2"));
            Assert.IsTrue(terms[0].Text() == "default", String.Concat("term 0 is '", terms[0].Text(), "', expected 'default'"));
            Assert.IsTrue(terms[1].Text() == "skin", String.Concat("term 1 is '", terms[1].Text(), "', expected 'skin'"));

            parser      = new SnLucParser();
            query       = parser.Parse("_.,WORD1__WORD2%_%WORD3__");
            phraseQuery = query as PhraseQuery;
            Assert.IsNotNull(phraseQuery, "query is not PhraseQuery");
            terms = phraseQuery.GetTerms();
            Assert.IsTrue(terms.Length == 3, String.Concat("terms.Length is ", terms.Length, ", expected 3"));
            Assert.IsTrue(terms[0].Text() == "word1", String.Concat("term 0 is '", terms[0].Text(), "', expected 'word1'"));
            Assert.IsTrue(terms[1].Text() == "word2", String.Concat("term 1 is '", terms[1].Text(), "', expected 'word2'"));
            Assert.IsTrue(terms[2].Text() == "word3", String.Concat("term 2 is '", terms[2].Text(), "', expected 'word3'"));
        }
Ejemplo n.º 6
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);
        }