lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject svn commit: r1375244 - in /incubator/lucene.net/trunk: lib/Spatial4n/NET35/ lib/Spatial4n/NET40/ src/contrib/Spatial/ src/contrib/Spatial/BBox/ src/contrib/Spatial/Prefix/ src/contrib/Spatial/Queries/ src/contrib/Spatial/Vector/ test/contrib/Spatial/ t...
Date Mon, 20 Aug 2012 21:44:00 GMT
Author: synhershko
Date: Mon Aug 20 21:43:59 2012
New Revision: 1375244

URL: http://svn.apache.org/viewvc?rev=1375244&view=rev
Log:
LUCENE-4167 - migrate Spatial4n.Core.Query to Lucene spatial

Migrate UnsupportedSpatialOperation too.

Added:
    incubator/lucene.net/trunk/lib/Spatial4n/NET35/TODO
    incubator/lucene.net/trunk/src/contrib/Spatial/Queries/
    incubator/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgs.cs
    incubator/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgsParser.cs
    incubator/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialOperation.cs
    incubator/lucene.net/trunk/src/contrib/Spatial/Queries/UnsupportedSpatialOperation.cs
    incubator/lucene.net/trunk/test/contrib/Spatial/Query/
    incubator/lucene.net/trunk/test/contrib/Spatial/Query/SpatialArgsParserTest.cs
Removed:
    incubator/lucene.net/trunk/lib/Spatial4n/NET35/Spatial4n.Core.dll
    incubator/lucene.net/trunk/lib/Spatial4n/NET35/Spatial4n.Core.pdb
Modified:
    incubator/lucene.net/trunk/lib/Spatial4n/NET40/Spatial4n.Core.dll
    incubator/lucene.net/trunk/lib/Spatial4n/NET40/Spatial4n.Core.pdb
    incubator/lucene.net/trunk/src/contrib/Spatial/BBox/BBoxSimilarityValueSource.cs
    incubator/lucene.net/trunk/src/contrib/Spatial/BBox/BBoxStrategy.cs
    incubator/lucene.net/trunk/src/contrib/Spatial/Contrib.Spatial.csproj
    incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/PrefixTreeStrategy.cs
    incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/RecursivePrefixTreeStrategy.cs
    incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/TermQueryPrefixTreeStrategy.cs
    incubator/lucene.net/trunk/src/contrib/Spatial/SpatialStrategy.cs
    incubator/lucene.net/trunk/src/contrib/Spatial/Vector/DistanceValueSource.cs
    incubator/lucene.net/trunk/src/contrib/Spatial/Vector/TwoDoublesStrategy.cs
    incubator/lucene.net/trunk/test/contrib/Spatial/Contrib.Spatial.Test.csproj

Added: incubator/lucene.net/trunk/lib/Spatial4n/NET35/TODO
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/lib/Spatial4n/NET35/TODO?rev=1375244&view=auto
==============================================================================
--- incubator/lucene.net/trunk/lib/Spatial4n/NET35/TODO (added)
+++ incubator/lucene.net/trunk/lib/Spatial4n/NET35/TODO Mon Aug 20 21:43:59 2012
@@ -0,0 +1 @@
+

Modified: incubator/lucene.net/trunk/lib/Spatial4n/NET40/Spatial4n.Core.dll
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/lib/Spatial4n/NET40/Spatial4n.Core.dll?rev=1375244&r1=1375243&r2=1375244&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/lucene.net/trunk/lib/Spatial4n/NET40/Spatial4n.Core.pdb
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/lib/Spatial4n/NET40/Spatial4n.Core.pdb?rev=1375244&r1=1375243&r2=1375244&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/lucene.net/trunk/src/contrib/Spatial/BBox/BBoxSimilarityValueSource.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/BBox/BBoxSimilarityValueSource.cs?rev=1375244&r1=1375243&r2=1375244&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/BBox/BBoxSimilarityValueSource.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/BBox/BBoxSimilarityValueSource.cs Mon Aug
20 21:43:59 2012
@@ -43,8 +43,7 @@ namespace Lucene.Net.Spatial.BBox
 			private readonly double[] maxX;
 			private readonly double[] maxY;
 
-			private readonly Bits validMinX;
-			private readonly Bits validMaxX;
+			private readonly IBits validMinX, validMaxX;
 
 			public BBoxSimilarityValueSourceDocValues(IndexReader reader, BBoxSimilarityValueSource
enclosingInstance)
 			{

Modified: incubator/lucene.net/trunk/src/contrib/Spatial/BBox/BBoxStrategy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/BBox/BBoxStrategy.cs?rev=1375244&r1=1375243&r2=1375244&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/BBox/BBoxStrategy.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/BBox/BBoxStrategy.cs Mon Aug 20 21:43:59
2012
@@ -19,8 +19,8 @@ using System;
 using Lucene.Net.Documents;
 using Lucene.Net.Search;
 using Lucene.Net.Search.Function;
+using Lucene.Net.Spatial.Queries;
 using Spatial4n.Core.Context;
-using Spatial4n.Core.Query;
 using Spatial4n.Core.Shapes;
 
 namespace Lucene.Net.Spatial.BBox

Modified: incubator/lucene.net/trunk/src/contrib/Spatial/Contrib.Spatial.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Contrib.Spatial.csproj?rev=1375244&r1=1375243&r2=1375244&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Contrib.Spatial.csproj (original)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Contrib.Spatial.csproj Mon Aug 20 21:43:59
2012
@@ -140,6 +140,10 @@
     <Compile Include="Prefix\Tree\SpatialPrefixTree.cs" />
     <Compile Include="Prefix\Tree\SpatialPrefixTreeFactory.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Queries\SpatialArgs.cs" />
+    <Compile Include="Queries\SpatialArgsParser.cs" />
+    <Compile Include="Queries\SpatialOperation.cs" />
+    <Compile Include="Queries\UnsupportedSpatialOperation.cs" />
     <Compile Include="SimpleSpatialFieldInfo.cs" />
     <Compile Include="SpatialFieldInfo.cs" />
     <Compile Include="SpatialStrategy.cs" />

Modified: incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/PrefixTreeStrategy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/PrefixTreeStrategy.cs?rev=1375244&r1=1375243&r2=1375244&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/PrefixTreeStrategy.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/PrefixTreeStrategy.cs Mon Aug 20
21:43:59 2012
@@ -27,9 +27,9 @@ using Lucene.Net.Analysis.Tokenattribute
 using Lucene.Net.Documents;
 using Lucene.Net.Search.Function;
 using Lucene.Net.Spatial.Prefix.Tree;
+using Lucene.Net.Spatial.Queries;
 using Lucene.Net.Spatial.Util;
 using Spatial4n.Core.Distance;
-using Spatial4n.Core.Query;
 using Spatial4n.Core.Shapes;
 
 namespace Lucene.Net.Spatial.Prefix

Modified: incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/RecursivePrefixTreeStrategy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/RecursivePrefixTreeStrategy.cs?rev=1375244&r1=1375243&r2=1375244&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/RecursivePrefixTreeStrategy.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/RecursivePrefixTreeStrategy.cs Mon
Aug 20 21:43:59 2012
@@ -18,9 +18,9 @@
 using Lucene.Net.Search;
 using Lucene.Net.Search.Function;
 using Lucene.Net.Spatial.Prefix.Tree;
+using Lucene.Net.Spatial.Queries;
 using Lucene.Net.Spatial.Util;
 using Spatial4n.Core.Exceptions;
-using Spatial4n.Core.Query;
 using Spatial4n.Core.Shapes;
 
 namespace Lucene.Net.Spatial.Prefix

Modified: incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/TermQueryPrefixTreeStrategy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/TermQueryPrefixTreeStrategy.cs?rev=1375244&r1=1375243&r2=1375244&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/TermQueryPrefixTreeStrategy.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/TermQueryPrefixTreeStrategy.cs Mon
Aug 20 21:43:59 2012
@@ -18,9 +18,9 @@
 using Lucene.Net.Index;
 using Lucene.Net.Search;
 using Lucene.Net.Spatial.Prefix.Tree;
+using Lucene.Net.Spatial.Queries;
 using Lucene.Net.Spatial.Util;
 using Spatial4n.Core.Exceptions;
-using Spatial4n.Core.Query;
 using Spatial4n.Core.Shapes;
 
 namespace Lucene.Net.Spatial.Prefix

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgs.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgs.cs?rev=1375244&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgs.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgs.cs Mon Aug 20 21:43:59
2012
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+using System;
+using System.Text;
+using Spatial4n.Core.Context;
+using Spatial4n.Core.Exceptions;
+using Spatial4n.Core.Shapes;
+
+namespace Spatial4n.Core.Exceptions
+{
+	public class InvalidSpatialArgument : ArgumentException
+	{
+		public InvalidSpatialArgument(String reason)
+			: base(reason)
+		{
+		}
+	}
+}
+
+namespace Lucene.Net.Spatial.Queries
+{
+	public class SpatialArgs
+	{
+		public static double DEFAULT_DIST_PRECISION = 0.025d;
+
+		public SpatialOperation Operation { get; set; }
+
+		private Shape shape;
+		private double distPrecision = DEFAULT_DIST_PRECISION;
+
+		// Useful for 'distance' calculations
+		public double? Min { get; set; }
+		public double? Max { get; set; }
+
+		public SpatialArgs(SpatialOperation operation)
+		{
+			this.Operation = operation;
+		}
+
+		public SpatialArgs(SpatialOperation operation, Shape shape)
+		{
+			this.Operation = operation;
+			this.shape = shape;
+		}
+
+		/// <summary>
+		/// Check if the arguments make sense -- throw an exception if not
+		/// </summary>
+		public void Validate()
+		{
+			if (Operation.IsTargetNeedsArea() && !shape.HasArea())
+			{
+				throw new InvalidSpatialArgument(Operation + " only supports geometry with area");
+			}
+		}
+
+		public String ToString(SpatialContext context)
+		{
+			var str = new StringBuilder();
+			str.Append(Operation.GetName()).Append('(');
+			str.Append(context.ToString(shape));
+			if (Min != null)
+			{
+				str.Append(" min=").Append(Min);
+			}
+			if (Max != null)
+			{
+				str.Append(" max=").Append(Max);
+			}
+			str.Append(" distPrec=").AppendFormat("{0:0.00}%", distPrecision / 100d);
+			str.Append(')');
+			return str.ToString();
+		}
+
+		public override String ToString()
+		{
+			return ToString(SpatialContext.GEO_KM);
+		}
+
+		//------------------------------------------------
+		// Getters & Setters
+		//------------------------------------------------
+
+		/// <summary>
+		/// Considers {@link SpatialOperation#BBoxWithin} in returning the shape.
+		/// </summary>
+		/// <returns></returns>
+		public Shape GetShape()
+		{
+			if (shape != null && (Operation == SpatialOperation.BBoxWithin || Operation ==
SpatialOperation.BBoxIntersects))
+				return shape.GetBoundingBox();
+			return shape;
+		}
+
+		public void SetShape(Shape shape)
+		{
+			this.shape = shape;
+		}
+
+		/// <summary>
+		/// The fraction of the distance from the center of the query shape to its nearest edge
that is considered acceptable
+		/// error. The algorithm for computing the distance to the nearest edge is actually a little
different. It normalizes
+		/// the shape to a square given it's bounding box area:
+		/// <pre>sqrt(shape.bbox.area)/2</pre>
+		/// And the error distance is beyond the shape such that the shape is a minimum shape.
+		/// </summary>
+		/// <returns></returns>
+		public Double GetDistPrecision()
+		{
+			return distPrecision;
+		}
+
+		public void SetDistPrecision(double? distPrecision)
+		{
+			if (distPrecision != null)
+				this.distPrecision = distPrecision.Value;
+		}
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgsParser.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgsParser.cs?rev=1375244&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgsParser.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialArgsParser.cs Mon Aug 20
21:43:59 2012
@@ -0,0 +1,104 @@
+/*
+ * 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.
+ */
+
+using System;
+using System.Collections.Generic;
+using Spatial4n.Core.Context;
+using Spatial4n.Core.Exceptions;
+
+namespace Lucene.Net.Spatial.Queries
+{
+	public class SpatialArgsParser
+	{
+		public SpatialArgs Parse(String v, SpatialContext ctx)
+		{
+			int idx = v.IndexOf('(');
+			int edx = v.LastIndexOf(')');
+
+			if (idx < 0 || idx > edx)
+			{
+				throw new InvalidSpatialArgument("missing parens: " + v);
+			}
+
+			SpatialOperation op = SpatialOperation.Get(v.Substring(0, idx).Trim());
+
+			//Substring in .NET is (startPosn, length), But in Java it's (startPosn, endPosn)
+			//see http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#substring(int,
int)
+			String body = v.Substring(idx + 1, edx - (idx + 1)).Trim();
+			if (body.Length < 1)
+			{
+				throw new InvalidSpatialArgument("missing body : " + v);
+			}
+
+			var shape = ctx.ReadShape(body);
+			var args = new SpatialArgs(op, shape);
+
+			if (v.Length > (edx + 1))
+			{
+				body = v.Substring(edx + 1).Trim();
+				if (body.Length > 0)
+				{
+					Dictionary<String, String> aa = ParseMap(body);
+					args.Min = ReadDouble(aa["min"]);
+					args.Max = ReadDouble(aa["max"]);
+					args.SetDistPrecision(ReadDouble(aa["distPrec"]));
+					if (aa.Count > 3)
+					{
+						throw new InvalidSpatialArgument("unused parameters: " + aa);
+					}
+				}
+			}
+			return args;
+		}
+
+		protected static double? ReadDouble(String v)
+		{
+			double val;
+			return double.TryParse(v, out val) ? val : (double?)null;
+		}
+
+		protected static bool ReadBool(String v, bool defaultValue)
+		{
+			bool ret;
+			return bool.TryParse(v, out ret) ? ret : defaultValue;
+		}
+
+		protected static Dictionary<String, String> ParseMap(String body)
+		{
+			var map = new Dictionary<String, String>();
+			int tokenPos = 0;
+			var st = body.Split(new[] {' ', '\n', '\t'}, StringSplitOptions.RemoveEmptyEntries);
+			while (tokenPos < st.Length)
+			{
+				String a = st[tokenPos++];
+				int idx = a.IndexOf('=');
+				if (idx > 0)
+				{
+					String k = a.Substring(0, idx);
+					String v = a.Substring(idx + 1);
+					map[k] = v;
+				}
+				else
+				{
+					map[a] = a;
+				}
+			}
+			return map;
+		}
+
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialOperation.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialOperation.cs?rev=1375244&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialOperation.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Queries/SpatialOperation.cs Mon Aug 20
21:43:59 2012
@@ -0,0 +1,107 @@
+/* See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * Esri Inc. 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.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using Spatial4n.Core.Exceptions;
+
+namespace Lucene.Net.Spatial.Queries
+{
+	public class SpatialOperation
+	{
+		// Private registry
+		private static readonly Dictionary<String, SpatialOperation> registry = new Dictionary<string,
SpatialOperation>();
+		private static readonly IList<SpatialOperation> list = new List<SpatialOperation>();
+
+		// Geometry Operations
+		public static readonly SpatialOperation BBoxIntersects = new SpatialOperation("BBoxIntersects",
true, false, false);
+		public static readonly SpatialOperation BBoxWithin = new SpatialOperation("BBoxWithin",
true, false, false);
+		public static readonly SpatialOperation Contains = new SpatialOperation("Contains", true,
true, false);
+		public static readonly SpatialOperation Intersects = new SpatialOperation("Intersects",
true, false, false);
+		public static readonly SpatialOperation IsEqualTo = new SpatialOperation("IsEqualTo", false,
false, false);
+		public static readonly SpatialOperation IsDisjointTo = new SpatialOperation("IsDisjointTo",
false, false, false);
+		public static readonly SpatialOperation IsWithin = new SpatialOperation("IsWithin", true,
false, true);
+		public static readonly SpatialOperation Overlaps = new SpatialOperation("Overlaps", true,
false, true);
+
+		// Member variables
+		private readonly bool scoreIsMeaningful;
+		private readonly bool sourceNeedsArea;
+		private readonly bool targetNeedsArea;
+		private readonly String name;
+
+		protected SpatialOperation(String name, bool scoreIsMeaningful, bool sourceNeedsArea, bool
targetNeedsArea)
+		{
+			this.name = name;
+			this.scoreIsMeaningful = scoreIsMeaningful;
+			this.sourceNeedsArea = sourceNeedsArea;
+			this.targetNeedsArea = targetNeedsArea;
+			registry[name] = this;
+			registry[name.ToUpper(CultureInfo.CreateSpecificCulture("en-US"))] = this;
+			list.Add(this);
+		}
+
+		public static SpatialOperation Get(String v)
+		{
+			SpatialOperation op;
+			if (!registry.TryGetValue(v, out op) || op == null)
+			{
+				if (!registry.TryGetValue(v.ToUpper(CultureInfo.CreateSpecificCulture("en-US")), out
op) || op == null)
+					throw new InvalidSpatialArgument("Unknown Operation: " + v);
+			}
+			return op;
+		}
+
+		public static IList<SpatialOperation> Values()
+		{
+			return list;
+		}
+
+		public static bool Is(SpatialOperation op, params SpatialOperation[] tst)
+		{
+			return tst.Any(t => op == t);
+		}
+
+
+		// ================================================= Getters / Setters =============================================
+
+		public bool IsScoreIsMeaningful()
+		{
+			return scoreIsMeaningful;
+		}
+
+		public bool IsSourceNeedsArea()
+		{
+			return sourceNeedsArea;
+		}
+
+		public bool IsTargetNeedsArea()
+		{
+			return targetNeedsArea;
+		}
+
+		public String GetName()
+		{
+			return name;
+		}
+
+		public override String ToString()
+		{
+			return name;
+		}
+
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Queries/UnsupportedSpatialOperation.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Queries/UnsupportedSpatialOperation.cs?rev=1375244&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Queries/UnsupportedSpatialOperation.cs
(added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Queries/UnsupportedSpatialOperation.cs
Mon Aug 20 21:43:59 2012
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+using System;
+
+namespace Lucene.Net.Spatial.Queries
+{
+	public class UnsupportedSpatialOperation : InvalidOperationException
+	{
+		public UnsupportedSpatialOperation(SpatialOperation op) : base(op.GetName())
+		{
+		}
+	}
+}

Modified: incubator/lucene.net/trunk/src/contrib/Spatial/SpatialStrategy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/SpatialStrategy.cs?rev=1375244&r1=1375243&r2=1375244&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/SpatialStrategy.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/SpatialStrategy.cs Mon Aug 20 21:43:59
2012
@@ -18,9 +18,9 @@
 using Lucene.Net.Documents;
 using Lucene.Net.Search;
 using Lucene.Net.Search.Function;
+using Lucene.Net.Spatial.Queries;
 using Lucene.Net.Spatial.Util;
 using Spatial4n.Core.Context;
-using Spatial4n.Core.Query;
 using Spatial4n.Core.Shapes;
 
 namespace Lucene.Net.Spatial

Modified: incubator/lucene.net/trunk/src/contrib/Spatial/Vector/DistanceValueSource.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Vector/DistanceValueSource.cs?rev=1375244&r1=1375243&r2=1375244&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Vector/DistanceValueSource.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Vector/DistanceValueSource.cs Mon Aug 20
21:43:59 2012
@@ -48,7 +48,7 @@ namespace Lucene.Net.Spatial.Vector
 			private readonly DistanceValueSource enclosingInstance;
 
 			private readonly double[] ptX, ptY;
-			private readonly Bits validX, validY;
+			private readonly IBits validX, validY;
 
 			public DistanceDocValues(DistanceValueSource enclosingInstance, IndexReader reader)
 			{

Modified: incubator/lucene.net/trunk/src/contrib/Spatial/Vector/TwoDoublesStrategy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Vector/TwoDoublesStrategy.cs?rev=1375244&r1=1375243&r2=1375244&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Vector/TwoDoublesStrategy.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Vector/TwoDoublesStrategy.cs Mon Aug 20
21:43:59 2012
@@ -19,10 +19,10 @@ using System;
 using Lucene.Net.Documents;
 using Lucene.Net.Search;
 using Lucene.Net.Search.Function;
+using Lucene.Net.Spatial.Queries;
 using Lucene.Net.Spatial.Util;
 using Spatial4n.Core.Context;
 using Spatial4n.Core.Exceptions;
-using Spatial4n.Core.Query;
 using Spatial4n.Core.Shapes;
 
 namespace Lucene.Net.Spatial.Vector
@@ -116,7 +116,7 @@ namespace Lucene.Net.Spatial.Vector
 					valueSource = MakeValueSource(args, fieldInfo);
 
 					var vsf = new ValueSourceFilter(
-						new QueryWrapperFilter(spatial), valueSource, 0, circle.GetDistance());
+						new QueryWrapperFilter(spatial), valueSource, 0, circle.GetRadius());
 
 					spatial = new FilteredQuery(new MatchAllDocsQuery(), vsf);
 				}
@@ -162,7 +162,7 @@ namespace Lucene.Net.Spatial.Vector
 					ValueSource valueSource = MakeValueSource(args, fieldInfo);
 
 					return new ValueSourceFilter(
-						new QueryWrapperFilter(bbox), valueSource, 0, circle.GetDistance());
+						new QueryWrapperFilter(bbox), valueSource, 0, circle.GetRadius());
 				}
 			}
 			return new QueryWrapperFilter(MakeQuery(args, fieldInfo));

Modified: incubator/lucene.net/trunk/test/contrib/Spatial/Contrib.Spatial.Test.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/Spatial/Contrib.Spatial.Test.csproj?rev=1375244&r1=1375243&r2=1375244&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/Spatial/Contrib.Spatial.Test.csproj (original)
+++ incubator/lucene.net/trunk/test/contrib/Spatial/Contrib.Spatial.Test.csproj Mon Aug 20
21:43:59 2012
@@ -124,6 +124,7 @@
     <Compile Include="Prefix\TestTermQueryPrefixGridStrategy.cs" />
     <Compile Include="Prefix\Tree\SpatialPrefixTreeTest.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Query\SpatialArgsParserTest.cs" />
     <Compile Include="SpatialMatchConcern.cs" />
     <Compile Include="SpatialTestCase.cs" />
     <Compile Include="SpatialTestQuery.cs" />

Added: incubator/lucene.net/trunk/test/contrib/Spatial/Query/SpatialArgsParserTest.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/Spatial/Query/SpatialArgsParserTest.cs?rev=1375244&view=auto
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/Spatial/Query/SpatialArgsParserTest.cs (added)
+++ incubator/lucene.net/trunk/test/contrib/Spatial/Query/SpatialArgsParserTest.cs Mon Aug
20 21:43:59 2012
@@ -0,0 +1,54 @@
+using System;
+using NUnit.Framework;
+using Spatial4n.Core.Context;
+using Spatial4n.Core.Query;
+using Spatial4n.Core.Shapes;
+
+namespace Lucene.Net.Contrib.Spatial.Test.Query
+{
+	public class SpatialArgsParserTest
+	{
+		private readonly SpatialContext ctx = SpatialContext.GEO_KM;
+
+		//The args parser is only dependent on the ctx for IO so I don't care to test
+		// with other implementations.
+
+		[Test]
+		public void TestArgParser()
+		{
+			SpatialArgsParser parser = new SpatialArgsParser();
+
+			String arg = SpatialOperation.IsWithin + "(-10 -20 10 20)";
+			SpatialArgs outValue = parser.Parse(arg, ctx);
+			Assert.AreEqual(SpatialOperation.IsWithin, outValue.Operation);
+			Rectangle bounds = (Rectangle)outValue.GetShape();
+			Assert.AreEqual(-10.0, bounds.GetMinX(), 0D);
+			Assert.AreEqual(10.0, bounds.GetMaxX(), 0D);
+
+			// Disjoint should not be scored
+			arg = SpatialOperation.IsDisjointTo + " (-10 10 -20 20)";
+			outValue = parser.Parse(arg, ctx);
+			Assert.AreEqual(SpatialOperation.IsDisjointTo, outValue.Operation);
+
+			try
+			{
+				parser.Parse(SpatialOperation.IsDisjointTo + "[ ]", ctx);
+				Assert.True(false, "spatial operations need args");
+			}
+			catch (Exception)
+			{
+				//expected
+			}
+
+			try
+			{
+				parser.Parse("XXXX(-10 10 -20 20)", ctx);
+				Assert.True(false, "unknown operation!");
+			}
+			catch (Exception)
+			{
+				//expected
+			}
+		}
+	}
+}



Mime
View raw message