lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [15/50] [abbrv] lucenenet git commit: Ported QueryParser.Surround namespace + tests.
Date Sun, 11 Sep 2016 21:30:46 GMT
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1e7576a6/Lucene.Net.QueryParser/Surround/Query/SpanNearClauseFactory.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.QueryParser/Surround/Query/SpanNearClauseFactory.cs b/Lucene.Net.QueryParser/Surround/Query/SpanNearClauseFactory.cs
new file mode 100644
index 0000000..6cddb9c
--- /dev/null
+++ b/Lucene.Net.QueryParser/Surround/Query/SpanNearClauseFactory.cs
@@ -0,0 +1,93 @@
+using Lucene.Net.Index;
+using Lucene.Net.Search.Spans;
+using Lucene.Net.Support;
+using System;
+using System.Collections.Generic;
+
+namespace Lucene.Net.QueryParser.Surround.Query
+{
+    /*
+     * 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>
+    /// Factory for <see cref="SpanOrQuery"/>
+    /// </summary>
+    public class SpanNearClauseFactory
+    {
+        public SpanNearClauseFactory(IndexReader reader, string fieldName, BasicQueryFactory qf) {
+            this.reader = reader;
+            this.fieldName = fieldName;
+            this.weightBySpanQuery = new HashMap<SpanQuery, float>();
+            this.qf = qf;
+          }
+
+        private IndexReader reader;
+        private string fieldName;
+        private IDictionary<SpanQuery, float> weightBySpanQuery;
+        private BasicQueryFactory qf;
+
+        public virtual IndexReader IndexReader { get { return reader; } }
+
+        public virtual string FieldName { get { return fieldName; } }
+
+        public virtual BasicQueryFactory BasicQueryFactory { get { return qf; } }
+
+        public virtual int Count { get { return weightBySpanQuery.Count; } }
+
+        public virtual void Clear() { weightBySpanQuery.Clear(); }
+
+        protected virtual void AddSpanQueryWeighted(SpanQuery sq, float weight)
+        {
+            float w;
+            if (weightBySpanQuery.ContainsKey(sq))
+                w = weightBySpanQuery[sq] + weight;
+            else
+                w = weight;
+            weightBySpanQuery[sq] = w;
+        }
+
+        public virtual void AddTermWeighted(Term t, float weight)
+        {
+            SpanTermQuery stq = qf.NewSpanTermQuery(t);
+            /* CHECKME: wrap in Hashable...? */
+            AddSpanQueryWeighted(stq, weight);
+        }
+
+        public virtual void AddSpanQuery(Search.Query q)
+        {
+            if (q == SrndQuery.TheEmptyLcnQuery)
+                return;
+            if (!(q is SpanQuery))
+                throw new InvalidOperationException("Expected SpanQuery: " + q.ToString(FieldName));
+            AddSpanQueryWeighted((SpanQuery)q, q.Boost);
+        }
+
+        public SpanQuery MakeSpanClause()
+        {
+            List<SpanQuery> spanQueries = new List<SpanQuery>();
+            foreach (var wsq in weightBySpanQuery)
+            {
+                wsq.Key.Boost = wsq.Value;
+                spanQueries.Add(wsq.Key);
+            }
+            if (spanQueries.Count == 1)
+                return spanQueries[0];
+            else
+                return new SpanOrQuery(spanQueries.ToArray());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1e7576a6/Lucene.Net.QueryParser/Surround/Query/SrndBooleanQuery.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.QueryParser/Surround/Query/SrndBooleanQuery.cs b/Lucene.Net.QueryParser/Surround/Query/SrndBooleanQuery.cs
new file mode 100644
index 0000000..7a1a8b3
--- /dev/null
+++ b/Lucene.Net.QueryParser/Surround/Query/SrndBooleanQuery.cs
@@ -0,0 +1,51 @@
+using Lucene.Net.Search;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Lucene.Net.QueryParser.Surround.Query
+{
+    /*
+     * 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.
+     */
+
+    public static class SrndBooleanQuery
+    {
+        public static void AddQueriesToBoolean(
+            BooleanQuery bq,
+            IEnumerable<Search.Query> queries,
+            BooleanClause.Occur occur)
+        {
+            foreach (var query in queries)
+            {
+                bq.Add(query, occur);
+            }
+        }
+
+        public static Search.Query MakeBooleanQuery(
+            IEnumerable<Search.Query> queries,
+            BooleanClause.Occur occur)
+        {
+            if (queries.Count() <= 1)
+            {
+                throw new InvalidOperationException("Too few subqueries: " + queries.Count());
+            }
+            BooleanQuery bq = new BooleanQuery();
+            AddQueriesToBoolean(bq, queries, occur);
+            return bq;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1e7576a6/Lucene.Net.QueryParser/Surround/Query/SrndPrefixQuery.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.QueryParser/Surround/Query/SrndPrefixQuery.cs b/Lucene.Net.QueryParser/Surround/Query/SrndPrefixQuery.cs
new file mode 100644
index 0000000..4044b09
--- /dev/null
+++ b/Lucene.Net.QueryParser/Surround/Query/SrndPrefixQuery.cs
@@ -0,0 +1,108 @@
+using Lucene.Net.Index;
+using Lucene.Net.Util;
+using System.Text;
+
+namespace Lucene.Net.QueryParser.Surround.Query
+{
+    /*
+     * 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>
+    /// Query that matches String prefixes
+    /// </summary>
+    public class SrndPrefixQuery : SimpleTerm
+    {
+        private readonly BytesRef prefixRef;
+        public SrndPrefixQuery(string prefix, bool quoted, char truncator)
+            : base(quoted)
+        {
+            this.prefix = prefix;
+            prefixRef = new BytesRef(prefix);
+            this.truncator = truncator;
+        }
+
+        private readonly string prefix;
+        public virtual string Prefix { get { return prefix; } }
+
+        private readonly char truncator;
+        public virtual char SuffixOperator { get { return truncator; } }
+
+        public virtual Term GetLucenePrefixTerm(string fieldName)
+        {
+            return new Term(fieldName, Prefix);
+        }
+
+        public override string ToStringUnquoted()
+        {
+            return Prefix;
+        }
+
+        protected override void SuffixToString(StringBuilder r)
+        {
+            r.Append(SuffixOperator);
+        }
+
+        public override void VisitMatchingTerms(IndexReader reader, string fieldName, IMatchingTermVisitor mtv)
+        {
+            /* inspired by PrefixQuery.rewrite(): */
+            Terms terms = MultiFields.GetTerms(reader, fieldName);
+            if (terms != null)
+            {
+                TermsEnum termsEnum = terms.Iterator(null);
+
+                bool skip = false;
+                TermsEnum.SeekStatus status = termsEnum.SeekCeil(new BytesRef(Prefix));
+                if (status == TermsEnum.SeekStatus.FOUND)
+                {
+                    mtv.VisitMatchingTerm(GetLucenePrefixTerm(fieldName));
+                }
+                else if (status == TermsEnum.SeekStatus.NOT_FOUND)
+                {
+                    if (StringHelper.StartsWith(termsEnum.Term(), prefixRef))
+                    {
+                        mtv.VisitMatchingTerm(new Term(fieldName, termsEnum.Term().Utf8ToString()));
+                    }
+                    else
+                    {
+                        skip = true;
+                    }
+                }
+                else
+                {
+                    // EOF
+                    skip = true;
+                }
+
+                if (!skip)
+                {
+                    while (true)
+                    {
+                        BytesRef text = termsEnum.Next();
+                        if (text != null && StringHelper.StartsWith(text, prefixRef))
+                        {
+                            mtv.VisitMatchingTerm(new Term(fieldName, text.Utf8ToString()));
+                        }
+                        else
+                        {
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1e7576a6/Lucene.Net.QueryParser/Surround/Query/SrndQuery.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.QueryParser/Surround/Query/SrndQuery.cs b/Lucene.Net.QueryParser/Surround/Query/SrndQuery.cs
new file mode 100644
index 0000000..57b19cc
--- /dev/null
+++ b/Lucene.Net.QueryParser/Surround/Query/SrndQuery.cs
@@ -0,0 +1,149 @@
+using Lucene.Net.Search;
+using Lucene.Net.Support;
+using System;
+using System.Text;
+
+namespace Lucene.Net.QueryParser.Surround.Query
+{
+    /*
+     * 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>
+    /// Lowest level base class for surround queries 
+    /// </summary>
+    public abstract class SrndQuery : ICloneable
+    {
+        //public SrndQuery() { }
+
+        private float weight = (float)1.0;
+        private bool weighted = false;
+
+        public virtual bool IsWeighted { get { return weighted; } }
+
+        public virtual float Weight 
+        { 
+            get { return weight; }
+            set
+            {
+                weight = value; /* as parsed from the query text */
+                weighted = true;
+            }
+        }
+
+        public virtual string WeightString { get { return Number.ToString(Weight); } }
+
+        public virtual string WeightOperator { get { return "^"; } }
+
+
+        protected virtual void WeightToString(StringBuilder r)
+        { 
+            /* append the weight part of a query */
+            if (IsWeighted)
+            {
+                r.Append(WeightOperator);
+                r.Append(WeightString);
+            }
+        }
+
+        public virtual Search.Query MakeLuceneQueryField(string fieldName, BasicQueryFactory qf)
+        {
+            Search.Query q = MakeLuceneQueryFieldNoBoost(fieldName, qf);
+            if (IsWeighted)
+            {
+                q.Boost=(Weight * q.Boost); /* weight may be at any level in a SrndQuery */
+            }
+            return q;
+        }
+
+        public abstract Search.Query MakeLuceneQueryFieldNoBoost(string fieldName, BasicQueryFactory qf);
+
+        /// <summary>
+        /// This method is used by <see cref="M:GetHashCode()"/> and <see cref="M:Equals(Object)"/>,
+        /// see LUCENE-2945.
+        /// </summary>
+        /// <returns></returns>
+        public abstract override string ToString();
+
+        public virtual bool IsFieldsSubQueryAcceptable { get { return true; } }
+
+        /// <summary> Shallow clone. Subclasses must override this if they
+        /// need to clone any members deeply,
+        /// </summary>
+        public virtual object Clone()
+        {
+            object clone = null;
+            try
+            {
+                clone = base.MemberwiseClone();
+            }
+            catch (Exception e)
+            {
+                throw new SystemException(e.Message, e); // shouldn't happen
+            }
+            return clone;
+        }
+
+        /// <summary>
+        /// For subclasses of <see cref="SrndQuery"/> within the package
+        /// {@link org.apache.lucene.queryparser.surround.query}
+        /// it is not necessary to override this method, <see cref="M:ToString()"/>
+        /// </summary>
+        public override int GetHashCode()
+        {
+            return GetType().GetHashCode() ^ ToString().GetHashCode();
+        }
+
+        /// <summary>
+        /// For subclasses of <see cref="SrndQuery"/> within the package
+        /// {@link org.apache.lucene.queryparser.surround.query}
+        /// it is not necessary to override this method,
+        /// @see #toString()
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <returns></returns>
+        public override bool Equals(object obj)
+        {
+            if (obj == null)
+                return false;
+            if (!GetType().Equals(obj.GetType()))
+                return false;
+            return ToString().Equals(obj.ToString());
+        }
+
+        /// <summary> An empty Lucene query  </summary>
+        public readonly static Search.Query TheEmptyLcnQuery = new EmptyLcnQuery(); /* no changes allowed */ 
+  
+        internal sealed class EmptyLcnQuery : BooleanQuery
+        {
+            public override float Boost
+            {
+                get { return base.Boost; }
+                set { throw new NotSupportedException(); }
+            }
+
+            public override void Add(BooleanClause clause)
+            {
+                throw new NotSupportedException();
+            }
+
+            public override void Add(Search.Query query, BooleanClause.Occur occur)
+            {
+                throw new NotSupportedException();
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1e7576a6/Lucene.Net.QueryParser/Surround/Query/SrndTermQuery.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.QueryParser/Surround/Query/SrndTermQuery.cs b/Lucene.Net.QueryParser/Surround/Query/SrndTermQuery.cs
new file mode 100644
index 0000000..45885a1
--- /dev/null
+++ b/Lucene.Net.QueryParser/Surround/Query/SrndTermQuery.cs
@@ -0,0 +1,63 @@
+using Lucene.Net.Index;
+using Lucene.Net.Util;
+
+namespace Lucene.Net.QueryParser.Surround.Query
+{
+    /*
+     * 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>
+    /// Simple single-term clause
+    /// </summary>
+    public class SrndTermQuery : SimpleTerm
+    {
+        public SrndTermQuery(string termText, bool quoted)
+            : base(quoted)
+        {
+            this.termText = termText;
+        }
+
+        private readonly string termText;
+        public virtual string TermText { get { return termText; } }
+
+        public virtual Term GetLuceneTerm(string fieldName)
+        {
+            return new Term(fieldName, TermText);
+        }
+
+        public override string ToStringUnquoted()
+        {
+            return TermText;
+        }
+
+        public override void VisitMatchingTerms(IndexReader reader, string fieldName, IMatchingTermVisitor mtv)
+        {
+            /* check term presence in index here for symmetry with other SimpleTerm's */
+            Terms terms = MultiFields.GetTerms(reader, fieldName);
+            if (terms != null)
+            {
+                TermsEnum termsEnum = terms.Iterator(null);
+
+                TermsEnum.SeekStatus status = termsEnum.SeekCeil(new BytesRef(TermText));
+                if (status == TermsEnum.SeekStatus.FOUND)
+                {
+                    mtv.VisitMatchingTerm(GetLuceneTerm(fieldName));
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1e7576a6/Lucene.Net.QueryParser/Surround/Query/SrndTruncQuery.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.QueryParser/Surround/Query/SrndTruncQuery.cs b/Lucene.Net.QueryParser/Surround/Query/SrndTruncQuery.cs
new file mode 100644
index 0000000..5ed9ff3
--- /dev/null
+++ b/Lucene.Net.QueryParser/Surround/Query/SrndTruncQuery.cs
@@ -0,0 +1,139 @@
+using Lucene.Net.Index;
+using Lucene.Net.Util;
+using System;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace Lucene.Net.QueryParser.Surround.Query
+{
+    /*
+     * 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.
+     */
+
+    public class SrndTruncQuery : SimpleTerm
+    {
+        public SrndTruncQuery(string truncated, char unlimited, char mask)
+            : base(false) /* not quoted */
+        {
+            this.truncated = truncated;
+            this.unlimited = unlimited;
+            this.mask = mask;
+            TruncatedToPrefixAndPattern();
+        }
+
+        private readonly string truncated;
+        private readonly char unlimited;
+        private readonly char mask;
+
+        private string prefix;
+        private BytesRef prefixRef;
+        private Regex pattern;
+
+        public virtual string Truncated { get { return truncated; } }
+
+        public override string ToStringUnquoted()
+        {
+            return Truncated;
+        }
+
+        protected virtual bool MatchingChar(char c)
+        {
+            return (c != unlimited) && (c != mask);
+        }
+
+        protected virtual void AppendRegExpForChar(char c, StringBuilder re)
+        {
+            if (c == unlimited)
+                re.Append(".*");
+            else if (c == mask)
+                re.Append(".");
+            else
+                re.Append(c);
+        }
+
+        protected virtual void TruncatedToPrefixAndPattern()
+        {
+            int i = 0;
+            while ((i < truncated.Length) && MatchingChar(truncated[i]))
+            {
+                i++;
+            }
+            prefix = truncated.Substring(0, i);
+            prefixRef = new BytesRef(prefix);
+
+            StringBuilder re = new StringBuilder();
+            while (i < truncated.Length)
+            {
+                AppendRegExpForChar(truncated[i], re);
+                i++;
+            }
+            pattern = new Regex(re.ToString(), RegexOptions.Compiled);
+        }
+
+        // TODO: Finish implementation
+        public override void VisitMatchingTerms(IndexReader reader, string fieldName, SimpleTerm.IMatchingTermVisitor mtv)
+        {
+            throw new NotImplementedException("Need to translate this from Java's whacky RegEx syntax");
+            //int prefixLength = prefix.Length;
+            //Terms terms = MultiFields.GetTerms(reader, fieldName);
+            //if (terms != null)
+            //{
+            //    MatchCollection matcher = pattern.Matches("");
+            //    try
+            //    {
+            //        TermsEnum termsEnum = terms.Iterator(null);
+
+            //        TermsEnum.SeekStatus status = termsEnum.SeekCeil(prefixRef);
+            //        BytesRef text;
+            //        if (status == TermsEnum.SeekStatus.FOUND)
+            //        {
+            //            text = prefixRef;
+            //        }
+            //        else if (status == TermsEnum.SeekStatus.NOT_FOUND)
+            //        {
+            //            text = termsEnum.Term();
+            //        }
+            //        else
+            //        {
+            //            text = null;
+            //        }
+
+            //        while (text != null)
+            //        {
+            //            if (text != null && StringHelper.StartsWith(text, prefixRef))
+            //            {
+            //                string textString = text.Utf8ToString();
+            //                matcher.Reset(textString.Substring(prefixLength));
+            //                if (matcher.Success)
+            //                {
+            //                    mtv.VisitMatchingTerm(new Term(fieldName, textString));
+            //                }
+            //            }
+            //            else
+            //            {
+            //                break;
+            //            }
+            //            text = termsEnum.Next();
+            //        }
+            //    }
+            //    finally
+            //    {
+            //        matcher.Reset();
+            //    }
+            //}
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1e7576a6/Lucene.Net.QueryParser/Surround/Query/TooManyBasicQueries.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.QueryParser/Surround/Query/TooManyBasicQueries.cs b/Lucene.Net.QueryParser/Surround/Query/TooManyBasicQueries.cs
new file mode 100644
index 0000000..27f313c
--- /dev/null
+++ b/Lucene.Net.QueryParser/Surround/Query/TooManyBasicQueries.cs
@@ -0,0 +1,30 @@
+namespace Lucene.Net.QueryParser.Surround.Query
+{
+    /*
+     * 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>
+    /// Exception thrown when <see cref="BasicQueryFactory"/> would exceed the limit
+    /// of query clauses.
+    /// </summary>
+    public class TooManyBasicQueries : System.IO.IOException
+    {
+        public TooManyBasicQueries(int maxBasicQueries)
+            : base("Exceeded maximum of " + maxBasicQueries + " basic queries.")
+        { }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1e7576a6/Lucene.Net.Tests.QueryParser/Lucene.Net.Tests.QueryParser.csproj
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/Lucene.Net.Tests.QueryParser.csproj b/Lucene.Net.Tests.QueryParser/Lucene.Net.Tests.QueryParser.csproj
index bcf9568..2094270 100644
--- a/Lucene.Net.Tests.QueryParser/Lucene.Net.Tests.QueryParser.csproj
+++ b/Lucene.Net.Tests.QueryParser/Lucene.Net.Tests.QueryParser.csproj
@@ -54,6 +54,13 @@
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Classic\TestMultiAnalyzer.cs" />
     <Compile Include="Simple\TestSimpleQueryParser.cs" />
+    <Compile Include="Surround\Query\BooleanQueryTst.cs" />
+    <Compile Include="Surround\Query\ExceptionQueryTst.cs" />
+    <Compile Include="Surround\Query\SingleFieldTestDb.cs" />
+    <Compile Include="Surround\Query\SrndQueryTest.cs" />
+    <Compile Include="Surround\Query\Test01Exceptions.cs" />
+    <Compile Include="Surround\Query\Test02Boolean.cs" />
+    <Compile Include="Surround\Query\Test03Distance.cs" />
     <Compile Include="Util\QueryParserTestBase.cs" />
   </ItemGroup>
   <ItemGroup>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1e7576a6/Lucene.Net.Tests.QueryParser/Surround/Query/BooleanQueryTst.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/Surround/Query/BooleanQueryTst.cs b/Lucene.Net.Tests.QueryParser/Surround/Query/BooleanQueryTst.cs
new file mode 100644
index 0000000..6f7fcfc
--- /dev/null
+++ b/Lucene.Net.Tests.QueryParser/Surround/Query/BooleanQueryTst.cs
@@ -0,0 +1,142 @@
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using NUnit.Framework;
+using System;
+
+namespace Lucene.Net.QueryParser.Surround.Query
+{
+    /*
+     * 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.
+     */
+
+    public class BooleanQueryTst
+    {
+        private string queryText;
+        private readonly int[] expectedDocNrs;
+        private SingleFieldTestDb dBase;
+        private string fieldName;
+        private Assert testCase;
+        private BasicQueryFactory qf;
+        private bool verbose = true;
+
+        public BooleanQueryTst(
+            string queryText,
+            int[] expectedDocNrs,
+            SingleFieldTestDb dBase,
+            string fieldName,
+            Assert testCase,
+            BasicQueryFactory qf)
+        {
+            this.queryText = queryText;
+            this.expectedDocNrs = expectedDocNrs;
+            this.dBase = dBase;
+            this.fieldName = fieldName;
+            this.testCase = testCase;
+            this.qf = qf;
+        }
+
+        public virtual bool Verbose { set { this.verbose = value; } }
+
+        public virtual string QueryText { get { return this.queryText; } }
+
+        public virtual int[] ExpectedDocNrs { get { return this.expectedDocNrs; } }
+
+        internal class TestCollector : Collector
+        { // FIXME: use check hits from Lucene tests
+            private int totalMatched;
+            private bool[] encountered;
+            private Scorer scorer = null;
+            private int docBase = 0;
+            private BooleanQueryTst parent;
+
+            public TestCollector(BooleanQueryTst parent)
+            {
+                totalMatched = 0;
+                encountered = new bool[parent.expectedDocNrs.Length];
+                this.parent = parent;
+            }
+
+            public override Scorer Scorer
+            {
+                set { this.scorer = value; }
+            }
+
+            public override bool AcceptsDocsOutOfOrder()
+            {
+                return true;
+            }
+
+            public override AtomicReaderContext NextReader
+            {
+                set { docBase = value.DocBase; }
+            }
+
+            public override void Collect(int docNr)
+            {
+                float score = scorer.Score();
+                docNr += docBase;
+                /* System.out.println(docNr + " '" + dBase.getDocs()[docNr] + "': " + score); */
+                Assert.True(score > 0.0, parent.QueryText + ": positive score");
+                Assert.True(totalMatched < parent.ExpectedDocNrs.Length, parent.QueryText + ": too many hits");
+                int i;
+                for (i = 0; i < parent.expectedDocNrs.Length; i++)
+                {
+                    if ((!encountered[i]) && (parent.ExpectedDocNrs[i] == docNr))
+                    {
+                        encountered[i] = true;
+                        break;
+                    }
+                }
+                if (i == parent.ExpectedDocNrs.Length)
+                {
+                    Assert.True(false, parent.QueryText + ": doc nr for hit not expected: " + docNr);
+                }
+                totalMatched++;
+            }
+
+            public void CheckNrHits()
+            {
+                Assert.AreEqual(parent.ExpectedDocNrs.Length, totalMatched, parent.QueryText + ": nr of hits");
+            }
+        }
+
+        public void DoTest()
+        {
+
+            if (verbose)
+            {
+                Console.WriteLine("");
+                Console.WriteLine("Query: " + queryText);
+            }
+
+            SrndQuery lq = Parser.QueryParser.Parse(queryText);
+
+            /* if (verbose) System.out.println("Srnd: " + lq.toString()); */
+
+            Search.Query query = lq.MakeLuceneQueryField(fieldName, qf);
+            /* if (verbose) System.out.println("Lucene: " + query.toString()); */
+
+            TestCollector tc = new TestCollector(this);
+            using (IndexReader reader = DirectoryReader.Open(dBase.Db))
+            {
+                IndexSearcher searcher = new IndexSearcher(reader);
+
+                searcher.Search(query, tc);
+            }
+            tc.CheckNrHits();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1e7576a6/Lucene.Net.Tests.QueryParser/Surround/Query/ExceptionQueryTst.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/Surround/Query/ExceptionQueryTst.cs b/Lucene.Net.Tests.QueryParser/Surround/Query/ExceptionQueryTst.cs
new file mode 100644
index 0000000..7468ef9
--- /dev/null
+++ b/Lucene.Net.Tests.QueryParser/Surround/Query/ExceptionQueryTst.cs
@@ -0,0 +1,76 @@
+using Lucene.Net.QueryParser.Surround.Parser;
+using System;
+using System.Text;
+
+namespace Lucene.Net.QueryParser.Surround.Query
+{
+    /*
+     * 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.
+     */
+
+    public class ExceptionQueryTst
+    {
+        private string queryText;
+        private bool verbose;
+
+        public ExceptionQueryTst(string queryText, bool verbose)
+        {
+            this.queryText = queryText;
+            this.verbose = verbose;
+        }
+
+        public void DoTest(StringBuilder failQueries)
+        {
+            bool pass = false;
+            SrndQuery lq = null;
+            try
+            {
+                lq = Parser.QueryParser.Parse(queryText);
+                if (verbose)
+                {
+                    Console.WriteLine("Query: " + queryText + "\nParsed as: " + lq.ToString());
+                }
+            }
+            catch (ParseException e)
+            {
+                if (verbose)
+                {
+                    Console.WriteLine("Parse exception for query:\n"
+                                      + queryText + "\n"
+                                      + e.Message);
+                }
+                pass = true;
+            }
+            if (!pass)
+            {
+                failQueries.append(queryText);
+                failQueries.append("\nParsed as: ");
+                failQueries.append(lq.toString());
+                failQueries.append("\n");
+            }
+        }
+
+        public static string GetFailQueries(string[] exceptionQueries, bool verbose)
+        {
+            StringBuilder failQueries = new StringBuilder();
+            for (int i = 0; i < exceptionQueries.Length; i++)
+            {
+                new ExceptionQueryTst(exceptionQueries[i], verbose).DoTest(failQueries);
+            }
+            return failQueries.toString();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1e7576a6/Lucene.Net.Tests.QueryParser/Surround/Query/SingleFieldTestDb.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/Surround/Query/SingleFieldTestDb.cs b/Lucene.Net.Tests.QueryParser/Surround/Query/SingleFieldTestDb.cs
new file mode 100644
index 0000000..1221835
--- /dev/null
+++ b/Lucene.Net.Tests.QueryParser/Surround/Query/SingleFieldTestDb.cs
@@ -0,0 +1,55 @@
+using Lucene.Net.Analysis;
+using Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Store;
+using Lucene.Net.Util;
+using System;
+
+namespace Lucene.Net.QueryParser.Surround.Query
+{
+    /*
+     * 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.
+     */
+
+    public class SingleFieldTestDb
+    {
+        private Directory db;
+        private string[] docs;
+        private string fieldName;
+
+        public SingleFieldTestDb(Random random, string[] documents, string fName)
+        {
+            db = new MockDirectoryWrapper(random, new RAMDirectory());
+            docs = documents;
+            fieldName = fName;
+            using (IndexWriter writer = new IndexWriter(db, new IndexWriterConfig(
+                LuceneVersion.LUCENE_CURRENT,
+                new MockAnalyzer(random))))
+            {
+                for (int j = 0; j < docs.Length; j++)
+                {
+                    Document d = new Document();
+                    d.Add(new TextField(fieldName, docs[j], Field.Store.NO));
+                    writer.AddDocument(d);
+                }
+            }
+        }
+
+        public Directory Db { get { return db; } }
+        public string[] Docs { get { return docs; } }
+        public string Fieldname { get { return fieldName; } }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1e7576a6/Lucene.Net.Tests.QueryParser/Surround/Query/SrndQueryTest.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/Surround/Query/SrndQueryTest.cs b/Lucene.Net.Tests.QueryParser/Surround/Query/SrndQueryTest.cs
new file mode 100644
index 0000000..ebe7e2b
--- /dev/null
+++ b/Lucene.Net.Tests.QueryParser/Surround/Query/SrndQueryTest.cs
@@ -0,0 +1,48 @@
+using Lucene.Net.Search;
+using Lucene.Net.Util;
+using NUnit.Framework;
+
+namespace Lucene.Net.QueryParser.Surround.Query
+{
+    /*
+     * 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.
+     */
+
+    [TestFixture]
+    public class SrndQueryTest : LuceneTestCase
+    {
+        private void CheckEqualParsings(string s1, string s2)
+        {
+            string fieldName = "foo";
+            BasicQueryFactory qf = new BasicQueryFactory(16);
+            Search.Query lq1, lq2;
+            lq1 = Parser.QueryParser.Parse(s1).MakeLuceneQueryField(fieldName, qf);
+            lq2 = Parser.QueryParser.Parse(s2).MakeLuceneQueryField(fieldName, qf);
+            QueryUtils.CheckEqual(lq1, lq2);
+        }
+
+        [Test]
+        public void TestHashEquals()
+        {
+            //grab some sample queries from Test02Boolean and Test03Distance and
+            //check there hashes and equals
+            CheckEqualParsings("word1 w word2", " word1  w  word2 ");
+            CheckEqualParsings("2N(w1,w2,w3)", " 2N(w1, w2 , w3)");
+            CheckEqualParsings("abc?", " abc? ");
+            CheckEqualParsings("w*rd?", " w*rd?");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1e7576a6/Lucene.Net.Tests.QueryParser/Surround/Query/Test01Exceptions.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/Surround/Query/Test01Exceptions.cs b/Lucene.Net.Tests.QueryParser/Surround/Query/Test01Exceptions.cs
new file mode 100644
index 0000000..6ebc87a
--- /dev/null
+++ b/Lucene.Net.Tests.QueryParser/Surround/Query/Test01Exceptions.cs
@@ -0,0 +1,72 @@
+using Lucene.Net.Util;
+using NUnit.Framework;
+
+namespace Lucene.Net.QueryParser.Surround.Query
+{
+    /*
+     * 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.
+     */
+
+    [TestFixture]
+    public class Test01Exceptions_ : LuceneTestCase
+    {
+        /** Main for running test case by itself. */
+        //public static void Main(string[] args)
+        //{
+        //    TestRunner.run(new TestSuite(Test01Exceptions.class));
+        //}
+
+        private bool verbose = false; /* to show actual parsing error messages */
+        private readonly string fieldName = "bi";
+
+        string[] exceptionQueries = {
+            "*",
+            "a*",
+            "ab*",
+            "?",
+            "a?",
+            "ab?",
+            "a???b",
+            "a?",
+            "a*b?",
+            "word1 word2",
+            "word2 AND",
+            "word1 OR",
+            "AND(word2)",
+            "AND(word2,)",
+            "AND(word2,word1,)",
+            "OR(word2)",
+            "OR(word2 ,",
+            "OR(word2 , word1 ,)",
+            "xx NOT",
+            "xx (a AND b)",
+            "(a AND b",
+            "a OR b)",
+            "or(word2+ not ord+, and xyz,def)",
+            ""
+        };
+
+        [Test]
+        public void Test01Exceptions()
+        {
+            string m = ExceptionQueryTst.GetFailQueries(exceptionQueries, verbose);
+            if (m.Length > 0)
+            {
+                fail("No ParseException for:\n" + m);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1e7576a6/Lucene.Net.Tests.QueryParser/Surround/Query/Test02Boolean.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/Surround/Query/Test02Boolean.cs b/Lucene.Net.Tests.QueryParser/Surround/Query/Test02Boolean.cs
new file mode 100644
index 0000000..aef9279
--- /dev/null
+++ b/Lucene.Net.Tests.QueryParser/Surround/Query/Test02Boolean.cs
@@ -0,0 +1,178 @@
+using Lucene.Net.Util;
+using NUnit.Framework;
+using System;
+
+namespace Lucene.Net.QueryParser.Surround.Query
+{
+    /*
+     * 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.
+     */
+
+    [TestFixture]
+    public class Test02Boolean : LuceneTestCase
+    {
+        //public static void Main(string[] args) {
+        //    TestRunner.run(new TestSuite(Test02Boolean.class));
+        //}
+
+        private readonly string fieldName = "bi";
+        private bool verbose = false;
+        private int maxBasicQueries = 16;
+
+        string[] docs1 = {
+            "word1 word2 word3",
+            "word4 word5",
+            "ord1 ord2 ord3",
+            "orda1 orda2 orda3 word2 worda3",
+            "a c e a b c"
+        };
+
+        public override void SetUp()
+        {
+            base.SetUp();
+            db1 = new SingleFieldTestDb(Random(), docs1, fieldName);
+        }
+
+        private SingleFieldTestDb db1;
+
+
+        public void NormalTest1(String query, int[] expdnrs)
+        {
+            BooleanQueryTst bqt = new BooleanQueryTst(query, expdnrs, db1, fieldName, this,
+                                                        new BasicQueryFactory(maxBasicQueries));
+            bqt.Verbose = (verbose);
+            bqt.DoTest();
+        }
+
+        [Test]
+        public void Test02Terms01()
+        {
+            int[] expdnrs = { 0 }; NormalTest1("word1", expdnrs);
+        }
+        [Test]
+        public void Test02Terms02()
+        {
+            int[] expdnrs = { 0, 1, 3 }; NormalTest1("word*", expdnrs);
+        }
+        [Test]
+        public void Test02Terms03()
+        {
+            int[] expdnrs = { 2 }; NormalTest1("ord2", expdnrs);
+        }
+        [Test]
+        public void Test02Terms04()
+        {
+            int[] expdnrs = { }; NormalTest1("kxork*", expdnrs);
+        }
+        [Test]
+        public void Test02Terms05()
+        {
+            int[] expdnrs = { 0, 1, 3 }; NormalTest1("wor*", expdnrs);
+        }
+        [Test]
+        public void Test02Terms06()
+        {
+            int[] expdnrs = { }; NormalTest1("ab", expdnrs);
+        }
+
+        [Test]
+        public void Test02Terms10()
+        {
+            int[] expdnrs = { }; NormalTest1("abc?", expdnrs);
+        }
+        [Test]
+        public void Test02Terms13()
+        {
+            int[] expdnrs = { 0, 1, 3 }; NormalTest1("word?", expdnrs);
+        }
+        [Test]
+        public void Test02Terms14()
+        {
+            int[] expdnrs = { 0, 1, 3 }; NormalTest1("w?rd?", expdnrs);
+        }
+        [Test]
+        public void Test02Terms20()
+        {
+            int[] expdnrs = { 0, 1, 3 }; NormalTest1("w*rd?", expdnrs);
+        }
+        [Test]
+        public void Test02Terms21()
+        {
+            int[] expdnrs = { 3 }; NormalTest1("w*rd??", expdnrs);
+        }
+        [Test]
+        public void Test02Terms22()
+        {
+            int[] expdnrs = { 3 }; NormalTest1("w*?da?", expdnrs);
+        }
+        [Test]
+        public void Test02Terms23()
+        {
+            int[] expdnrs = { }; NormalTest1("w?da?", expdnrs);
+        }
+
+        [Test]
+        public void Test03And01()
+        {
+            int[] expdnrs = { 0 }; NormalTest1("word1 AND word2", expdnrs);
+        }
+        [Test]
+        public void Test03And02()
+        {
+            int[] expdnrs = { 3 }; NormalTest1("word* and ord*", expdnrs);
+        }
+        [Test]
+        public void Test03And03()
+        {
+            int[] expdnrs = { 0 }; NormalTest1("and(word1,word2)", expdnrs);
+        }
+        [Test]
+        public void Test04Or01()
+        {
+            int[] expdnrs = { 0, 3 }; NormalTest1("word1 or word2", expdnrs);
+        }
+        [Test]
+        public void Test04Or02()
+        {
+            int[] expdnrs = { 0, 1, 2, 3 }; NormalTest1("word* OR ord*", expdnrs);
+        }
+        [Test]
+        public void Test04Or03()
+        {
+            int[] expdnrs = { 0, 3 }; NormalTest1("OR (word1, word2)", expdnrs);
+        }
+        [Test]
+        public void Test05Not01()
+        {
+            int[] expdnrs = { 3 }; NormalTest1("word2 NOT word1", expdnrs);
+        }
+        [Test]
+        public void Test05Not02()
+        {
+            int[] expdnrs = { 0 }; NormalTest1("word2* not ord*", expdnrs);
+        }
+        [Test]
+        public void Test06AndOr01()
+        {
+            int[] expdnrs = { 0 }; NormalTest1("(word1 or ab)and or(word2,xyz, defg)", expdnrs);
+        }
+        [Test]
+        public void Test07AndOrNot02()
+        {
+            int[] expdnrs = { 0 }; NormalTest1("or( word2* not ord*, and(xyz,def))", expdnrs);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1e7576a6/Lucene.Net.Tests.QueryParser/Surround/Query/Test03Distance.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/Surround/Query/Test03Distance.cs b/Lucene.Net.Tests.QueryParser/Surround/Query/Test03Distance.cs
new file mode 100644
index 0000000..6a19cb7
--- /dev/null
+++ b/Lucene.Net.Tests.QueryParser/Surround/Query/Test03Distance.cs
@@ -0,0 +1,341 @@
+using Lucene.Net.Util;
+using NUnit.Framework;
+using System;
+
+namespace Lucene.Net.QueryParser.Surround.Query
+{
+    /*
+     * 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.
+     */
+
+    [TestFixture]
+    public class Test03Distance : LuceneTestCase
+    {
+        //public static void Main(string[] args) {
+        //    TestRunner.run(new TestSuite(Test03Distance.class));
+        //}
+
+        private bool verbose = false;
+        private int maxBasicQueries = 16;
+
+        private string[] exceptionQueries = {
+            "(aa and bb) w cc",
+            "(aa or bb) w (cc and dd)",
+            "(aa opt bb) w cc",
+            "(aa not bb) w cc",
+            "(aa or bb) w (bi:cc)",
+            "(aa or bb) w bi:cc",
+            "(aa or bi:bb) w cc",
+            "(aa or (bi:bb)) w cc",
+            "(aa or (bb and dd)) w cc"
+        };
+
+        [Test]
+        public void Test00Exceptions()
+        {
+            string m = ExceptionQueryTst.GetFailQueries(exceptionQueries, verbose);
+            if (m.Length > 0)
+            {
+                fail("No ParseException for:\n" + m);
+            }
+        }
+
+        private readonly string fieldName = "bi";
+
+        private string[] docs1 = {
+            "word1 word2 word3",
+            "word4 word5",
+            "ord1 ord2 ord3",
+            "orda1 orda2 orda3 word2 worda3",
+            "a c e a b c"
+        };
+
+        SingleFieldTestDb db1;
+
+        public override void SetUp()
+        {
+            base.SetUp();
+            db1 = new SingleFieldTestDb(Random(), docs1, fieldName);
+            db2 = new SingleFieldTestDb(Random(), docs2, fieldName);
+            db3 = new SingleFieldTestDb(Random(), docs3, fieldName);
+        }
+
+        private void DistanceTst(String query, int[] expdnrs, SingleFieldTestDb db)
+        {
+            BooleanQueryTst bqt = new BooleanQueryTst(query, expdnrs, db, fieldName, this,
+                                                        new BasicQueryFactory(maxBasicQueries));
+            bqt.Verbose = (verbose);
+            bqt.DoTest();
+        }
+
+        public void DistanceTest1(string query, int[] expdnrs)
+        {
+            DistanceTst(query, expdnrs, db1);
+        }
+
+        [Test]
+        public void Test0W01()
+        {
+            int[] expdnrs = { 0 }; DistanceTest1("word1 w word2", expdnrs);
+        }
+        [Test]
+        public void Test0N01()
+        {
+            int[] expdnrs = { 0 }; DistanceTest1("word1 n word2", expdnrs);
+        }
+        [Test]
+        public void Test0N01r()
+        { /* r reverse */
+            int[] expdnrs = { 0 }; DistanceTest1("word2 n word1", expdnrs);
+        }
+        [Test]
+        public void Test0W02()
+        {
+            int[] expdnrs = { }; DistanceTest1("word2 w word1", expdnrs);
+        }
+        [Test]
+        public void Test0W03()
+        {
+            int[] expdnrs = { }; DistanceTest1("word2 2W word1", expdnrs);
+        }
+        [Test]
+        public void Test0N03()
+        {
+            int[] expdnrs = { 0 }; DistanceTest1("word2 2N word1", expdnrs);
+        }
+        [Test]
+        public void Test0N03r()
+        {
+            int[] expdnrs = { 0 }; DistanceTest1("word1 2N word2", expdnrs);
+        }
+
+        [Test]
+        public void Test0W04()
+        {
+            int[] expdnrs = { }; DistanceTest1("word2 3w word1", expdnrs);
+        }
+
+        [Test]
+        public void Test0N04()
+        {
+            int[] expdnrs = { 0 }; DistanceTest1("word2 3n word1", expdnrs);
+        }
+        [Test]
+        public void Test0N04r()
+        {
+            int[] expdnrs = { 0 }; DistanceTest1("word1 3n word2", expdnrs);
+        }
+
+        [Test]
+        public void Test0W05()
+        {
+            int[] expdnrs = { }; DistanceTest1("orda1 w orda3", expdnrs);
+        }
+        [Test]
+        public void Test0W06()
+        {
+            int[] expdnrs = { 3 }; DistanceTest1("orda1 2w orda3", expdnrs);
+        }
+
+        [Test]
+        public void Test1Wtrunc01()
+        {
+            int[] expdnrs = { 0 }; DistanceTest1("word1* w word2", expdnrs);
+        }
+        [Test]
+        public void Test1Wtrunc02()
+        {
+            int[] expdnrs = { 0 }; DistanceTest1("word* w word2", expdnrs);
+        }
+        [Test]
+        public void Test1Wtrunc02r()
+        {
+            int[] expdnrs = { 0, 3 }; DistanceTest1("word2 w word*", expdnrs);
+        }
+        [Test]
+        public void Test1Ntrunc02()
+        {
+            int[] expdnrs = { 0, 3 }; DistanceTest1("word* n word2", expdnrs);
+        }
+        [Test]
+        public void Test1Ntrunc02r()
+        {
+            int[] expdnrs = { 0, 3 }; DistanceTest1("word2 n word*", expdnrs);
+        }
+
+        [Test]
+        public void Test1Wtrunc03()
+        {
+            int[] expdnrs = { 0 }; DistanceTest1("word1* w word2*", expdnrs);
+        }
+        [Test]
+        public void Test1Ntrunc03()
+        {
+            int[] expdnrs = { 0 }; DistanceTest1("word1* N word2*", expdnrs);
+        }
+
+        [Test]
+        public void Test1Wtrunc04()
+        {
+            int[] expdnrs = { }; DistanceTest1("kxork* w kxor*", expdnrs);
+        }
+        [Test]
+        public void Test1Ntrunc04()
+        {
+            int[] expdnrs = { }; DistanceTest1("kxork* 99n kxor*", expdnrs);
+        }
+
+        [Test]
+        public void Test1Wtrunc05()
+        {
+            int[] expdnrs = { }; DistanceTest1("word2* 2W word1*", expdnrs);
+        }
+        [Test]
+        public void Test1Ntrunc05()
+        {
+            int[] expdnrs = { 0 }; DistanceTest1("word2* 2N word1*", expdnrs);
+        }
+
+        [Test]
+        public void Test1Wtrunc06()
+        {
+            int[] expdnrs = { 3 }; DistanceTest1("ord* W word*", expdnrs);
+        }
+        [Test]
+        public void Test1Ntrunc06()
+        {
+            int[] expdnrs = { 3 }; DistanceTest1("ord* N word*", expdnrs);
+        }
+        [Test]
+        public void Test1Ntrunc06r()
+        {
+            int[] expdnrs = { 3 }; DistanceTest1("word* N ord*", expdnrs);
+        }
+
+        [Test]
+        public void Test1Wtrunc07()
+        {
+            int[] expdnrs = { 3 }; DistanceTest1("(orda2 OR orda3) W word*", expdnrs);
+        }
+        [Test]
+        public void Test1Wtrunc08()
+        {
+            int[] expdnrs = { 3 }; DistanceTest1("(orda2 OR orda3) W (word2 OR worda3)", expdnrs);
+        }
+        [Test]
+        public void Test1Wtrunc09()
+        {
+            int[] expdnrs = { 3 }; DistanceTest1("(orda2 OR orda3) 2W (word2 OR worda3)", expdnrs);
+        }
+        [Test]
+        public void Test1Ntrunc09()
+        {
+            int[] expdnrs = { 3 }; DistanceTest1("(orda2 OR orda3) 2N (word2 OR worda3)", expdnrs);
+        }
+
+        string[] docs2 = {
+            "w1 w2 w3 w4 w5",
+            "w1 w3 w2 w3",
+            ""
+        };
+
+        SingleFieldTestDb db2;
+
+        public void DistanceTest2(string query, int[] expdnrs)
+        {
+            DistanceTst(query, expdnrs, db2);
+        }
+
+        [Test]
+        public void Test2Wprefix01()
+        {
+            int[] expdnrs = { 0 }; DistanceTest2("W (w1, w2, w3)", expdnrs);
+        }
+        [Test]
+        public void Test2Nprefix01a()
+        {
+            int[] expdnrs = { 0, 1 }; DistanceTest2("N(w1, w2, w3)", expdnrs);
+        }
+        [Test]
+        public void Test2Nprefix01b()
+        {
+            int[] expdnrs = { 0, 1 }; DistanceTest2("N(w3, w1, w2)", expdnrs);
+        }
+
+        [Test]
+        public void Test2Wprefix02()
+        {
+            int[] expdnrs = { 0, 1 }; DistanceTest2("2W(w1,w2,w3)", expdnrs);
+        }
+
+        [Test]
+        public void Test2Nprefix02a()
+        {
+            int[] expdnrs = { 0, 1 }; DistanceTest2("2N(w1,w2,w3)", expdnrs);
+        }
+        [Test]
+        public void Test2Nprefix02b()
+        {
+            int[] expdnrs = { 0, 1 }; DistanceTest2("2N(w2,w3,w1)", expdnrs);
+        }
+
+        [Test]
+        public void Test2Wnested01()
+        {
+            int[] expdnrs = { 0 }; DistanceTest2("w1 W w2 W w3", expdnrs);
+        }
+        [Test]
+        public void Test2Nnested01()
+        {
+            int[] expdnrs = { 0 }; DistanceTest2("w1 N w2 N w3", expdnrs);
+        }
+
+        [Test]
+        public void Test2Wnested02()
+        {
+            int[] expdnrs = { 0, 1 }; DistanceTest2("w1 2W w2 2W w3", expdnrs);
+        }
+        [Test]
+        public void Test2Nnested02()
+        {
+            int[] expdnrs = { 0, 1 }; DistanceTest2("w1 2N w2 2N w3", expdnrs);
+        }
+
+        string[] docs3 = {
+            "low pressure temperature inversion and rain",
+            "when the temperature has a negative height above a depression no precipitation gradient is expected",
+            "when the temperature has a negative height gradient above a depression no precipitation is expected",
+            ""
+        };
+
+        SingleFieldTestDb db3;
+
+        public void DistanceTest3(string query, int[] expdnrs)
+        {
+            DistanceTst(query, expdnrs, db3);
+        }
+
+        [Test]
+        public void Test3Example01()
+        {
+            int[] expdnrs = { 0, 2 }; // query does not match doc 1 because "gradient" is in wrong place there.
+            DistanceTest3("50n((low w pressure*) or depression*,"
+                           + "5n(temperat*, (invers* or (negativ* 3n gradient*))),"
+                           + "rain* or precipitat*)",
+                           expdnrs);
+        }
+    }
+}


Mime
View raw message