示例#1
0
        private static QueryParserNode BuildTree(IList subtokens, QueryParserNode.Type opCode)
        {
            QueryParserNode node = new TermNode((string)subtokens[subtokens.Count - 1]);

            for (int i = subtokens.Count - 2; i >= 0; i--)
            {
                TermNode leftOpnd = new TermNode((string)subtokens[i]);
                OpNode   op       = new OpNode(opCode);
                op.AddOperand(leftOpnd);
                op.AddOperand(node);
                node = op;
            }
            return(node);
        }
示例#2
0
        private static QueryParserNode SplitTokenToTree(string token)
        {
            ArrayList       subtokens = SplitTokens(token);
            QueryParserNode node;

            //  1. If there are no tokens - the input string completely consists
            //     of delimiter symbols.
            //  2. If there is only one token - then delimiter symbols either started
            //     or closed the string.
            if (subtokens.Count == 0)
            {
                node = new TermNode(token);
            }
            else if (subtokens.Count == 1)
            {
                // check if wildcard
                if (token.EndsWith("*") || token.EndsWith("?"))
                {
                    ArrayList tokens = Word.GetTokensByWildcard(token);
                    if (tokens.Count > 0)
                    {
                        node = BuildTree(tokens, QueryParserNode.Type.eoOr);
                    }
                    else
                    {
                        node = new TermNode(token);
                    }
                }
                else
                {
                    node = new TermNode((string)subtokens[0]);
                }
            }
            else
            {
                node = BuildTree(subtokens, QueryParserNode.Type.eoPhraseNear);
            }
            return(node);
        }
示例#3
0
        private static QueryParserNode  ProcessPrimaryLevel()
        {
            QueryParserNode nodePrimaryToken = null;

            GetNextToken();
            if (strToken != "")
            {
                if (strToken == "(")
                {
                    nodePrimaryToken = ParseExpression();
                    _errorMessage    = "Error in the query syntax - expected ')' symbol in expression";
                    Expect(")");
                    _errorMessage = null;
                }
                else
                if (strToken == "\"+")
                {
                    isPhrasalMode    = true;
                    nodePrimaryToken = ParseExpression();
                    Expect("+\"");
                    isPhrasalMode = false;
                }
                else
                {
                    string normToken = OMEnv.LexemeConstructor.GetNormalizedToken(strToken);

                    if (isDelimitableToken(normToken))
                    {
                        nodePrimaryToken = SplitTokenToTree(normToken);
                    }
                    else
                    {
                        nodePrimaryToken = new TermNode(normToken);
                    }
                }
            }

            return(nodePrimaryToken);
        }