protected override IQueryNode PreProcessNode(IQueryNode node)
        {
            if (node is IFieldableNode)
            {
                IFieldableNode fieldNode = (IFieldableNode)node;

                QueryConfigHandler queryConfig = GetQueryConfigHandler();

                if (queryConfig == null)
                {
                    throw new ArgumentException(
                        "A config handler is expected by the processor UniqueFieldQueryNodeProcessor!");
                }

                if (!queryConfig.Has(SpansQueryConfigHandler.UNIQUE_FIELD))
                {
                    throw new ArgumentException(
                        "UniqueFieldAttribute should be defined in the config handler!");
                }

                String uniqueField = queryConfig.Get(SpansQueryConfigHandler.UNIQUE_FIELD);
                fieldNode.Field = (uniqueField);
            }

            return node;
        }
        protected override IQueryNode PreProcessNode(IQueryNode node)
        {
            if (node is FuzzyQueryNode)
            {
                FuzzyQueryNode fuzzyNode = (FuzzyQueryNode)node;
                QueryConfigHandler config = GetQueryConfigHandler();

                FuzzyConfig fuzzyConfig = null;

                if (config != null && (fuzzyConfig = config.Get(ConfigurationKeys.FUZZY_CONFIG)) != null)
                {
                    fuzzyNode.PrefixLength = fuzzyConfig.PrefixLength;

                    if (fuzzyNode.Similarity < 0)
                    {
                        fuzzyNode.Similarity = fuzzyConfig.MinSimilarity;
                    }
                }
                else if (fuzzyNode.Similarity < 0)
                {
                    throw new ArgumentException("No FUZZY_CONFIG set in the config");
                }
            }

            return node;
        }
        public virtual Query Build(IQueryNode node)
        {
            FieldQueryNode fieldQueryNode = (FieldQueryNode)node;

            return new SpanTermQuery(new Term(fieldQueryNode.GetFieldAsString(),
                fieldQueryNode.GetTextAsString()));
        }
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            if (node is IFieldableNode &&
                (node.Parent == null || !(node.Parent is IFieldableNode)))
            {
                IFieldableNode fieldNode = (IFieldableNode)node;
                QueryConfigHandler config = GetQueryConfigHandler();

                if (config != null)
                {
                    string field = fieldNode.Field;
                    FieldConfig fieldConfig = config.GetFieldConfig(StringUtils.ToString(field));

                    if (fieldConfig != null)
                    {
                        float? boost = fieldConfig.Get(ConfigurationKeys.BOOST);

                        if (boost != null)
                        {
                            return new BoostQueryNode(node, boost.Value);
                        }
                    }
                }
            }

            return node;
        }
        public override IQueryNode Process(IQueryNode queryTree)
        {
            Analyzer analyzer = GetQueryConfigHandler().Get(ConfigurationKeys.ANALYZER);

            if (analyzer != null)
            {
                this.analyzer = analyzer;
                this.positionIncrementsEnabled = false;
                bool? positionIncrementsEnabled = GetQueryConfigHandler().Get(ConfigurationKeys.ENABLE_POSITION_INCREMENTS);
                var defaultOperator = GetQueryConfigHandler().Get(ConfigurationKeys.DEFAULT_OPERATOR);
                this.defaultOperator = defaultOperator != null ? defaultOperator.Value : Operator.OR;

                if (positionIncrementsEnabled != null)
                {
                    this.positionIncrementsEnabled = positionIncrementsEnabled.Value;
                }

                if (this.analyzer != null)
                {
                    return base.Process(queryTree);
                }
            }

            return queryTree;
        }
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            if (!node.IsLeaf)
            {
                IList<IQueryNode> children = node.GetChildren();
                bool removeBoolean = false;

                if (children == null || children.Count == 0)
                {
                    removeBoolean = true;
                }
                else
                {
                    removeBoolean = true;

                    for (IEnumerator<IQueryNode> it = children.GetEnumerator(); it.MoveNext();)
                    {

                        if (!(it.Current is DeletedQueryNode))
                        {
                            removeBoolean = false;
                            break;
                        }
                    }
                }

                if (removeBoolean)
                {
                    return new DeletedQueryNode();
                }
            }

            return node;
        }
        public virtual Query Build(IQueryNode queryNode)
        {
            TermRangeQueryNode rangeNode = (TermRangeQueryNode)queryNode;
            FieldQueryNode upper = (FieldQueryNode)rangeNode.UpperBound;
            FieldQueryNode lower = (FieldQueryNode)rangeNode.LowerBound;

            string field = StringUtils.ToString(rangeNode.Field);
            string lowerText = lower.GetTextAsString();
            string upperText = upper.GetTextAsString();

            if (lowerText.Length == 0)
            {
                lowerText = null;
            }

            if (upperText.Length == 0)
            {
                upperText = null;
            }

            TermRangeQuery rangeQuery = TermRangeQuery.NewStringRange(field, lowerText, upperText, rangeNode
                .IsLowerInclusive, rangeNode.IsUpperInclusive);

            MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod)queryNode
                .GetTag(MultiTermRewriteMethodProcessor.TAG_ID);
            if (method != null)
            {
                rangeQuery.SetRewriteMethod(method);
            }

            return rangeQuery;
        }
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            if (node is TermRangeQueryNode)
            {
                TermRangeQueryNode rangeNode = (TermRangeQueryNode)node;
                FieldQueryNode lowerNode = (FieldQueryNode)rangeNode.LowerBound;
                FieldQueryNode upperNode = (FieldQueryNode)rangeNode.UpperBound;
                ICharSequence lowerText = lowerNode.Text;
                ICharSequence upperText = upperNode.Text;

                if (OPEN_RANGE_TOKEN.Equals(upperNode.GetTextAsString())
                    && (!(upperText is UnescapedCharSequence) || !((UnescapedCharSequence)upperText)
                        .WasEscaped(0)))
                {
                    upperText = "".ToCharSequence();
                }

                if (OPEN_RANGE_TOKEN.Equals(lowerNode.GetTextAsString())
                    && (!(lowerText is UnescapedCharSequence) || !((UnescapedCharSequence)lowerText)
                        .WasEscaped(0)))
                {
                    lowerText = "".ToCharSequence();
                }

                lowerNode.Text = lowerText;
                upperNode.Text = upperText;
            }

            return node;
        }
示例#9
0
        public virtual Query Build(IQueryNode queryNode)
        {
            GroupQueryNode groupNode = (GroupQueryNode)queryNode;

            return (Query)(groupNode).GetChild().GetTag(
                QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
        }
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            // the old Lucene Parser ignores FuzzyQueryNode that are also PrefixWildcardQueryNode or WildcardQueryNode
            // we do the same here, also ignore empty terms
            if (node is FieldQueryNode || node is FuzzyQueryNode)
            {
                FieldQueryNode fqn = (FieldQueryNode)node;
                string text = fqn.Text.ToString();

                // do not process wildcards for TermRangeQueryNode children and 
                // QuotedFieldQueryNode to reproduce the old parser behavior
                if (fqn.Parent is TermRangeQueryNode
                    || fqn is QuotedFieldQueryNode
                    || text.Length <= 0)
                {
                    // Ignore empty terms
                    return node;
                }

                // Code below simulates the old lucene parser behavior for wildcards

                if (IsPrefixWildcard(text))
                {
                    PrefixWildcardQueryNode prefixWildcardQN = new PrefixWildcardQueryNode(fqn);
                    return prefixWildcardQN;
                }
                else if (IsWildcard(text))
                {
                    WildcardQueryNode wildcardQN = new WildcardQueryNode(fqn);
                    return wildcardQN;
                }
            }

            return node;
        }
        public virtual Query Build(IQueryNode queryNode)
        {
            StandardBooleanQueryNode booleanNode = (StandardBooleanQueryNode)queryNode;

            BooleanQuery bQuery = new BooleanQuery(booleanNode.DisableCoord);
            IList<IQueryNode> children = booleanNode.GetChildren();

            if (children != null)
            {
                foreach (IQueryNode child in children)
                {
                    object obj = child.GetTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);

                    if (obj != null)
                    {
                        Query query = (Query)obj;

                        try
                        {
                            bQuery.Add(query, GetModifierValue(child));
                        }
                        catch (BooleanQuery.TooManyClauses ex)
                        {
                            throw new QueryNodeException(new MessageImpl(
                                QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, BooleanQuery
                                    .MaxClauseCount, queryNode
                                    .ToQueryString(new EscapeQuerySyntaxImpl())), ex);
                        }
                    }
                }
            }

            return bQuery;
        }
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            if (node is WildcardQueryNode)
            {
                WildcardQueryNode wildcardNode = (WildcardQueryNode)node;

                if (wildcardNode.Text.Length > 0)
                {
                    // Validate if the wildcard was escaped
                    if (UnescapedCharSequence.WasEscaped(wildcardNode.Text, 0))
                        return node;

                    switch (wildcardNode.Text[0])
                    {
                        case '*':
                        case '?':
                            throw new QueryNodeException(new MessageImpl(
                                QueryParserMessages.LEADING_WILDCARD_NOT_ALLOWED, node
                                    .ToQueryString(new EscapeQuerySyntaxImpl())));
                    }
                }
            }

            return node;
        }
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            if (node is BooleanQueryNode)
            {
                IList<IQueryNode> children = node.GetChildren();

                if (children != null && children.Count == 1)
                {
                    IQueryNode child = children[0];

                    if (child is ModifierQueryNode)
                    {
                        ModifierQueryNode modNode = (ModifierQueryNode)child;

                        if (modNode is BooleanModifierNode
                            || modNode.Modifier == Modifier.MOD_NONE)
                        {
                            return child;
                        }
                    }
                    else
                    {
                        return child;
                    }
                }
            }

            return node;
        }
        protected override IQueryNode PreProcessNode(IQueryNode node)
        {
            if (node is SlopQueryNode)
            {
                this.processChildren = false;
            }

            return node;
        }
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            if (node is TokenizedPhraseQueryNode
                || node is MultiPhraseQueryNode)
            {
                return new SlopQueryNode(node, this.defaultPhraseSlop);
            }

            return node;
        }
        protected override IQueryNode PreProcessNode(IQueryNode node)
        {
            if (!((node is BooleanQueryNode && !(node is AndQueryNode)) || node
                .GetType() == typeof(FieldQueryNode)))
            {
                throw new QueryNodeException(new MessageImpl(
                    QueryParserMessages.NODE_ACTION_NOT_SUPPORTED));
            }

            return node;
        }
示例#17
0
        public void Add(IQueryNode child)
        {
            if (IsLeaf || this.clauses == null || child == null)
            {
                throw new ArgumentException(NLS
                    .GetLocalizedMessage(QueryParserMessages.NODE_ACTION_NOT_SUPPORTED));
            }

            this.clauses.Add(child);
            ((QueryNodeImpl)child).SetParent(this);
        }
 protected override void ProcessChildren(IQueryNode queryTree)
 {
     if (this.processChildren)
     {
         base.ProcessChildren(queryTree);
     }
     else
     {
         this.processChildren = true;
     }
 }
        public override IQueryNode Process(IQueryNode queryTree)
        {
            bool? lowercaseExpandedTerms = GetQueryConfigHandler().Get(ConfigurationKeys.LOWERCASE_EXPANDED_TERMS);

            if (lowercaseExpandedTerms != null && lowercaseExpandedTerms.Value)
            {
                return base.Process(queryTree);
            }

            return queryTree;
        }
 protected virtual void ProcessChildren(IQueryNode queryTree)
 {
     IList<IQueryNode> children = queryTree.GetChildren();
     if (children != null && children.Count > 0)
     {
         foreach (IQueryNode child in children)
         {
             /*child = */
             ProcessIteration(child);
         }
     }
 }
示例#21
0
        /// <summary>
        /// This IQueryNode is used to identify parenthesis on the original query string
        /// </summary>
        public GroupQueryNode(IQueryNode query)
        {
            if (query == null)
            {
                throw new QueryNodeError(new MessageImpl(
                    QueryParserMessages.PARAMETER_VALUE_NOT_SUPPORTED, "query", "null"));
            }

            Allocate();
            IsLeaf = false;
            Add(query);
        }
        public override IQueryNode Process(IQueryNode queryTree)
        {
            queryTree = base.Process(queryTree);

            if (queryTree is DeletedQueryNode
                && !(queryTree is MatchNoDocsQueryNode))
            {
                return new MatchNoDocsQueryNode();
            }

            return queryTree;
        }
        public virtual Query Build(IQueryNode queryNode)
        {
            // validates node
            if (!(queryNode is MatchAllDocsQueryNode))
            {
                throw new QueryNodeException(new MessageImpl(
                    QueryParserMessages.LUCENE_QUERY_CONVERSION_ERROR, queryNode
                        .ToQueryString(new EscapeQuerySyntaxImpl()), queryNode.GetType()
                        .Name));
            }

            return new MatchAllDocsQuery();
        }
示例#24
0
        /// <summary>
        /// Used to store the modifier value on the original query string
        /// </summary>
        /// <param name="query">QueryNode subtree</param>
        /// <param name="mod">Modifier Value</param>
        public ModifierQueryNode(IQueryNode query, Modifier mod)
        {
            if (query == null)
            {
                throw new QueryNodeError(new MessageImpl(
                    QueryParserMessages.PARAMETER_VALUE_NOT_SUPPORTED, "query", "null"));
            }

            Allocate();
            IsLeaf = false;
            Add(query);
            this.modifier = mod;
        }
示例#25
0
        /// <summary>
        /// Constructs a boost node
        /// </summary>
        /// <param name="query">the query to be boosted</param>
        /// <param name="value">the boost value, it may vary from 0.0 to 1.0</param>
        public BoostQueryNode(IQueryNode query, float value)
        {
            if (query == null)
            {
                throw new QueryNodeError(new MessageImpl(
                    QueryParserMessages.NODE_ACTION_NOT_SUPPORTED, "query", "null"));
            }

            this.value = value;
            IsLeaf = false;
            Allocate();
            Add(query);
        }
示例#26
0
        public virtual Query Build(IQueryNode queryNode)
        {
            FuzzyQueryNode fuzzyNode = (FuzzyQueryNode)queryNode;
            string text = fuzzyNode.GetTextAsString();

#pragma warning disable 612, 618
            int numEdits = FuzzyQuery.FloatToEdits(fuzzyNode.Similarity,
                text.CodePointCount(0, text.Length));
#pragma warning restore 612, 618

            return new FuzzyQuery(new Term(fuzzyNode.GetFieldAsString(), fuzzyNode
                .GetTextAsString()), numEdits, fuzzyNode
                .PrefixLength);
        }
        public override IQueryNode Process(IQueryNode queryTree)
        {
            bool? allowsLeadingWildcard = GetQueryConfigHandler().Get(ConfigurationKeys.ALLOW_LEADING_WILDCARD);

            if (allowsLeadingWildcard != null)
            {
                if (!allowsLeadingWildcard.Value)
                {
                    return base.Process(queryTree);
                }
            }

            return queryTree;
        }
        public virtual Query Build(IQueryNode queryNode)
        {
            WildcardQueryNode wildcardNode = (WildcardQueryNode)queryNode;

            WildcardQuery q = new WildcardQuery(new Term(wildcardNode.GetFieldAsString(),
                                                 wildcardNode.GetTextAsString()));

            MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod)queryNode.GetTag(MultiTermRewriteMethodProcessor.TAG_ID);
            if (method != null)
            {
                q.SetRewriteMethod(method);
            }

            return q;
        }
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            if (node is FieldQueryNode)
            {
                FieldQueryNode fqn = (FieldQueryNode)node;

                if (fqn.Field.ToString().Equals("*")
                    && fqn.Text.ToString().Equals("*"))
                {
                    return new MatchAllDocsQueryNode();
                }
            }

            return node;
        }
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            if (node is SlopQueryNode)
            {
                SlopQueryNode phraseSlopNode = (SlopQueryNode)node;

                if (!(phraseSlopNode.GetChild() is TokenizedPhraseQueryNode)
                    && !(phraseSlopNode.GetChild() is MultiPhraseQueryNode))
                {
                    return phraseSlopNode.GetChild();
                }
            }

            return node;
        }
 public static void SetQuery(this IQueryNode node, QueryBase container)
 {
     node.Data[QueryKey] = container;
 }
示例#32
0
 public static Task <IQueryNode> RunAsync(IQueryNode node, IQueryVisitorContext context = null)
 {
     return(new EventFieldsQueryVisitor().AcceptAsync(node, context));
 }
 public static IEnumerable <IFieldSort> Run(IQueryNode node, IQueryVisitorContext context = null)
 {
     return(RunAsync(node, context).GetAwaiter().GetResult());
 }
示例#34
0
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            if (node is ITextableQueryNode &&
                !(node is WildcardQueryNode) &&
                !(node is FuzzyQueryNode) &&
                !(node is RegexpQueryNode) &&
                !(node.Parent is IRangeQueryNode))
            {
                FieldQueryNode fieldNode = ((FieldQueryNode)node);
                string         text      = fieldNode.GetTextAsString();
                string         field     = fieldNode.GetFieldAsString();

                CachingTokenFilter          buffer     = null;
                IPositionIncrementAttribute posIncrAtt = null;
                int  numTokens     = 0;
                int  positionCount = 0;
                bool severalTokensAtSamePosition = false;

                TokenStream source = null;
                try
                {
                    source = this.analyzer.GetTokenStream(field, text);
                    source.Reset();
                    buffer = new CachingTokenFilter(source);

                    if (buffer.HasAttribute <IPositionIncrementAttribute>())
                    {
                        posIncrAtt = buffer.GetAttribute <IPositionIncrementAttribute>();
                    }

                    try
                    {
                        while (buffer.IncrementToken())
                        {
                            numTokens++;
                            int positionIncrement = (posIncrAtt != null) ? posIncrAtt
                                                    .PositionIncrement : 1;
                            if (positionIncrement != 0)
                            {
                                positionCount += positionIncrement;
                            }
                            else
                            {
                                severalTokensAtSamePosition = true;
                            }
                        }
                    }
#pragma warning disable 168
                    catch (IOException e)
#pragma warning restore 168
                    {
                        // ignore
                    }
                }
                catch (IOException e)
                {
                    throw new Exception(e.ToString(), e);
                }
                finally
                {
                    IOUtils.DisposeWhileHandlingException(source);
                }

                // rewind the buffer stream
                buffer.Reset();

                if (!buffer.HasAttribute <ICharTermAttribute>())
                {
                    return(new NoTokenFoundQueryNode());
                }

                ICharTermAttribute termAtt = buffer.GetAttribute <ICharTermAttribute>();

                if (numTokens == 0)
                {
                    return(new NoTokenFoundQueryNode());
                }
                else if (numTokens == 1)
                {
                    string term = null;
                    try
                    {
                        bool hasNext;
                        hasNext = buffer.IncrementToken();
                        if (Debugging.AssertsEnabled)
                        {
                            Debugging.Assert(hasNext == true);
                        }
                        term = termAtt.ToString();
                    }
                    catch (IOException) // LUCENENET: IDE0059: Remove unnecessary value assignment
                    {
                        // safe to ignore, because we know the number of tokens
                    }

                    fieldNode.Text = term.AsCharSequence();

                    return(fieldNode);
                }
                else if (severalTokensAtSamePosition || !(node is QuotedFieldQueryNode))
                {
                    if (positionCount == 1 || !(node is QuotedFieldQueryNode))
                    {
                        // no phrase query:

                        if (positionCount == 1)
                        {
                            // simple case: only one position, with synonyms
                            List <IQueryNode> children = new List <IQueryNode>();

                            for (int i = 0; i < numTokens; i++)
                            {
                                string term = null;
                                try
                                {
                                    bool hasNext = buffer.IncrementToken();
                                    if (Debugging.AssertsEnabled)
                                    {
                                        Debugging.Assert(hasNext == true);
                                    }
                                    term = termAtt.ToString();
                                }
                                catch (IOException) // LUCENENET: IDE0059: Remove unnecessary value assignment
                                {
                                    // safe to ignore, because we know the number of tokens
                                }

                                children.Add(new FieldQueryNode(field, term, -1, -1));
                            }
                            return(new GroupQueryNode(
                                       new StandardBooleanQueryNode(children, positionCount == 1)));
                        }
                        else
                        {
                            // multiple positions
                            IQueryNode q            = new StandardBooleanQueryNode(Collections.EmptyList <IQueryNode>(), false);
                            IQueryNode currentQuery = null;
                            for (int i = 0; i < numTokens; i++)
                            {
                                string term = null;
                                try
                                {
                                    bool hasNext = buffer.IncrementToken();
                                    if (Debugging.AssertsEnabled)
                                    {
                                        Debugging.Assert(hasNext == true);
                                    }
                                    term = termAtt.ToString();
                                }
                                catch (IOException) // LUCENENET: IDE0059: Remove unnecessary value assignment
                                {
                                    // safe to ignore, because we know the number of tokens
                                }
                                if (posIncrAtt != null && posIncrAtt.PositionIncrement == 0)
                                {
                                    if (!(currentQuery is BooleanQueryNode))
                                    {
                                        IQueryNode t = currentQuery;
                                        currentQuery = new StandardBooleanQueryNode(Collections.EmptyList <IQueryNode>(), true);
                                        ((BooleanQueryNode)currentQuery).Add(t);
                                    }
                                    ((BooleanQueryNode)currentQuery).Add(new FieldQueryNode(field, term, -1, -1));
                                }
                                else
                                {
                                    if (currentQuery != null)
                                    {
                                        if (this.defaultOperator == Operator.OR)
                                        {
                                            q.Add(currentQuery);
                                        }
                                        else
                                        {
                                            q.Add(new ModifierQueryNode(currentQuery, Modifier.MOD_REQ));
                                        }
                                    }
                                    currentQuery = new FieldQueryNode(field, term, -1, -1);
                                }
                            }
                            if (this.defaultOperator == Operator.OR)
                            {
                                q.Add(currentQuery);
                            }
                            else
                            {
                                q.Add(new ModifierQueryNode(currentQuery, Modifier.MOD_REQ));
                            }

                            if (q is BooleanQueryNode)
                            {
                                q = new GroupQueryNode(q);
                            }
                            return(q);
                        }
                    }
                    else
                    {
                        // phrase query:
                        MultiPhraseQueryNode mpq = new MultiPhraseQueryNode();

                        List <FieldQueryNode> multiTerms = new List <FieldQueryNode>();
                        int position       = -1;
                        int i              = 0;
                        int termGroupCount = 0;
                        for (; i < numTokens; i++)
                        {
                            string term = null;
                            int    positionIncrement = 1;
                            try
                            {
                                bool hasNext = buffer.IncrementToken();
                                if (Debugging.AssertsEnabled)
                                {
                                    Debugging.Assert(hasNext == true);
                                }
                                term = termAtt.ToString();
                                if (posIncrAtt != null)
                                {
                                    positionIncrement = posIncrAtt.PositionIncrement;
                                }
                            }
                            catch (IOException) // LUCENENET: IDE0059: Remove unnecessary value assignment
                            {
                                // safe to ignore, because we know the number of tokens
                            }

                            if (positionIncrement > 0 && multiTerms.Count > 0)
                            {
                                foreach (FieldQueryNode termNode in multiTerms)
                                {
                                    if (this.positionIncrementsEnabled)
                                    {
                                        termNode.PositionIncrement = position;
                                    }
                                    else
                                    {
                                        termNode.PositionIncrement = termGroupCount;
                                    }

                                    mpq.Add(termNode);
                                }

                                // Only increment once for each "group" of
                                // terms that were in the same position:
                                termGroupCount++;

                                multiTerms.Clear();
                            }

                            position += positionIncrement;
                            multiTerms.Add(new FieldQueryNode(field, term, -1, -1));
                        }

                        foreach (FieldQueryNode termNode in multiTerms)
                        {
                            if (this.positionIncrementsEnabled)
                            {
                                termNode.PositionIncrement = position;
                            }
                            else
                            {
                                termNode.PositionIncrement = termGroupCount;
                            }

                            mpq.Add(termNode);
                        }

                        return(mpq);
                    }
                }
                else
                {
                    TokenizedPhraseQueryNode pq = new TokenizedPhraseQueryNode();

                    int position = -1;

                    for (int i = 0; i < numTokens; i++)
                    {
                        string term = null;
                        int    positionIncrement = 1;

                        try
                        {
                            bool hasNext = buffer.IncrementToken();
                            if (Debugging.AssertsEnabled)
                            {
                                Debugging.Assert(hasNext == true);
                            }
                            term = termAtt.ToString();

                            if (posIncrAtt != null)
                            {
                                positionIncrement = posIncrAtt.PositionIncrement;
                            }
                        }
                        catch (IOException) // LUCENENET: IDE0059: Remove unnecessary value assignment
                        {
                            // safe to ignore, because we know the number of tokens
                        }

                        FieldQueryNode newFieldNode = new FieldQueryNode(field, term, -1, -1);

                        if (this.positionIncrementsEnabled)
                        {
                            position += positionIncrement;
                            newFieldNode.PositionIncrement = position;
                        }
                        else
                        {
                            newFieldNode.PositionIncrement = i;
                        }

                        pq.Add(newFieldNode);
                    }

                    return(pq);
                }
            }

            return(node);
        }
示例#35
0
 /// <summary>
 /// コンストラクタ、親ノードと破棄するテーブル定義を指定して初期化する
 /// </summary>
 /// <param name="parent">親ノード</param>
 /// <param name="table">破棄するテーブル定義</param>
 public DropTable(IQueryNode parent, ITableDef table)
 {
     this.Parent = parent;
     this.Table  = table;
 }
示例#36
0
 public static Task <IQueryNode> RunAsync(IQueryNode node, AliasResolver resolver, IQueryVisitorContextWithAliasResolver context = null)
 {
     return(new AliasedQueryVisitor().AcceptAsync(node, context ?? new QueryVisitorContextWithAliasResolver {
         RootAliasResolver = resolver
     }));
 }
示例#37
0
文件: Limit.cs 项目: nQuantums/tips
 /// <summary>
 /// 指定の子ノードを取り除く
 /// </summary>
 /// <param name="child">子ノード</param>
 public void RemoveChild(IQueryNode child)
 {
     throw new NotImplementedException();
 }
示例#38
0
 public void AddNode(IQueryNode node)
 {
     children.Add(node);
     node.parent = this;
 }
示例#39
0
        /// <summary>
        /// Builds some kind of object from a query tree. Each node in the query tree
        /// is built using an specific builder associated to it.
        /// </summary>
        /// <param name="queryNode">the query tree root node</param>
        /// <returns>the built object</returns>
        /// <exception cref="QueryNodeException">if some node builder throws a
        /// <see cref="QueryNodeException"/> or if there is a node which had no
        /// builder associated to it</exception>
        public virtual TQuery Build(IQueryNode queryNode)
        {
            Process(queryNode);

            return((TQuery)queryNode.GetTag(QUERY_TREE_BUILDER_TAGID));
        }
示例#40
0
 public FacetNode(IQueryNode field, List <string> values, bool isMultiFacet)
 {
     Field        = field;
     Values       = values;
     IsMultiFacet = isMultiFacet;
 }
示例#41
0
 public SubstractNode(IQueryNode left, IQueryNode right) : base(left, right)
 {
 }
示例#42
0
 public OrNode(IQueryNode left, IQueryNode right) : base(left, right)
 {
 }
        private Func <TData, bool> BuildFunctionFromNode(IQueryNode node)
        {
            switch (node.type)
            {
            case QueryNodeType.And:
            {
                Assert.IsFalse(node.leaf, "And node cannot be leaf.");
                var leftFunc  = BuildFunctionFromNode(node.children[0]);
                var rightFunc = BuildFunctionFromNode(node.children[1]);
                return(o => leftFunc(o) && rightFunc(o));
            }

            case QueryNodeType.Or:
            {
                Assert.IsFalse(node.leaf, "Or node cannot be leaf.");
                var leftFunc  = BuildFunctionFromNode(node.children[0]);
                var rightFunc = BuildFunctionFromNode(node.children[1]);
                return(o => leftFunc(o) || rightFunc(o));
            }

            case QueryNodeType.Not:
            {
                Assert.IsFalse(node.leaf, "Not node cannot be leaf.");
                var childFunc = BuildFunctionFromNode(node.children[0]);
                return(o => !childFunc(o));
            }

            case QueryNodeType.Filter:
            {
                var filterNode      = node as FilterNode;
                var filterOperation = filterNode?.filterOperation as BaseFilterOperation <TData>;
                Assert.IsNotNull(filterNode);
                Assert.IsNotNull(filterOperation);
                return(o => filterOperation.Match(o));
            }

            case QueryNodeType.Search:
            {
                if (m_Engine.searchDataCallback == null)
                {
                    return(o => false);
                }
                var searchNode = node as SearchNode;
                Assert.IsNotNull(searchNode);
                Func <string, bool> matchWordFunc;
                var stringComparison = m_Engine.globalStringComparison;
                if (m_Engine.searchDataOverridesStringComparison)
                {
                    stringComparison = m_Engine.searchDataStringComparison;
                }
                if (searchNode.exact)
                {
                    matchWordFunc = s => s.Equals(searchNode.searchValue, stringComparison);
                }
                else
                {
                    matchWordFunc = s => s.IndexOf(searchNode.searchValue, stringComparison) >= 0;
                }
                return(o => m_Engine.searchDataCallback(o).Any(data => matchWordFunc(data)));
            }
            }

            return(o => false);
        }
示例#44
0
 public BinaryNode(IQueryNode leftNode, IQueryNode rightNode, ExpressionType type)
 {
     LeftNode  = leftNode;
     RightNode = rightNode;
     Type      = type;
 }
 public static void SetAggregation(this IQueryNode node, AggregationBase aggregation)
 {
     node.Data[AggregationKey] = aggregation;
 }
示例#46
0
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            if (node is FieldQueryNode fieldNode &&
                !(node.Parent is IRangeQueryNode))
            {
                QueryConfigHandler config = GetQueryConfigHandler();

                if (config != null)
                {
                    FieldConfig fieldConfig = config.GetFieldConfig(fieldNode
                                                                    .GetFieldAsString());

                    if (fieldConfig != null)
                    {
                        NumericConfig numericConfig = fieldConfig
                                                      .Get(ConfigurationKeys.NUMERIC_CONFIG);

                        if (numericConfig != null)
                        {
                            NumberFormat numberFormat = numericConfig.NumberFormat;
                            string       text         = fieldNode.GetTextAsString();
                            Number       number; // LUCENENET: IDE0059: Remove unnecessary value assignment

                            if (text.Length > 0)
                            {
                                try
                                {
                                    number = numberFormat.Parse(text);
                                }
                                catch (FormatException e) // LUCENENET: In .NET we are expecting the framework to throw FormatException, not ParseException
                                {
                                    // LUCENENET: Factored out NLS/Message/IMessage so end users can optionally utilize the built-in .NET localization.
                                    throw new QueryNodeParseException(string.Format(
                                                                          QueryParserMessages.COULD_NOT_PARSE_NUMBER, fieldNode
                                                                          .GetTextAsString(), numberFormat.GetType()
                                                                          .AssemblyQualifiedName), e);
                                }

                                switch (numericConfig.Type)
                                {
                                case NumericType.INT64:
                                    number = J2N.Numerics.Int64.GetInstance(number.ToInt64());
                                    break;

                                case NumericType.INT32:
                                    number = J2N.Numerics.Int32.GetInstance(number.ToInt32());
                                    break;

                                case NumericType.DOUBLE:
                                    number = J2N.Numerics.Double.GetInstance(number.ToDouble());
                                    break;

                                case NumericType.SINGLE:
                                    number = J2N.Numerics.Single.GetInstance(number.ToSingle());
                                    break;
                                }
                            }
                            else
                            {
                                // LUCENENET: Factored out NLS/Message/IMessage so end users can optionally utilize the built-in .NET localization.
                                throw new QueryNodeParseException(string.Format(
                                                                      QueryParserMessages.NUMERIC_CANNOT_BE_EMPTY, fieldNode.GetFieldAsString()));
                            }

                            NumericQueryNode lowerNode = new NumericQueryNode(fieldNode
                                                                              .Field, number, numberFormat);
                            NumericQueryNode upperNode = new NumericQueryNode(fieldNode
                                                                              .Field, number, numberFormat);

                            return(new NumericRangeQueryNode(lowerNode, upperNode, true, true,
                                                             numericConfig));
                        }
                    }
                }
            }

            return(node);
        }
示例#47
0
 protected override IQueryNode PreProcessNode(IQueryNode node)
 {
     return(node);
 }
        public override async Task <IEnumerable <IFieldSort> > AcceptAsync(IQueryNode node, IQueryVisitorContext context)
        {
            await node.AcceptAsync(this, context).ConfigureAwait(false);

            return(_fields);
        }
示例#49
0
 public GreaterThanNode(IQueryNode left, IQueryNode right) : base(left, right)
 {
 }
示例#50
0
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            if (node is TermRangeQueryNode)
            {
                TermRangeQueryNode termRangeNode = (TermRangeQueryNode)node;
                FieldQueryNode     upper         = (FieldQueryNode)termRangeNode.UpperBound;
                FieldQueryNode     lower         = (FieldQueryNode)termRangeNode.LowerBound;

                // LUCENENET specific - set to 0 (instead of null), since it doesn't correspond to any valid setting
                DateTools.Resolution dateRes = 0 /* = null*/;
                bool        inclusive        = false;
                CultureInfo locale           = GetQueryConfigHandler().Get(ConfigurationKeys.LOCALE);

                if (locale == null)
                {
                    locale = CultureInfo.CurrentCulture; //Locale.getDefault();
                }

                TimeZoneInfo timeZone = GetQueryConfigHandler().Get(ConfigurationKeys.TIMEZONE);

                if (timeZone == null)
                {
                    timeZone = TimeZoneInfo.Local; //TimeZone.getDefault();
                }

                string field    = termRangeNode.Field;
                string fieldStr = null;

                if (field != null)
                {
                    fieldStr = field.ToString();
                }

                FieldConfig fieldConfig = GetQueryConfigHandler()
                                          .GetFieldConfig(fieldStr);

                if (fieldConfig != null)
                {
                    dateRes = fieldConfig.Get(ConfigurationKeys.DATE_RESOLUTION);
                }

                if (termRangeNode.IsUpperInclusive)
                {
                    inclusive = true;
                }

                string part1 = lower.GetTextAsString();
                string part2 = upper.GetTextAsString();

                try
                {
                    string   shortDateFormat = locale.DateTimeFormat.ShortDatePattern;
                    DateTime d1;
                    DateTime d2 = DateTime.MaxValue; // We really don't care what we set this to, but we need something or the compiler will complain below

                    if (DateTime.TryParseExact(part1, shortDateFormat, locale, DateTimeStyles.None, out d1))
                    {
                        part1      = DateTools.DateToString(d1, dateRes);
                        lower.Text = new StringCharSequenceWrapper(part1);
                    }

                    if (DateTime.TryParseExact(part2, shortDateFormat, locale, DateTimeStyles.None, out d2))
                    {
                        if (inclusive)
                        {
                            // The user can only specify the date, not the time, so make sure
                            // the time is set to the latest possible time of that date to
                            // really
                            // include all documents:
                            //Calendar cal = Calendar.getInstance(timeZone, locale);
                            //cal.setTime(d2);
                            //cal.set(Calendar.HOUR_OF_DAY, 23);
                            //cal.set(Calendar.MINUTE, 59);
                            //cal.set(Calendar.SECOND, 59);
                            //cal.set(Calendar.MILLISECOND, 999);
                            //d2 = cal.getTime();

                            d2 = TimeZoneInfo.ConvertTime(d2, timeZone);
                            var cal = locale.Calendar;
                            d2 = cal.AddHours(d2, 23);
                            d2 = cal.AddMinutes(d2, 59);
                            d2 = cal.AddSeconds(d2, 59);
                            d2 = cal.AddMilliseconds(d2, 999);
                        }

                        part2      = DateTools.DateToString(d2, dateRes);
                        upper.Text = new StringCharSequenceWrapper(part2);
                    }
                }
#pragma warning disable 168
                catch (Exception e)
#pragma warning restore 168
                {
                    // do nothing
                }
            }

            return(node);
        }
示例#51
0
文件: Limit.cs 项目: nQuantums/tips
 /// <summary>
 /// 親ノードが変更された際に呼び出される
 /// </summary>
 /// <param name="parent">新しい親ノード</param>
 public void ChangeParent(IQueryNode parent)
 {
     this.Parent = parent;
 }
示例#52
0
 public virtual IQueryNode Process(IQueryNode queryTree)
 {
     return(ProcessIteration(queryTree));
 }
示例#53
0
文件: Limit.cs 项目: nQuantums/tips
 /// <summary>
 /// コンストラクタ、親ノードと列順序指定式を指定して初期化する
 /// </summary>
 /// <param name="parent">親ノード</param>
 /// <param name="value">制限値</param>
 public Limit(IQueryNode parent, object value)
 {
     this.Parent = parent;
     this.Value  = value;
 }
示例#54
0
文件: Sql.cs 项目: nQuantums/tips
 /// <summary>
 /// 指定の子ノードを取り除く
 /// </summary>
 /// <param name="child">子ノード</param>
 public void RemoveChild(IQueryNode child)
 {
     this.Children.Remove(child);
 }
示例#55
0
文件: Sql.cs 项目: nQuantums/tips
 /// <summary>
 /// 親ノードが変更された際に呼び出される
 /// </summary>
 /// <param name="parent">新しい親ノード</param>
 public void ChangeParent(IQueryNode parent)
 {
 }
示例#56
0
        private Node AddNode(IQueryNode node, Dictionary <IQueryNode, Node> queryNodesToViewNodes)
        {
            var visualElementNode = new Node();

            switch (node.type)
            {
            case QueryNodeType.And:
            case QueryNodeType.Or:
            case QueryNodeType.Not:
            case QueryNodeType.Intersection:
            case QueryNodeType.Union:
            case QueryNodeType.Where:
                visualElementNode.title = node.type.ToString();
                break;

            case QueryNodeType.Search:
                var searchNode = node as SearchNode;
                visualElementNode.title = $"{(searchNode.exact? "!":"")}{searchNode.searchValue}";
                break;

            case QueryNodeType.Filter:
                var filterNode = node as FilterNode;
                visualElementNode.title = filterNode.identifier;
                break;

            case QueryNodeType.NestedQuery:
            case QueryNodeType.Aggregator:
                visualElementNode.title = node.identifier;
                break;

            case QueryNodeType.In:
                var inFilterNode = node as InFilterNode;
                var paramString  = string.IsNullOrEmpty(inFilterNode.paramValue) ? "" : $"({inFilterNode.paramValue})";
                visualElementNode.title = $"{inFilterNode.filter.token}{paramString}{inFilterNode.op.token} In";
                break;
            }
            visualElementNode.expanded = false;

            AddElement(visualElementNode);

            if (node.parent != null)
            {
                var inputPort = visualElementNode.InstantiatePort(Orientation.Vertical, Direction.Input, Port.Capacity.Single, typeof(bool));
                visualElementNode.inputContainer.Add(inputPort);

                var parentViewNode   = queryNodesToViewNodes[node.parent];
                var parentOutputPort = parentViewNode.outputContainer[0] as Port;
                var edge             = inputPort.ConnectTo(parentOutputPort);
                parentViewNode.RefreshPorts();
                AddElement(edge);
            }

            if (!node.leaf)
            {
                var outputPort = visualElementNode.InstantiatePort(Orientation.Vertical, Direction.Output, Port.Capacity.Multi, typeof(bool));
                visualElementNode.outputContainer.Add(outputPort);
            }

            visualElementNode.RefreshPorts();

            return(visualElementNode);
        }
示例#57
0
 public static IQueryNode Run(IQueryNode node, IQueryVisitorContext context = null)
 {
     return(RunAsync(node, context).GetAwaiter().GetResult());
 }
示例#58
0
 /// <summary>
 /// This method is invoked for every node when walking up the tree.
 /// </summary>
 /// <param name="node">node the query node to be post-processed</param>
 /// <returns>a query node</returns>
 /// <exception cref="QueryNodeException">if something goes wrong during the query node processing</exception>
 protected abstract IQueryNode PostProcessNode(IQueryNode node);
示例#59
0
 public static IQueryNode Run(IQueryNode node, AliasMap aliasMap, IQueryVisitorContextWithAliasResolver context = null)
 {
     return(RunAsync(node, aliasMap, context).GetAwaiter().GetResult());
 }
 public static Task <IEnumerable <IFieldSort> > RunAsync(IQueryNode node, IQueryVisitorContext context = null)
 {
     return(new GetSortFieldsVisitor().AcceptAsync(node, context));
 }