You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2016/09/11 21:30:58 UTC

[27/50] [abbrv] lucenenet git commit: Moved Lucene.Net.QueryParser and Lucene.Net.Tests.QueryParser projects into src\ directory.

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/679ad24c/src/Lucene.Net.QueryParser/Classic/MultiFieldQueryParser.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.QueryParser/Classic/MultiFieldQueryParser.cs b/src/Lucene.Net.QueryParser/Classic/MultiFieldQueryParser.cs
new file mode 100644
index 0000000..151fe38
--- /dev/null
+++ b/src/Lucene.Net.QueryParser/Classic/MultiFieldQueryParser.cs
@@ -0,0 +1,404 @@
+using System;
+using System.Collections.Generic;
+using Lucene.Net.Search;
+using Lucene.Net.Analysis;
+using Lucene.Net.Util;
+
+namespace Lucene.Net.QueryParser.Classic
+{
+    /*
+     * Licensed to the Apache Software Foundation (ASF) under one or more
+     * contributor license agreements.  See the NOTICE file distributed with
+     * this work for additional information regarding copyright ownership.
+     * The ASF licenses this file to You under the Apache License, Version 2.0
+     * (the "License"); you may not use this file except in compliance with
+     * the License.  You may obtain a copy of the License at
+     *
+     *     http://www.apache.org/licenses/LICENSE-2.0
+     *
+     * Unless required by applicable law or agreed to in writing, software
+     * distributed under the License is distributed on an "AS IS" BASIS,
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     * See the License for the specific language governing permissions and
+     * limitations under the License.
+     */
+
+
+    /// <summary> 
+    /// A QueryParser which constructs queries to search multiple fields.
+    /// </summary>
+    public class MultiFieldQueryParser : QueryParser
+    {
+        protected internal string[] fields;
+        protected internal IDictionary<string, float> boosts;
+
+        /// <summary> 
+        /// Creates a MultiFieldQueryParser. Allows passing of a map with term to
+        /// Boost, and the boost to apply to each term.
+        /// 
+        /// <p/>
+        /// It will, when parse(String query) is called, construct a query like this
+        /// (assuming the query consists of two terms and you specify the two fields
+        /// <c>title</c> and <c>body</c>):
+        /// <p/>
+        /// 
+        /// <code>
+        /// (title:term1 body:term1) (title:term2 body:term2)
+        /// </code>
+        /// 
+        /// <p/>
+        /// When setDefaultOperator(AND_OPERATOR) is set, the result will be:
+        /// <p/>
+        /// 
+        /// <code>
+        /// +(title:term1 body:term1) +(title:term2 body:term2)
+        /// </code>
+        /// 
+        /// <p/>
+        /// When you pass a boost (title=>5 body=>10) you can get
+        /// <p/>
+        /// 
+        /// <code>
+        /// +(title:term1^5.0 body:term1^10.0) +(title:term2^5.0 body:term2^10.0)
+        /// </code>
+        /// 
+        /// <p/>
+        /// In other words, all the query's terms must appear, but it doesn't matter
+        /// in what fields they appear.
+        /// <p/>
+        /// </summary>
+        public MultiFieldQueryParser(LuceneVersion matchVersion, string[] fields, Analyzer analyzer, IDictionary<string, float> boosts)
+            : this(matchVersion, fields, analyzer)
+        {
+            this.boosts = boosts;
+        }
+
+        /// <summary> 
+        /// Creates a MultiFieldQueryParser.
+        /// 
+        /// <p/>
+        /// It will, when parse(String query) is called, construct a query like this
+        /// (assuming the query consists of two terms and you specify the two fields
+        /// <c>title</c> and <c>body</c>):
+        /// <p/>
+        /// 
+        /// <code>
+        /// (title:term1 body:term1) (title:term2 body:term2)
+        /// </code>
+        /// 
+        /// <p/>
+        /// When setDefaultOperator(AND_OPERATOR) is set, the result will be:
+        /// <p/>
+        /// 
+        /// <code>
+        /// +(title:term1 body:term1) +(title:term2 body:term2)
+        /// </code>
+        /// 
+        /// <p/>
+        /// In other words, all the query's terms must appear, but it doesn't matter
+        /// in what fields they appear.
+        /// <p/>
+        /// </summary>
+        public MultiFieldQueryParser(LuceneVersion matchVersion, string[] fields, Analyzer analyzer)
+            : base(matchVersion, null, analyzer)
+        {
+            this.fields = fields;
+        }
+
+        protected internal override Query GetFieldQuery(string field, string queryText, int slop)
+        {
+            if (field == null)
+            {
+                IList<BooleanClause> clauses = new List<BooleanClause>();
+                for (int i = 0; i < fields.Length; i++)
+                {
+                    Query q = base.GetFieldQuery(fields[i], queryText, true);
+                    if (q != null)
+                    {
+                        //If the user passes a map of boosts
+                        if (boosts != null)
+                        {
+                            //Get the boost from the map and apply them
+                            float boost = boosts[fields[i]];
+                            q.Boost = boost;
+                        }
+                        ApplySlop(q, slop);
+                        clauses.Add(new BooleanClause(q, BooleanClause.Occur.SHOULD));
+                    }
+                }
+                if (clauses.Count == 0)
+                    // happens for stopwords
+                    return null;
+                return GetBooleanQuery(clauses, true);
+            }
+            Query q2 = base.GetFieldQuery(field, queryText, true);
+            ApplySlop(q2, slop);
+            return q2;
+        }
+
+        private void ApplySlop(Query q, int slop)
+        {
+            if (q is PhraseQuery)
+            {
+                ((PhraseQuery)q).Slop = slop;
+            }
+            else if (q is MultiPhraseQuery)
+            {
+                ((MultiPhraseQuery)q).Slop = slop;
+            }
+        }
+
+        protected internal override Query GetFieldQuery(string field, string queryText, bool quoted)
+        {
+            if (field == null)
+            {
+                IList<BooleanClause> clauses = new List<BooleanClause>();
+                for (int i = 0; i < fields.Length; i++)
+                {
+                    Query q = base.GetFieldQuery(fields[i], queryText, quoted);
+                    if (q != null)
+                    {
+                        //If the user passes a map of boosts
+                        if (boosts != null)
+                        {
+                            //Get the boost from the map and apply them
+                            float boost = boosts[fields[i]];
+                            q.Boost = boost;
+                        }
+                        clauses.Add(new BooleanClause(q, BooleanClause.Occur.SHOULD));
+                    }
+                }
+                if (clauses.Count == 0)  // happens for stopwords
+                    return null;
+                return GetBooleanQuery(clauses, true);
+            }
+            Query q2 = base.GetFieldQuery(field, queryText, quoted);
+            return q2;
+        }
+
+        protected internal override Query GetFuzzyQuery(string field, string termStr, float minSimilarity)
+        {
+            if (field == null)
+            {
+                IList<BooleanClause> clauses = new List<BooleanClause>();
+                for (int i = 0; i < fields.Length; i++)
+                {
+                    clauses.Add(new BooleanClause(GetFuzzyQuery(fields[i], termStr, minSimilarity), BooleanClause.Occur.SHOULD));
+                }
+                return GetBooleanQuery(clauses, true);
+            }
+            return base.GetFuzzyQuery(field, termStr, minSimilarity);
+        }
+
+        protected internal override Query GetPrefixQuery(System.String field, System.String termStr)
+        {
+            if (field == null)
+            {
+                IList<BooleanClause> clauses = new List<BooleanClause>();
+                for (int i = 0; i < fields.Length; i++)
+                {
+                    clauses.Add(new BooleanClause(GetPrefixQuery(fields[i], termStr), BooleanClause.Occur.SHOULD));
+                }
+                return GetBooleanQuery(clauses, true);
+            }
+            return base.GetPrefixQuery(field, termStr);
+        }
+
+        protected internal override Query GetWildcardQuery(string field, string termStr)
+        {
+            if (field == null)
+            {
+                IList<BooleanClause> clauses = new List<BooleanClause>();
+                for (int i = 0; i < fields.Length; i++)
+                {
+                    clauses.Add(new BooleanClause(GetWildcardQuery(fields[i], termStr), BooleanClause.Occur.SHOULD));
+                }
+                return GetBooleanQuery(clauses, true);
+            }
+            return base.GetWildcardQuery(field, termStr);
+        }
+
+
+        protected internal override Query GetRangeQuery(string field, string part1, string part2, bool startInclusive, bool endInclusive)
+        {
+            if (field == null)
+            {
+                IList<BooleanClause> clauses = new List<BooleanClause>();
+                for (int i = 0; i < fields.Length; i++)
+                {
+                    clauses.Add(new BooleanClause(GetRangeQuery(fields[i], part1, part2, startInclusive, endInclusive), BooleanClause.Occur.SHOULD));
+                }
+                return GetBooleanQuery(clauses, true);
+            }
+            return base.GetRangeQuery(field, part1, part2, startInclusive, endInclusive);
+        }
+
+        protected internal override Query GetRegexpQuery(string field, string termStr)
+        {
+            if (field == null)
+            {
+                IList<BooleanClause> clauses = new List<BooleanClause>();
+                for (int i = 0; i < fields.Length; i++)
+                {
+                    clauses.Add(new BooleanClause(GetRegexpQuery(fields[i], termStr),
+                        BooleanClause.Occur.SHOULD));
+                }
+                return GetBooleanQuery(clauses, true);
+            }
+            return base.GetRegexpQuery(field, termStr);
+        }
+
+        /// <summary> 
+        /// Parses a query which searches on the fields specified.
+        /// <p/>
+        /// If x fields are specified, this effectively constructs:
+        /// 
+        /// <code>
+        /// (field1:query1) (field2:query2) (field3:query3)...(fieldx:queryx)
+        /// </code>
+        /// 
+        /// </summary>
+        /// <param name="matchVersion">Lucene version to match; this is passed through to
+        /// QueryParser.
+        /// </param>
+        /// <param name="queries">Queries strings to parse
+        /// </param>
+        /// <param name="fields">Fields to search on
+        /// </param>
+        /// <param name="analyzer">Analyzer to use
+        /// </param>
+        /// <throws>  ParseException </throws>
+        /// <summary>             if query parsing fails
+        /// </summary>
+        /// <throws>  IllegalArgumentException </throws>
+        /// <summary>             if the length of the queries array differs from the length of
+        /// the fields array
+        /// </summary>
+        public static Query Parse(LuceneVersion matchVersion, string[] queries, string[] fields, Analyzer analyzer)
+        {
+            if (queries.Length != fields.Length)
+                throw new System.ArgumentException("queries.length != fields.length");
+            BooleanQuery bQuery = new BooleanQuery();
+            for (int i = 0; i < fields.Length; i++)
+            {
+                QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
+                Query q = qp.Parse(queries[i]);
+                if (q != null && (!(q is BooleanQuery) || ((BooleanQuery)q).GetClauses().Count > 0))
+                {
+                    bQuery.Add(q, BooleanClause.Occur.SHOULD);
+                }
+            }
+            return bQuery;
+        }
+
+        /// <summary> 
+        /// Parses a query, searching on the fields specified. Use this if you need
+        /// to specify certain fields as required, and others as prohibited.
+        /// <p/>
+        /// Uasge:
+        /// <code>
+        /// String[] fields = {&quot;filename&quot;, &quot;contents&quot;, &quot;description&quot;};
+        /// BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
+        /// BooleanClause.Occur.MUST,
+        /// BooleanClause.Occur.MUST_NOT};
+        /// MultiFieldQueryParser.parse(&quot;query&quot;, fields, flags, analyzer);
+        /// </code>
+        /// <p/>
+        /// The code above would construct a query:
+        /// 
+        /// <code>
+        /// (filename:query) +(contents:query) -(description:query)
+        /// </code>
+        /// 
+        /// </summary>
+        /// <param name="matchVersion">Lucene version to match; this is passed through to
+        /// QueryParser.
+        /// </param>
+        /// <param name="query">Query string to parse
+        /// </param>
+        /// <param name="fields">Fields to search on
+        /// </param>
+        /// <param name="flags">Flags describing the fields
+        /// </param>
+        /// <param name="analyzer">Analyzer to use
+        /// </param>
+        /// <throws>  ParseException </throws>
+        /// <summary>             if query parsing fails
+        /// </summary>
+        /// <throws>  IllegalArgumentException </throws>
+        /// <summary>             if the length of the fields array differs from the length of
+        /// the flags array
+        /// </summary>
+        public static Query Parse(LuceneVersion matchVersion, string query, string[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
+        {
+            if (fields.Length != flags.Length)
+                throw new System.ArgumentException("fields.length != flags.length");
+            BooleanQuery bQuery = new BooleanQuery();
+            for (int i = 0; i < fields.Length; i++)
+            {
+                QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
+                Query q = qp.Parse(query);
+                if (q != null && (!(q is BooleanQuery) || ((BooleanQuery)q).GetClauses().Count > 0))
+                {
+                    bQuery.Add(q, flags[i]);
+                }
+            }
+            return bQuery;
+        }
+
+        /// <summary> 
+        /// Parses a query, searching on the fields specified. Use this if you need
+        /// to specify certain fields as required, and others as prohibited.
+        /// <p/>
+        /// Usage:
+        /// <code>
+        /// String[] query = {&quot;query1&quot;, &quot;query2&quot;, &quot;query3&quot;};
+        /// String[] fields = {&quot;filename&quot;, &quot;contents&quot;, &quot;description&quot;};
+        /// BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
+        /// BooleanClause.Occur.MUST,
+        /// BooleanClause.Occur.MUST_NOT};
+        /// MultiFieldQueryParser.parse(query, fields, flags, analyzer);
+        /// </code>
+        /// <p/>
+        /// The code above would construct a query:
+        /// 
+        /// <code>
+        /// (filename:query1) +(contents:query2) -(description:query3)
+        /// </code>
+        /// 
+        /// </summary>
+        /// <param name="matchVersion">Lucene version to match; this is passed through to
+        /// QueryParser.
+        /// </param>
+        /// <param name="queries">Queries string to parse
+        /// </param>
+        /// <param name="fields">Fields to search on
+        /// </param>
+        /// <param name="flags">Flags describing the fields
+        /// </param>
+        /// <param name="analyzer">Analyzer to use
+        /// </param>
+        /// <throws>  ParseException </throws>
+        /// <summary>             if query parsing fails
+        /// </summary>
+        /// <throws>  IllegalArgumentException </throws>
+        /// <summary>             if the length of the queries, fields, and flags array differ
+        /// </summary>
+        public static Query Parse(LuceneVersion matchVersion, string[] queries, string[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
+        {
+            if (!(queries.Length == fields.Length && queries.Length == flags.Length))
+                throw new System.ArgumentException("queries, fields, and flags array have have different length");
+            BooleanQuery bQuery = new BooleanQuery();
+            for (int i = 0; i < fields.Length; i++)
+            {
+                QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
+                Query q = qp.Parse(queries[i]);
+                if (q != null && (!(q is BooleanQuery) || ((BooleanQuery)q).GetClauses().Count > 0))
+                {
+                    bQuery.Add(q, flags[i]);
+                }
+            }
+            return bQuery;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/679ad24c/src/Lucene.Net.QueryParser/Classic/ParseException.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.QueryParser/Classic/ParseException.cs b/src/Lucene.Net.QueryParser/Classic/ParseException.cs
new file mode 100644
index 0000000..161fa95
--- /dev/null
+++ b/src/Lucene.Net.QueryParser/Classic/ParseException.cs
@@ -0,0 +1,235 @@
+using System;
+using System.Text;
+using Lucene.Net.Support;
+
+namespace Lucene.Net.QueryParser.Classic
+{
+    /*
+     * Licensed to the Apache Software Foundation (ASF) under one or more
+     * contributor license agreements.  See the NOTICE file distributed with
+     * this work for additional information regarding copyright ownership.
+     * The ASF licenses this file to You under the Apache License, Version 2.0
+     * (the "License"); you may not use this file except in compliance with
+     * the License.  You may obtain a copy of the License at
+     *
+     *     http://www.apache.org/licenses/LICENSE-2.0
+     *
+     * Unless required by applicable law or agreed to in writing, software
+     * distributed under the License is distributed on an "AS IS" BASIS,
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     * See the License for the specific language governing permissions and
+     * limitations under the License.
+     */
+
+	/// <summary> 
+    /// This exception is thrown when parse errors are encountered.
+	/// You can explicitly create objects of this exception type by
+	/// calling the method GenerateParseException in the generated
+	/// parser.
+	/// 
+	/// You can modify this class to customize your error reporting
+	/// mechanisms so long as you retain the public fields.
+	/// </summary>
+	[Serializable]
+	public class ParseException : Exception
+	{
+        /// <summary>
+        /// This constructor is used by the method "GenerateParseException"
+        /// in the generated parser.  Calling this constructor generates
+        /// a new object of this type with the fields "currentToken",
+        /// "expectedTokenSequences", and "tokenImage" set.
+        /// </summary>
+        /// <param name="currentTokenVal"></param>
+        /// <param name="expectedTokenSequencesVal"></param>
+        /// <param name="tokenImageVal"></param>
+        public ParseException(Token currentTokenVal,
+                        int[][] expectedTokenSequencesVal,
+                        string[] tokenImageVal)
+            : base(Initialize(currentTokenVal, expectedTokenSequencesVal, tokenImageVal))
+        {
+            currentToken = currentTokenVal;
+            expectedTokenSequences = expectedTokenSequencesVal;
+            tokenImage = tokenImageVal;
+        }
+
+        /**
+         * The following constructors are for use by you for whatever
+         * purpose you can think of.  Constructing the exception in this
+         * manner makes the exception behave in the normal way - i.e., as
+         * documented in the class "Throwable".  The fields "errorToken",
+         * "expectedTokenSequences", and "tokenImage" do not contain
+         * relevant information.  The JavaCC generated code does not use
+         * these constructors.
+         */
+
+        public ParseException()
+        { }
+
+        public ParseException(string message)
+            : base(message)
+        { }
+
+        public ParseException(string message, Exception innerException)
+            : base(message, innerException)
+        { }
+
+
+        /// <summary> 
+        /// This is the last token that has been consumed successfully.  If
+        /// this object has been created due to a parse error, the token
+        /// following this token will (therefore) be the first error token.
+        /// </summary>
+        public Token currentToken;
+
+        /// <summary> 
+        /// Each entry in this array is an array of integers.  Each array
+        /// of integers represents a sequence of tokens (by their ordinal
+        /// values) that is expected at this point of the parse.
+        /// </summary>
+        public int[][] expectedTokenSequences;
+
+        /// <summary> 
+        /// This is a reference to the "tokenImage" array of the generated
+        /// parser within which the parse error occurred.  This array is
+        /// defined in the generated ...Constants interface.
+        /// </summary>
+        public string[] tokenImage;
+
+
+        /// <summary>
+        /// It uses "currentToken" and "expectedTokenSequences" to generate a parse
+        /// error message and returns it.  If this object has been created
+        /// due to a parse error, and you do not catch it (it gets thrown
+        /// from the parser) the correct error message
+        /// gets displayed.
+        /// </summary>
+        /// <param name="currentToken"></param>
+        /// <param name="expectedTokenSequences"></param>
+        /// <param name="tokenImage"></param>
+        /// <returns></returns>
+        private static string Initialize(Token currentToken,
+            int[][] expectedTokenSequences,
+            string[] tokenImage)
+        {
+
+            StringBuilder expected = new StringBuilder();
+            int maxSize = 0;
+            for (int i = 0; i < expectedTokenSequences.Length; i++)
+            {
+                if (maxSize < expectedTokenSequences[i].Length)
+                {
+                    maxSize = expectedTokenSequences[i].Length;
+                }
+                for (int j = 0; j < expectedTokenSequences[i].Length; j++)
+                {
+                    expected.Append(tokenImage[expectedTokenSequences[i][j]]).Append(' ');
+                }
+                if (expectedTokenSequences[i][expectedTokenSequences[i].Length - 1] != 0)
+                {
+                    expected.Append("...");
+                }
+                expected.Append(eol).Append("    ");
+            }
+            string retval = "Encountered \"";
+            Token tok = currentToken.next;
+            for (int i = 0; i < maxSize; i++)
+            {
+                if (i != 0)
+                    retval += " ";
+                if (tok.kind == 0)
+                {
+                    retval += tokenImage[0];
+                    break;
+                }
+                retval += (" " + tokenImage[tok.kind]);
+                retval += " \"";
+                retval += Add_escapes(tok.image);
+                retval += " \"";
+                tok = tok.next;
+            }
+            retval += ("\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn);
+            retval += ("." + eol);
+            if (expectedTokenSequences.Length == 1)
+            {
+                retval += ("Was expecting:" + eol + "    ");
+            }
+            else
+            {
+                retval += ("Was expecting one of:" + eol + "    ");
+            }
+            retval += expected.ToString();
+            return retval;
+        }
+		
+		/// <summary> 
+        /// The end of line string for this machine.
+        /// </summary>
+		protected static string eol = Environment.NewLine;
+		
+		/// <summary> 
+        /// Used to convert raw characters to their escaped version
+		/// when these raw version cannot be used as part of an ASCII
+		/// string literal.
+		/// </summary>
+		internal static string Add_escapes(string str)
+		{
+			StringBuilder retval = new StringBuilder();
+			char ch;
+			for (int i = 0; i < str.Length; i++)
+			{
+				switch (str[i])
+				{
+					
+					case (char) (0): 
+						continue;
+					
+					case '\b': 
+						retval.Append("\\b");
+						continue;
+					
+					case '\t': 
+						retval.Append("\\t");
+						continue;
+					
+					case '\n': 
+						retval.Append("\\n");
+						continue;
+					
+					case '\f': 
+						retval.Append("\\f");
+						continue;
+					
+					case '\r': 
+						retval.Append("\\r");
+						continue;
+					
+					case '\"': 
+						retval.Append("\\\"");
+						continue;
+					
+					case '\'': 
+						retval.Append("\\\'");
+						continue;
+					
+					case '\\': 
+						retval.Append("\\\\");
+						continue;
+					
+					default: 
+						if ((ch = str[i]) < 0x20 || ch > 0x7e)
+						{
+							System.String s = "0000" + System.Convert.ToString(ch, 16);
+							retval.Append("\\u" + s.Substring(s.Length - 4, (s.Length) - (s.Length - 4)));
+						}
+						else
+						{
+							retval.Append(ch);
+						}
+						continue;
+					
+				}
+			}
+			return retval.ToString();
+		}
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/679ad24c/src/Lucene.Net.QueryParser/Classic/QueryParser.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.QueryParser/Classic/QueryParser.cs b/src/Lucene.Net.QueryParser/Classic/QueryParser.cs
new file mode 100644
index 0000000..e86c716
--- /dev/null
+++ b/src/Lucene.Net.QueryParser/Classic/QueryParser.cs
@@ -0,0 +1,921 @@
+using Lucene.Net.Analysis;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace Lucene.Net.QueryParser.Classic
+{
+    /*
+     * Licensed to the Apache Software Foundation (ASF) under one or more
+     * contributor license agreements.  See the NOTICE file distributed with
+     * this work for additional information regarding copyright ownership.
+     * The ASF licenses this file to You under the Apache License, Version 2.0
+     * (the "License"); you may not use this file except in compliance with
+     * the License.  You may obtain a copy of the License at
+     *
+     *     http://www.apache.org/licenses/LICENSE-2.0
+     *
+     * Unless required by applicable law or agreed to in writing, software
+     * distributed under the License is distributed on an "AS IS" BASIS,
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     * See the License for the specific language governing permissions and
+     * limitations under the License.
+     */
+
+    /// <summary> This class is generated by JavaCC.  The most important method is
+    /// <see cref="Parse(String)" />.
+    /// 
+    /// The syntax for query strings is as follows:
+    /// A Query is a series of clauses.
+    /// A clause may be prefixed by:
+    /// <list type="bullet">
+    /// <item> a plus (<c>+</c>) or a minus (<c>-</c>) sign, indicating
+    /// that the clause is required or prohibited respectively; or</item>
+    /// <item> a term followed by a colon, indicating the field to be searched.
+    /// This enables one to construct queries which search multiple fields.</item>
+    /// </list>
+    /// 
+    /// A clause may be either:
+    /// <list type="bullet">
+    /// <item> a term, indicating all the documents that contain this term; or</item>
+    /// <item> a nested query, enclosed in parentheses.  Note that this may be used
+    /// with a <c>+</c>/<c>-</c> prefix to require any of a set of
+    /// terms.</item>
+    /// </list>
+    /// 
+    /// Thus, in BNF, the query grammar is:
+    /// <code>
+    /// Query  ::= ( Clause )*
+    /// Clause ::= ["+", "-"] [&lt;TERM&gt; ":"] ( &lt;TERM&gt; | "(" Query ")" )
+    /// </code>
+    /// 
+    /// <p/>
+    /// Examples of appropriately formatted queries can be found in the <a
+    /// href="../../../../../../queryparsersyntax.html">query syntax
+    /// documentation</a>.
+    /// <p/>
+    /// 
+    /// <p/>
+    /// In <see cref="TermRangeQuery" />s, QueryParser tries to detect date values, e.g.
+    /// <tt>date:[6/1/2005 TO 6/4/2005]</tt> produces a range query that searches
+    /// for "date" fields between 2005-06-01 and 2005-06-04. Note that the format
+    /// of the accepted input depends on the <see cref="Locale" />.
+    /// A <see cref="Lucene.Net.Documents.DateTools.Resolution" /> has to be set,
+    /// if you want to use <see cref="DateTools"/> for date conversion.<p/>
+    /// <p/>
+    /// The date resolution that shall be used for RangeQueries can be set
+    /// using <see cref="SetDateResolution(DateTools.Resolution)" />
+    /// or <see cref="SetDateResolution(String, DateTools.Resolution)" />. The former
+    /// sets the default date resolution for all fields, whereas the latter can
+    /// be used to set field specific date resolutions. Field specific date
+    /// resolutions take, if set, precedence over the default date resolution.
+    /// <p/>
+    /// <p/>
+    /// If you don't use <see cref="DateTools" /> in your index, you can create your own
+    /// query parser that inherits QueryParser and overwrites
+    /// <see cref="GetRangeQuery(String, String, String, bool)" /> to
+    /// use a different method for date conversion.
+    /// <p/>
+    /// 
+    /// <p/>Note that QueryParser is <em>not</em> thread-safe.<p/> 
+    /// 
+    /// <p/><b>NOTE</b>: there is a new QueryParser in contrib, which matches
+    /// the same syntax as this class, but is more modular,
+    /// enabling substantial customization to how a query is created.
+    /// 
+    /// <b>NOTE</b>: You must specify the required <see cref="LuceneVersion" /> compatibility when
+    /// creating QueryParser:
+    /// <list type="bullet">
+    /// <item>As of 3.1, <see cref="AutoGeneratePhraseQueries"/> is false by default.</item>
+    /// </list>
+    /// </summary>
+    public class QueryParser : QueryParserBase
+    {
+        // NOTE: This was moved into the QueryParserBase class.
+
+        ///* The default operator_Renamed for parsing queries. 
+        // * Use {@link QueryParser#setDefaultOperator} to change it.
+        // */
+
+        //public enum Operator
+        //{
+        //    OR,
+        //    AND
+        //}
+
+        /// <summary>
+        /// Constructs a query parser.
+        /// </summary>
+        /// <param name="matchVersion">Lucene version to match.</param>
+        /// <param name="f">the default field for query terms.</param>
+        /// <param name="a">used to find terms in the query text.</param>
+        public QueryParser(LuceneVersion matchVersion, string f, Analyzer a)
+            : this(new FastCharStream(new StringReader("")))
+        {
+            Init(matchVersion, f, a);
+        }
+
+        // *   Query  ::= ( Clause )*
+        // *   Clause ::= ["+", "-"] [<TermToken> ":"] ( <TermToken> | "(" Query ")" )
+        public int Conjunction()
+        {
+            int ret = CONJ_NONE;
+            switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+            {
+                case RegexpToken.AND:
+                case RegexpToken.OR:
+                    switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                    {
+                        case RegexpToken.AND:
+                            Jj_consume_token(RegexpToken.AND);
+                            ret = CONJ_AND;
+                            break;
+                        case RegexpToken.OR:
+                            Jj_consume_token(RegexpToken.OR);
+                            ret = CONJ_OR;
+                            break;
+                        default:
+                            jj_la1[0] = jj_gen;
+                            Jj_consume_token(-1);
+                            throw new ParseException();
+                    }
+                    break;
+                default:
+                    jj_la1[1] = jj_gen;
+                    break;
+            }
+            {
+                if (true) return ret;
+            }
+            throw new ApplicationException("Missing return statement in function");
+        }
+
+        public int Modifiers()
+        {
+            int ret = MOD_NONE;
+            switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+            {
+                case RegexpToken.NOT:
+                case RegexpToken.PLUS:
+                case RegexpToken.MINUS:
+                    switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                    {
+                        case RegexpToken.PLUS:
+                            Jj_consume_token(RegexpToken.PLUS);
+                            ret = MOD_REQ;
+                            break;
+                        case RegexpToken.MINUS:
+                            Jj_consume_token(RegexpToken.MINUS);
+                            ret = MOD_NOT;
+                            break;
+                        case RegexpToken.NOT:
+                            Jj_consume_token(RegexpToken.NOT);
+                            ret = MOD_NOT;
+                            break;
+                        default:
+                            jj_la1[2] = jj_gen;
+                            Jj_consume_token(-1);
+                            throw new ParseException();
+                    }
+                    break;
+                default:
+                    jj_la1[3] = jj_gen;
+                    break;
+            }
+            {
+                if (true) return ret;
+            }
+            throw new Exception("Missing return statement in function");
+        }
+
+        // This makes sure that there is no garbage after the query string
+        public override Query TopLevelQuery(string field)
+        {
+            Query q;
+            q = Query(field);
+            Jj_consume_token(0);
+            {
+                if (true) return q;
+            }
+            throw new Exception("Missing return statement in function");
+        }
+
+        public Query Query(string field)
+        {
+            List<BooleanClause> clauses = new List<BooleanClause>();
+            Query q, firstQuery = null;
+            int conj, mods;
+            mods = Modifiers();
+            q = Clause(field);
+            AddClause(clauses, CONJ_NONE, mods, q);
+            if (mods == MOD_NONE)
+                firstQuery = q;
+            while (true)
+            {
+                switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                {
+                    case RegexpToken.AND:
+                    case RegexpToken.OR:
+                    case RegexpToken.NOT:
+                    case RegexpToken.PLUS:
+                    case RegexpToken.MINUS:
+                    case RegexpToken.BAREOPER:
+                    case RegexpToken.LPAREN:
+                    case RegexpToken.STAR:
+                    case RegexpToken.QUOTED:
+                    case RegexpToken.TERM:
+                    case RegexpToken.PREFIXTERM:
+                    case RegexpToken.WILDTERM:
+                    case RegexpToken.REGEXPTERM:
+                    case RegexpToken.RANGEIN_START:
+                    case RegexpToken.RANGEEX_START:
+                    case RegexpToken.NUMBER:
+                        break;
+                    default:
+                        jj_la1[4] = jj_gen;
+                        goto label_1;
+                }
+
+                conj = Conjunction();
+                mods = Modifiers();
+                q = Clause(field);
+                AddClause(clauses, conj, mods, q);
+            }
+
+        label_1:
+
+            if (clauses.Count == 1 && firstQuery != null)
+            {
+                if (true) return firstQuery;
+            }
+
+            return GetBooleanQuery(clauses);
+        }
+
+        public Query Clause(string field)
+        {
+            Query q;
+            Token fieldToken = null, boost = null;
+            if (Jj_2_1(2))
+            {
+                switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                {
+                    case RegexpToken.TERM:
+                        fieldToken = Jj_consume_token(RegexpToken.TERM);
+                        Jj_consume_token(RegexpToken.COLON);
+                        field = DiscardEscapeChar(fieldToken.image);
+                        break;
+                    case RegexpToken.STAR:
+                        Jj_consume_token(RegexpToken.STAR);
+                        Jj_consume_token(RegexpToken.COLON);
+                        field = "*";
+                        break;
+                    default:
+                        jj_la1[5] = jj_gen;
+                        Jj_consume_token(-1);
+                        throw new ParseException();
+                }
+            }
+            else
+            {
+                ;
+            }
+            switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+            {
+                case RegexpToken.BAREOPER:
+                case RegexpToken.STAR:
+                case RegexpToken.QUOTED:
+                case RegexpToken.TERM:
+                case RegexpToken.PREFIXTERM:
+                case RegexpToken.WILDTERM:
+                case RegexpToken.REGEXPTERM:
+                case RegexpToken.RANGEIN_START:
+                case RegexpToken.RANGEEX_START:
+                case RegexpToken.NUMBER:
+                    q = Term(field);
+                    break;
+                case RegexpToken.LPAREN:
+                    Jj_consume_token(RegexpToken.LPAREN);
+                    q = Query(field);
+                    Jj_consume_token(RegexpToken.RPAREN);
+                    switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                    {
+                        case RegexpToken.CARAT:
+                            Jj_consume_token(RegexpToken.CARAT);
+                            boost = Jj_consume_token(RegexpToken.NUMBER);
+                            break;
+                        default:
+                            jj_la1[6] = jj_gen;
+                            break;
+                    }
+                    break;
+                default:
+                    jj_la1[7] = jj_gen;
+                    Jj_consume_token(-1);
+                    throw new ParseException();
+            }
+            {
+                if (true) return HandleBoost(q, boost);
+            }
+            throw new Exception("Missing return statement in function");
+        }
+
+        public Query Term(String field)
+        {
+            Token term, boost = null, fuzzySlop = null, goop1, goop2;
+            bool prefix = false;
+            bool wildcard = false;
+            bool fuzzy = false;
+            bool regexp = false;
+            bool startInc = false;
+            bool endInc = false;
+            Query q;
+            switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+            {
+                case RegexpToken.BAREOPER:
+                case RegexpToken.STAR:
+                case RegexpToken.TERM:
+                case RegexpToken.PREFIXTERM:
+                case RegexpToken.WILDTERM:
+                case RegexpToken.REGEXPTERM:
+                case RegexpToken.NUMBER:
+                    switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                    {
+                        case RegexpToken.TERM:
+                            term = Jj_consume_token(RegexpToken.TERM);
+                            break;
+                        case RegexpToken.STAR:
+                            term = Jj_consume_token(RegexpToken.STAR);
+                            wildcard = true;
+                            break;
+                        case RegexpToken.PREFIXTERM:
+                            term = Jj_consume_token(RegexpToken.PREFIXTERM);
+                            prefix = true;
+                            break;
+                        case RegexpToken.WILDTERM:
+                            term = Jj_consume_token(RegexpToken.WILDTERM);
+                            wildcard = true;
+                            break;
+                        case RegexpToken.REGEXPTERM:
+                            term = Jj_consume_token(RegexpToken.REGEXPTERM);
+                            regexp = true;
+                            break;
+                        case RegexpToken.NUMBER:
+                            term = Jj_consume_token(RegexpToken.NUMBER);
+                            break;
+                        case RegexpToken.BAREOPER:
+                            term = Jj_consume_token(RegexpToken.BAREOPER);
+                            term.image = term.image.Substring(0, 1);
+                            break;
+                        default:
+                            jj_la1[8] = jj_gen;
+                            Jj_consume_token(-1);
+                            throw new ParseException();
+                    }
+                    switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                    {
+                        case RegexpToken.FUZZY_SLOP:
+                            fuzzySlop = Jj_consume_token(RegexpToken.FUZZY_SLOP);
+                            fuzzy = true;
+                            break;
+                        default:
+                            jj_la1[9] = jj_gen;
+                            break;
+                    }
+                    switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                    {
+                        case RegexpToken.CARAT:
+                            Jj_consume_token(RegexpToken.CARAT);
+                            boost = Jj_consume_token(RegexpToken.NUMBER);
+                            switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                            {
+                                case RegexpToken.FUZZY_SLOP:
+                                    fuzzySlop = Jj_consume_token(RegexpToken.FUZZY_SLOP);
+                                    fuzzy = true;
+                                    break;
+                                default:
+                                    jj_la1[10] = jj_gen;
+                                    break;
+                            }
+                            break;
+                        default:
+                            jj_la1[11] = jj_gen;
+                            break;
+                    }
+                    q = HandleBareTokenQuery(field, term, fuzzySlop, prefix, wildcard, fuzzy, regexp);
+                    break;
+                case RegexpToken.RANGEIN_START:
+                case RegexpToken.RANGEEX_START:
+                    switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                    {
+                        case RegexpToken.RANGEIN_START:
+                            Jj_consume_token(RegexpToken.RANGEIN_START);
+                            startInc = true;
+                            break;
+                        case RegexpToken.RANGEEX_START:
+                            Jj_consume_token(RegexpToken.RANGEEX_START);
+                            break;
+                        default:
+                            jj_la1[12] = jj_gen;
+                            Jj_consume_token(-1);
+                            throw new ParseException();
+                    }
+                    switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                    {
+                        case RegexpToken.RANGE_GOOP:
+                            goop1 = Jj_consume_token(RegexpToken.RANGE_GOOP);
+                            break;
+                        case RegexpToken.RANGE_QUOTED:
+                            goop1 = Jj_consume_token(RegexpToken.RANGE_QUOTED);
+                            break;
+                        default:
+                            jj_la1[13] = jj_gen;
+                            Jj_consume_token(-1);
+                            throw new ParseException();
+                    }
+                    switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                    {
+                        case RegexpToken.RANGE_TO:
+                            Jj_consume_token(RegexpToken.RANGE_TO);
+                            break;
+                        default:
+                            jj_la1[14] = jj_gen;
+                            break;
+                    }
+                    switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                    {
+                        case RegexpToken.RANGE_GOOP:
+                            goop2 = Jj_consume_token(RegexpToken.RANGE_GOOP);
+                            break;
+                        case RegexpToken.RANGE_QUOTED:
+                            goop2 = Jj_consume_token(RegexpToken.RANGE_QUOTED);
+                            break;
+                        default:
+                            jj_la1[15] = jj_gen;
+                            Jj_consume_token(-1);
+                            throw new ParseException();
+                    }
+                    switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                    {
+                        case RegexpToken.RANGEIN_END:
+                            Jj_consume_token(RegexpToken.RANGEIN_END);
+                            endInc = true;
+                            break;
+                        case RegexpToken.RANGEEX_END:
+                            Jj_consume_token(RegexpToken.RANGEEX_END);
+                            break;
+                        default:
+                            jj_la1[16] = jj_gen;
+                            Jj_consume_token(-1);
+                            throw new ParseException();
+                    }
+                    switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                    {
+                        case RegexpToken.CARAT:
+                            Jj_consume_token(RegexpToken.CARAT);
+                            boost = Jj_consume_token(RegexpToken.NUMBER);
+                            break;
+                        default:
+                            jj_la1[17] = jj_gen;
+                            break;
+                    }
+                    bool startOpen = false;
+                    bool endOpen = false;
+                    if (goop1.kind == RegexpToken.RANGE_QUOTED)
+                    {
+                        goop1.image = goop1.image.Substring(1, goop1.image.Length - 2);
+                    }
+                    else if ("*".Equals(goop1.image))
+                    {
+                        startOpen = true;
+                    }
+                    if (goop2.kind == RegexpToken.RANGE_QUOTED)
+                    {
+                        goop2.image = goop2.image.Substring(1, goop2.image.Length - 2);
+                    }
+                    else if ("*".Equals(goop2.image))
+                    {
+                        endOpen = true;
+                    }
+                    q = GetRangeQuery(field, startOpen ? null : DiscardEscapeChar(goop1.image), endOpen ? null : DiscardEscapeChar(goop2.image), startInc, endInc);
+                    break;
+                case RegexpToken.QUOTED:
+                    term = Jj_consume_token(RegexpToken.QUOTED);
+                    switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                    {
+                        case RegexpToken.FUZZY_SLOP:
+                            fuzzySlop = Jj_consume_token(RegexpToken.FUZZY_SLOP);
+                            break;
+                        default:
+                            jj_la1[18] = jj_gen;
+                            break;
+                    }
+                    switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
+                    {
+                        case RegexpToken.CARAT:
+                            Jj_consume_token(RegexpToken.CARAT);
+                            boost = Jj_consume_token(RegexpToken.NUMBER);
+                            break;
+                        default:
+                            jj_la1[19] = jj_gen;
+                            break;
+                    }
+                    q = HandleQuotedTerm(field, term, fuzzySlop);
+                    break;
+                default:
+                    jj_la1[20] = jj_gen;
+                    Jj_consume_token(-1);
+                    throw new ParseException();
+            }
+            { if (true) return HandleBoost(q, boost); }
+            throw new Exception("Missing return statement in function");
+        }
+
+        private bool Jj_2_1(int xla)
+        {
+            jj_la = xla;
+            jj_lastpos = jj_scanpos = token;
+            try
+            {
+                return !Jj_3_1();
+            }
+            catch (LookaheadSuccess)
+            {
+                return true;
+            }
+            finally
+            {
+                Jj_save(0, xla);
+            }
+        }
+
+        private bool Jj_3R_2()
+        {
+            if (Jj_scan_token(RegexpToken.TERM)) return true;
+            if (Jj_scan_token(RegexpToken.COLON)) return true;
+            return false;
+        }
+
+        private bool Jj_3_1()
+        {
+            Token xsp;
+            xsp = jj_scanpos;
+            if (Jj_3R_2())
+            {
+                jj_scanpos = xsp;
+                if (Jj_3R_3()) return true;
+            }
+            return false;
+        }
+
+        private bool Jj_3R_3()
+        {
+            if (Jj_scan_token(RegexpToken.STAR)) return true;
+            if (Jj_scan_token(RegexpToken.COLON)) return true;
+            return false;
+        }
+
+        /* Generated Token Manager. */
+        public QueryParserTokenManager token_source;
+        /* Current token. */
+        public Token token;
+        /* Next token. */
+        public Token jj_nt;
+        private int jj_ntk;
+        private Token jj_scanpos, jj_lastpos;
+        private int jj_la;
+        private int jj_gen;
+        private int[] jj_la1 = new int[21];
+        private static uint[] jj_la1_0;
+        private static int[] jj_la1_1;
+
+        static QueryParser()
+        {
+            {
+                Jj_la1_init_0();
+                Jj_la1_init_1();
+            }
+        }
+
+        private static void Jj_la1_init_0()
+        {
+            jj_la1_0 = new uint[] 
+            { 
+                0x300, 0x300, 0x1c00, 0x1c00, 0xfda7f00, 0x120000, 0x40000, 0xfda6000, 0x9d22000, 0x200000, 
+                0x200000, 0x40000, 0x6000000, 0x80000000, 0x10000000, 0x80000000, 0x60000000, 0x40000, 
+                0x200000, 0x40000, 0xfda2000, 
+            };
+        }
+
+        private static void Jj_la1_init_1()
+        {
+            jj_la1_1 = new int[] 
+            { 
+                0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 
+                0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 
+            };
+        }
+
+        private JJCalls[] jj_2_rtns = new JJCalls[1];
+        private bool jj_rescan = false;
+        private int jj_gc = 0;
+
+        /// <summary>Constructor with user supplied CharStream. </summary>
+        protected internal QueryParser(ICharStream stream)
+        {
+            token_source = new QueryParserTokenManager(stream);
+            token = new Token();
+            jj_ntk = -1;
+            jj_gen = 0;
+            for (int i = 0; i < 21; i++) jj_la1[i] = -1;
+            for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();
+        }
+
+        /// <summary>Reinitialise. </summary>
+        public override void ReInit(ICharStream stream)
+        {
+            token_source.ReInit(stream);
+            token = new Token();
+            jj_ntk = -1;
+            jj_gen = 0;
+            for (int i = 0; i < 21; i++) jj_la1[i] = -1;
+            for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();
+        }
+
+        /// <summary>Constructor with generated Token Manager. </summary>
+        protected QueryParser(QueryParserTokenManager tm)
+        {
+            token_source = tm;
+            token = new Token();
+            jj_ntk = -1;
+            jj_gen = 0;
+            for (int i = 0; i < 21; i++) jj_la1[i] = -1;
+            for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();
+        }
+
+        /// <summary>Reinitialise. </summary>
+        public void ReInit(QueryParserTokenManager tm)
+        {
+            token_source = tm;
+            token = new Token();
+            jj_ntk = -1;
+            jj_gen = 0;
+            for (int i = 0; i < 21; i++) jj_la1[i] = -1;
+            for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();
+        }
+
+        private Token Jj_consume_token(int kind)
+        {
+            Token oldToken;
+            if ((oldToken = token).next != null) token = token.next;
+            else token = token.next = token_source.GetNextToken();
+            jj_ntk = -1;
+            if (token.kind == kind)
+            {
+                jj_gen++;
+                if (++jj_gc > 100)
+                {
+                    jj_gc = 0;
+                    for (int i = 0; i < jj_2_rtns.Length; i++)
+                    {
+                        JJCalls c = jj_2_rtns[i];
+                        while (c != null)
+                        {
+                            if (c.gen < jj_gen) c.first = null;
+                            c = c.next;
+                        }
+                    }
+                }
+                return token;
+            }
+            token = oldToken;
+            jj_kind = kind;
+            throw GenerateParseException();
+        }
+
+        [Serializable]
+        private sealed class LookaheadSuccess : Exception
+        {
+        }
+
+        private LookaheadSuccess jj_ls = new LookaheadSuccess();
+        private bool Jj_scan_token(int kind)
+        {
+            if (jj_scanpos == jj_lastpos)
+            {
+                jj_la--;
+                if (jj_scanpos.next == null)
+                {
+                    jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.GetNextToken();
+                }
+                else
+                {
+                    jj_lastpos = jj_scanpos = jj_scanpos.next;
+                }
+            }
+            else
+            {
+                jj_scanpos = jj_scanpos.next;
+            }
+            if (jj_rescan)
+            {
+                int i = 0;
+                Token tok = token;
+                while (tok != null && tok != jj_scanpos)
+                {
+                    i++;
+                    tok = tok.next;
+                }
+                if (tok != null) Jj_add_error_token(kind, i);
+            }
+            if (jj_scanpos.kind != kind) return true;
+            if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
+            return false;
+        }
+
+        /// <summary>Get the next Token. </summary>
+        public Token GetNextToken()
+        {
+            if (token.next != null) token = token.next;
+            else token = token.next = token_source.GetNextToken();
+            jj_ntk = -1;
+            jj_gen++;
+            return token;
+        }
+
+        /// <summary>Get the specific Token. </summary>
+        public Token GetToken(int index)
+        {
+            Token t = token;
+            for (int i = 0; i < index; i++)
+            {
+                if (t.next != null) t = t.next;
+                else t = t.next = token_source.GetNextToken();
+            }
+            return t;
+        }
+
+        private int Jj_ntk()
+        {
+            if ((jj_nt = token.next) == null)
+                return (jj_ntk = (token.next = token_source.GetNextToken()).kind);
+            else
+                return (jj_ntk = jj_nt.kind);
+        }
+
+        private List<int[]> jj_expentries = new List<int[]>();
+        private int[] jj_expentry;
+        private int jj_kind = -1;
+        private int[] jj_lasttokens = new int[100];
+        private int jj_endpos;
+
+        private void Jj_add_error_token(int kind, int pos)
+        {
+            if (pos >= 100) return;
+            if (pos == jj_endpos + 1)
+            {
+                jj_lasttokens[jj_endpos++] = kind;
+            }
+            else if (jj_endpos != 0)
+            {
+                jj_expentry = new int[jj_endpos];
+                for (int i = 0; i < jj_endpos; i++)
+                {
+                    jj_expentry[i] = jj_lasttokens[i];
+                }
+
+                foreach (var oldentry in jj_expentries)
+                {
+                    if (oldentry.Length == jj_expentry.Length)
+                    {
+                        for (int i = 0; i < jj_expentry.Length; i++)
+                        {
+                            if (oldentry[i] != jj_expentry[i])
+                            {
+                                continue;
+                            }
+                        }
+                        jj_expentries.Add(jj_expentry);
+                        break;
+                    }
+                }
+                if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
+            }
+        }
+
+        /// <summary>Generate ParseException. </summary>
+        public virtual ParseException GenerateParseException()
+        {
+            jj_expentries.Clear();
+            bool[] la1tokens = new bool[33];
+            if (jj_kind >= 0)
+            {
+                la1tokens[jj_kind] = true;
+                jj_kind = -1;
+            }
+            for (int i = 0; i < 21; i++)
+            {
+                if (jj_la1[i] == jj_gen)
+                {
+                    for (int j = 0; j < 32; j++)
+                    {
+                        if ((jj_la1_0[i] & (1 << j)) != 0)
+                        {
+                            la1tokens[j] = true;
+                        }
+                        if ((jj_la1_1[i] & (1 << j)) != 0)
+                        {
+                            la1tokens[32 + j] = true;
+                        }
+                    }
+                }
+            }
+            for (int i = 0; i < 33; i++)
+            {
+                if (la1tokens[i])
+                {
+                    jj_expentry = new int[1];
+                    jj_expentry[0] = i;
+                    jj_expentries.Add(jj_expentry);
+                }
+            }
+            jj_endpos = 0;
+            Jj_rescan_token();
+            Jj_add_error_token(0, 0);
+            int[][] exptokseq = new int[jj_expentries.Count][];
+            for (int i = 0; i < jj_expentries.Count; i++)
+            {
+                exptokseq[i] = jj_expentries[i];
+            }
+            return new ParseException(token, exptokseq, QueryParserConstants.TokenImage);
+        }
+
+        /// <summary>Enable tracing. </summary>
+        public void Enable_tracing()
+        {
+        }
+
+        /// <summary>Disable tracing. </summary>
+        public void Disable_tracing()
+        {
+        }
+
+        private void Jj_rescan_token()
+        {
+            jj_rescan = true;
+            for (int i = 0; i < 1; i++)
+            {
+                try
+                {
+                    JJCalls p = jj_2_rtns[i];
+                    do
+                    {
+                        if (p.gen > jj_gen)
+                        {
+                            jj_la = p.arg;
+                            jj_lastpos = jj_scanpos = p.first;
+                            switch (i)
+                            {
+                                case 0:
+                                    Jj_3_1();
+                                    break;
+                            }
+                        }
+                        p = p.next;
+                    } while (p != null);
+                }
+                catch (LookaheadSuccess)
+                {
+                }
+            }
+            jj_rescan = false;
+        }
+
+        private void Jj_save(int index, int xla)
+        {
+            JJCalls p = jj_2_rtns[index];
+            while (p.gen > jj_gen)
+            {
+                if (p.next == null)
+                {
+                    p = p.next = new JJCalls();
+                    break;
+                }
+                p = p.next;
+            }
+            p.gen = jj_gen + xla - jj_la;
+            p.first = token;
+            p.arg = xla;
+        }
+
+        internal sealed class JJCalls
+        {
+            internal int gen;
+            internal Token first;
+            internal int arg;
+            internal JJCalls next;
+        }
+    }
+}
\ No newline at end of file