lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject svn commit: r1375248 - in /incubator/lucene.net/trunk: src/contrib/Spatial/ src/contrib/Spatial/BBox/ src/contrib/Spatial/Prefix/ src/contrib/Spatial/Vector/ src/core/Document/ test/contrib/Spatial/ test/contrib/Spatial/Vector/
Date Mon, 20 Aug 2012 21:46:48 GMT
Author: synhershko
Date: Mon Aug 20 21:46:47 2012
New Revision: 1375248

URL: http://svn.apache.org/viewvc?rev=1375248&view=rev
Log:
LUCENE-4099 remove SpatialFieldInfo (and corresponding generics) and put fieldName into Strategy
instead of methods. Thus an instance of SpatialStrategy is now a per-field object, not per-fieldType

Removed:
    incubator/lucene.net/trunk/src/contrib/Spatial/SimpleSpatialFieldInfo.cs
    incubator/lucene.net/trunk/src/contrib/Spatial/SpatialFieldInfo.cs
    incubator/lucene.net/trunk/src/contrib/Spatial/Vector/TwoDoublesFieldInfo.cs
Modified:
    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/src/core/Document/NumericField.cs
    incubator/lucene.net/trunk/test/contrib/Spatial/StrategyTestCase.cs
    incubator/lucene.net/trunk/test/contrib/Spatial/Vector/BaseTwoDoublesStrategyTestCase.cs

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=1375248&r1=1375247&r2=1375248&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:46:47
2012
@@ -25,7 +25,7 @@ using Spatial4n.Core.Shapes;
 
 namespace Lucene.Net.Spatial.BBox
 {
-	public class BBoxStrategy : SpatialStrategy<SimpleSpatialFieldInfo>
+	public class BBoxStrategy : SpatialStrategy
 	{
 		public static String SUFFIX_MINX = "__minX";
 		public static String SUFFIX_MAXX = "__maxX";
@@ -49,7 +49,7 @@ namespace Lucene.Net.Spatial.BBox
 		public int precisionStep = 8; // same as solr default
 
 		public BBoxStrategy(SpatialContext ctx, String fieldNamePrefix)
-			: base(ctx/*, fieldNamePrefix*/)
+			: base(ctx, fieldNamePrefix)
 		{
 			field_bbox = fieldNamePrefix;
 			field_minX = fieldNamePrefix + SUFFIX_MINX;
@@ -70,22 +70,22 @@ namespace Lucene.Net.Spatial.BBox
 		// Indexing
 		//---------------------------------
 
-		public override Field CreateField(SimpleSpatialFieldInfo fieldInfo, Shape shape, bool index,
bool store)
+		public override Field CreateField(Shape shape, bool index, bool store)
 		{
 			throw new NotImplementedException();
 		}
 
-		public override ValueSource MakeValueSource(SpatialArgs args, SimpleSpatialFieldInfo fieldInfo)
+		public override ValueSource MakeValueSource(SpatialArgs args)
 		{
 			throw new NotImplementedException();
 		}
 
-		public override Query MakeQuery(SpatialArgs args, SimpleSpatialFieldInfo fieldInfo)
+		public override Query MakeQuery(SpatialArgs args)
 		{
 			throw new NotImplementedException();
 		}
 
-		public override Filter MakeFilter(SpatialArgs args, SimpleSpatialFieldInfo fieldInfo)
+		public override Filter MakeFilter(SpatialArgs args)
 		{
 			throw new NotImplementedException();
 		}

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=1375248&r1=1375247&r2=1375248&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:46:47
2012
@@ -144,8 +144,6 @@
     <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" />
     <Compile Include="Util\Bits.cs" />
     <Compile Include="Util\CachedDistanceValueSource.cs" />
@@ -163,7 +161,6 @@
     <Compile Include="Util\TruncateFilter.cs" />
     <Compile Include="Util\ValueSourceFilter.cs" />
     <Compile Include="Vector\DistanceValueSource.cs" />
-    <Compile Include="Vector\TwoDoublesFieldInfo.cs" />
     <Compile Include="Vector\TwoDoublesStrategy.cs" />
   </ItemGroup>
   <ItemGroup>

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=1375248&r1=1375247&r2=1375248&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:46:47 2012
@@ -34,17 +34,19 @@ using Spatial4n.Core.Shapes;
 
 namespace Lucene.Net.Spatial.Prefix
 {
-	public abstract class PrefixTreeStrategy : SpatialStrategy<SimpleSpatialFieldInfo>
+	public abstract class PrefixTreeStrategy : SpatialStrategy
 	{
 		protected readonly SpatialPrefixTree grid;
+		private readonly string fieldName;
 		private readonly IDictionary<String, PointPrefixTreeFieldCacheProvider> provider
= new ConcurrentDictionary<string, PointPrefixTreeFieldCacheProvider>();
 		protected int defaultFieldValuesArrayLen = 2;
 		protected double distErrPct = SpatialArgs.DEFAULT_DIST_PRECISION;
 
-		protected PrefixTreeStrategy(SpatialPrefixTree grid)
-			: base(grid.GetSpatialContext())
+		protected PrefixTreeStrategy(SpatialPrefixTree grid, String fieldName)
+			: base(grid.GetSpatialContext(), fieldName)
 		{
 			this.grid = grid;
+			this.fieldName = fieldName;
 		}
 
 		/** Used in the in-memory ValueSource as a default ArrayList length for this field's array
of values, per doc. */
@@ -59,7 +61,7 @@ namespace Lucene.Net.Spatial.Prefix
 			this.distErrPct = distErrPct;
 		}
 
-		public override Field CreateField(SimpleSpatialFieldInfo fieldInfo, Shape shape, bool index,
bool store)
+		public override Field CreateField(Shape shape, bool index, bool store)
 		{
 			int detailLevel = grid.GetMaxLevelForPrecision(shape, distErrPct);
 			var cells = grid.GetNodes(shape, detailLevel, true);//true=intermediates cells
@@ -76,7 +78,7 @@ namespace Lucene.Net.Spatial.Prefix
 			//TODO is CellTokenStream supposed to be re-used somehow? see Uwe's comments:
 			//  http://code.google.com/p/lucene-spatial-playground/issues/detail?id=4
 
-			var fname = fieldInfo.GetFieldName();
+			var fname = GetFieldName();
 			if (store)
 			{
 				//TODO figure out how to re-use original string instead of reconstituting it.
@@ -170,32 +172,32 @@ namespace Lucene.Net.Spatial.Prefix
 			}
 		}
 
-		public override ValueSource MakeValueSource(SpatialArgs args, SimpleSpatialFieldInfo fieldInfo)
+		public override ValueSource MakeValueSource(SpatialArgs args)
 		{
 			var calc = grid.GetSpatialContext().GetDistCalc();
-			return MakeValueSource(args, fieldInfo, calc);
+			return MakeValueSource(args, calc);
 		}
 
-		public ShapeFieldCacheProvider<Point> GetCacheProvider(SimpleSpatialFieldInfo fieldInfo)
+		public ShapeFieldCacheProvider<Point> GetCacheProvider()
 		{
 			PointPrefixTreeFieldCacheProvider p;
-			if (!provider.TryGetValue(fieldInfo.GetFieldName(), out p) || p == null)
+			if (!provider.TryGetValue(GetFieldName(), out p) || p == null)
 			{
 				lock (this)
 				{//double checked locking idiom is okay since provider is threadsafe
-					if (!provider.ContainsKey(fieldInfo.GetFieldName()))
+					if (!provider.ContainsKey(GetFieldName()))
 					{
-						p = new PointPrefixTreeFieldCacheProvider(grid, fieldInfo.GetFieldName(), defaultFieldValuesArrayLen);
-						provider[fieldInfo.GetFieldName()] = p;
+						p = new PointPrefixTreeFieldCacheProvider(grid, GetFieldName(), defaultFieldValuesArrayLen);
+						provider[GetFieldName()] = p;
 					}
 				}
 			}
 			return p;
 		}
 
-		public ValueSource MakeValueSource(SpatialArgs args, SimpleSpatialFieldInfo fieldInfo,
DistanceCalculator calc)
+		public ValueSource MakeValueSource(SpatialArgs args, DistanceCalculator calc)
 		{
-			PointPrefixTreeFieldCacheProvider p = (PointPrefixTreeFieldCacheProvider)GetCacheProvider(fieldInfo);
+			PointPrefixTreeFieldCacheProvider p = (PointPrefixTreeFieldCacheProvider)GetCacheProvider();
 			Point point = args.GetShape().GetCenter();
 			return new CachedDistanceValueSource(point, calc, p);
 		}

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=1375248&r1=1375247&r2=1375248&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:46:47 2012
@@ -16,11 +16,8 @@
  */
 
 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.Shapes;
 
 namespace Lucene.Net.Spatial.Prefix
@@ -30,20 +27,23 @@ namespace Lucene.Net.Spatial.Prefix
 	/// </summary>
 	public class RecursivePrefixTreeStrategy : PrefixTreeStrategy
 	{
-		private int prefixGridScanLevel;//TODO how is this customized?
+		private readonly string fieldName;
+		private int prefixGridScanLevel;
 
-		public RecursivePrefixTreeStrategy(SpatialPrefixTree grid)
-			: base(grid)
+		public RecursivePrefixTreeStrategy(SpatialPrefixTree grid, string fieldName)
+			: base(grid, fieldName)
 		{
+			this.fieldName = fieldName;
 			prefixGridScanLevel = grid.GetMaxLevels() - 4;//TODO this default constant is dependent
on the prefix grid size
 		}
 
 		public void SetPrefixGridScanLevel(int prefixGridScanLevel)
 		{
+			//TODO if negative then subtract from maxlevels
 			this.prefixGridScanLevel = prefixGridScanLevel;
 		}
 
-		public override Filter MakeFilter(SpatialArgs args, SimpleSpatialFieldInfo fieldInfo)
+		public override Filter MakeFilter(SpatialArgs args)
 		{
 			var op = args.Operation;
 			if (!SpatialOperation.Is(op, SpatialOperation.IsWithin, SpatialOperation.Intersects, SpatialOperation.BBoxWithin,
SpatialOperation.BBoxIntersects))
@@ -53,7 +53,7 @@ namespace Lucene.Net.Spatial.Prefix
 
 			int detailLevel = grid.GetMaxLevelForPrecision(shape, args.GetDistPrecision());
 
-			return new RecursivePrefixTreeFilter(fieldInfo.GetFieldName(), grid, shape, prefixGridScanLevel,
detailLevel);
+			return new RecursivePrefixTreeFilter(GetFieldName(), grid, shape, prefixGridScanLevel,
detailLevel);
 		}
 
 		public override string ToString()

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=1375248&r1=1375247&r2=1375248&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:46:47 2012
@@ -15,12 +15,12 @@
  * limitations under the License.
  */
 
+using System;
 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.Shapes;
 
 namespace Lucene.Net.Spatial.Prefix
@@ -31,12 +31,15 @@ namespace Lucene.Net.Spatial.Prefix
 	/// </summary>
 	public class TermQueryPrefixTreeStrategy : PrefixTreeStrategy
 	{
-		public TermQueryPrefixTreeStrategy(SpatialPrefixTree grid)
-			: base(grid)
+		private readonly string fieldName;
+
+		public TermQueryPrefixTreeStrategy(SpatialPrefixTree grid, string fieldName)
+			: base(grid, fieldName)
 		{
+			this.fieldName = fieldName;
 		}
 
-		public override Filter MakeFilter(SpatialArgs args, SimpleSpatialFieldInfo fieldInfo)
+		public override Filter MakeFilter(SpatialArgs args)
 		{
 			SpatialOperation op = args.Operation;
 			if (
@@ -50,7 +53,7 @@ namespace Lucene.Net.Spatial.Prefix
 			var filter = new TermsFilter();
 			foreach (Node cell in cells)
 			{
-				filter.AddTerm(new Term(fieldInfo.GetFieldName(), cell.GetTokenString()));
+				filter.AddTerm(new Term(GetFieldName(), cell.GetTokenString()));
 			}
 			return filter;
 		}

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=1375248&r1=1375247&r2=1375248&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:46:47
2012
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 
+using System;
 using Lucene.Net.Documents;
 using Lucene.Net.Search;
 using Lucene.Net.Search.Function;
@@ -26,14 +27,24 @@ using Spatial4n.Core.Shapes;
 namespace Lucene.Net.Spatial
 {
 	/* must be thread safe */
-	public abstract class SpatialStrategy<T> where T : SpatialFieldInfo
+	public abstract class SpatialStrategy
 	{
-		protected bool ignoreIncompatibleGeometry = false;
+		protected bool ignoreIncompatibleGeometry;
 		protected readonly SpatialContext ctx;
+		private readonly string fieldName;
 
-		protected SpatialStrategy(SpatialContext ctx)
+		/// <summary>
+		/// Constructs the spatial strategy with its mandatory arguments.
+		/// </summary>
+		/// <param name="ctx"></param>
+		protected SpatialStrategy(SpatialContext ctx, string fieldName)
 		{
+			if (ctx == null)
+				throw new ArgumentException("ctx is required", "ctx");
 			this.ctx = ctx;
+			if (string.IsNullOrEmpty(fieldName))
+				throw new ArgumentException("fieldName is required", "fieldName");
+			this.fieldName = fieldName;
 		}
 
 		public SpatialContext GetSpatialContext()
@@ -47,6 +58,16 @@ namespace Lucene.Net.Spatial
 			return false;
 		}
 
+		/// <summary>
+		/// The name of the field or the prefix of them if there are multiple
+		/// fields needed internally.
+		/// </summary>
+		/// <returns></returns>
+		public String GetFieldName()
+		{
+			return fieldName;
+		}
+
 		/**
 		 * Corresponds with Solr's FieldType.createField().
 		 *
@@ -54,12 +75,12 @@ namespace Lucene.Net.Spatial
 		 * This is reasonable behavior if 'ignoreIncompatibleGeometry=true' and the
 		 * geometry is incompatible
 		 */
-		public abstract Field CreateField(T fieldInfo, Shape shape, bool index, bool store);
+		public abstract Field CreateField(Shape shape, bool index, bool store);
 
 		/** Corresponds with Solr's FieldType.createFields(). */
-		public virtual AbstractField[] CreateFields(T fieldInfo, Shape shape, bool index, bool
store)
+		public virtual AbstractField[] CreateFields(Shape shape, bool index, bool store)
 		{
-			return new AbstractField[] { CreateField(fieldInfo, shape, index, store) };
+			return new AbstractField[] { CreateField(shape, index, store) };
 		}
 
 		/// <summary>
@@ -68,7 +89,7 @@ namespace Lucene.Net.Spatial
 		/// <param name="args"></param>
 		/// <param name="fieldInfo"></param>
 		/// <returns></returns>
-		public abstract ValueSource MakeValueSource(SpatialArgs args, T fieldInfo);
+		public abstract ValueSource MakeValueSource(SpatialArgs args);
 
 		/// <summary>
 		/// Make a query which has a score based on the distance from the data to the query shape.
@@ -79,10 +100,10 @@ namespace Lucene.Net.Spatial
 		/// <param name="args"></param>
 		/// <param name="fieldInfo"></param>
 		/// <returns></returns>
-		public virtual Query MakeQuery(SpatialArgs args, T fieldInfo)
+		public virtual Query MakeQuery(SpatialArgs args)
 		{
-			Filter filter = MakeFilter(args, fieldInfo);
-			ValueSource vs = MakeValueSource(args, fieldInfo);
+			Filter filter = MakeFilter(args);
+			ValueSource vs = MakeValueSource(args);
 			return new FilteredQuery(new FunctionQuery(vs), filter);
 		}
 
@@ -92,7 +113,7 @@ namespace Lucene.Net.Spatial
 		/// <param name="args"></param>
 		/// <param name="fieldInfo"></param>
 		/// <returns></returns>
-		public abstract Filter MakeFilter(SpatialArgs args, T fieldInfo);
+		public abstract Filter MakeFilter(SpatialArgs args);
 
 		public bool IsIgnoreIncompatibleGeometry()
 		{
@@ -104,5 +125,9 @@ namespace Lucene.Net.Spatial
 			this.ignoreIncompatibleGeometry = ignoreIncompatibleGeometry;
 		}
 
+		public override string ToString()
+		{
+			return GetType().Name + " field:" + fieldName + " ctx=" + ctx;
+		}
 	}
 }

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=1375248&r1=1375247&r2=1375248&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:46:47 2012
@@ -30,17 +30,15 @@ namespace Lucene.Net.Spatial.Vector
 	/// </summary>
 	public class DistanceValueSource : ValueSource
 	{
-		private readonly TwoDoublesFieldInfo fields;
-		private readonly DistanceCalculator calculator;
+		private TwoDoublesStrategy strategy;
 		private readonly Point from;
-		private readonly DoubleParser parser;
+		private readonly DistanceCalculator calculator;
 
-		public DistanceValueSource(Point from, DistanceCalculator calc, TwoDoublesFieldInfo fields,
DoubleParser parser)
+		public DistanceValueSource(TwoDoublesStrategy strategy, Point from, DistanceCalculator
calc)
 		{
+			this.strategy = strategy;
 			this.from = from;
-			this.fields = fields;
 			this.calculator = calc;
-			this.parser = parser;
 		}
 
 		public class DistanceDocValues : DocValues
@@ -54,10 +52,10 @@ namespace Lucene.Net.Spatial.Vector
 			{
 				this.enclosingInstance = enclosingInstance;
 
-				ptX = FieldCache_Fields.DEFAULT.GetDoubles(reader, enclosingInstance.fields.GetFieldNameX()/*,
true*/);
-				ptY = FieldCache_Fields.DEFAULT.GetDoubles(reader, enclosingInstance.fields.GetFieldNameY()/*,
true*/);
-				validX = FieldCache_Fields.DEFAULT.GetDocsWithField(reader, enclosingInstance.fields.GetFieldNameX());
-				validY = FieldCache_Fields.DEFAULT.GetDocsWithField(reader, enclosingInstance.fields.GetFieldNameY());
+				ptX = FieldCache_Fields.DEFAULT.GetDoubles(reader, enclosingInstance.strategy.GetFieldNameX()/*,
true*/);
+				ptY = FieldCache_Fields.DEFAULT.GetDoubles(reader, enclosingInstance.strategy.GetFieldNameY()/*,
true*/);
+				validX = FieldCache_Fields.DEFAULT.GetDocsWithField(reader, enclosingInstance.strategy.GetFieldNameX());
+				validY = FieldCache_Fields.DEFAULT.GetDocsWithField(reader, enclosingInstance.strategy.GetFieldNameY());
 			}
 
 			public override float FloatVal(int doc)
@@ -99,7 +97,7 @@ namespace Lucene.Net.Spatial.Vector
 			if (that == null) return false;
 
 			if (calculator != null ? !calculator.Equals(that.calculator) : that.calculator != null)
return false;
-			if (fields != null ? !fields.Equals(that.fields) : that.fields != null) return false;
+			if (strategy != null ? !strategy.Equals(that.strategy) : that.strategy != null) return
false;
 			if (from != null ? !from.Equals(that.from) : that.from != null) return false;
 
 			return true;
@@ -107,7 +105,7 @@ namespace Lucene.Net.Spatial.Vector
 
 		public override int GetHashCode()
 		{
-			int result = fields != null ? fields.GetHashCode() : 0;
+			int result = strategy != null ? strategy.GetHashCode() : 0;
 			result = 31 * result + (calculator != null ? calculator.GetHashCode() : 0);
 			result = 31 * result + (from != null ? from.GetHashCode() : 0);
 			return result;

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=1375248&r1=1375247&r2=1375248&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:46:47 2012
@@ -27,16 +27,38 @@ using Spatial4n.Core.Shapes;
 
 namespace Lucene.Net.Spatial.Vector
 {
-	public class TwoDoublesStrategy : SpatialStrategy<TwoDoublesFieldInfo>
+	public class TwoDoublesStrategy : SpatialStrategy
 	{
-		private readonly NumericFieldInfo finfo;
-		private readonly DoubleParser parser;
+		public static String SUFFIX_X = "__x";
+		public static String SUFFIX_Y = "__y";
 
-		public TwoDoublesStrategy(SpatialContext ctx, NumericFieldInfo finfo, DoubleParser parser)
-			: base(ctx)
+		private readonly String fieldNameX;
+		private readonly String fieldNameY;
+
+		public int precisionStep = 8; // same as solr default
+
+		public TwoDoublesStrategy(SpatialContext ctx, String fieldNamePrefix)
+			: base(ctx, fieldNamePrefix)
+		{
+			this.fieldNameX = fieldNamePrefix + SUFFIX_X;
+			this.fieldNameY = fieldNamePrefix + SUFFIX_Y;
+		}
+
+		public void SetPrecisionStep(int p)
+		{
+			precisionStep = p;
+			if (precisionStep <= 0 || precisionStep >= 64)
+				precisionStep = int.MaxValue;
+		}
+
+		public string GetFieldNameX()
+		{
+			return fieldNameX;
+		}
+
+		public string GetFieldNameY()
 		{
-			this.finfo = finfo;
-			this.parser = parser;
+			return fieldNameY;
 		}
 
 		public override bool IsPolyField()
@@ -44,7 +66,7 @@ namespace Lucene.Net.Spatial.Vector
 			return true;
 		}
 
-		public override AbstractField[] CreateFields(TwoDoublesFieldInfo fieldInfo, Shape shape,
bool index, bool store)
+		public override AbstractField[] CreateFields(Shape shape, bool index, bool store)
 		{
 			var point = shape as Point;
 			if (point != null)
@@ -52,12 +74,12 @@ namespace Lucene.Net.Spatial.Vector
 				var f = new AbstractField[(index ? 2 : 0) + (store ? 1 : 0)];
 				if (index)
 				{
-					f[0] = finfo.CreateDouble(fieldInfo.GetFieldNameX(), point.GetX());
-					f[1] = finfo.CreateDouble(fieldInfo.GetFieldNameY(), point.GetY());
+					f[0] = CreateDouble(fieldNameX, point.GetX(), index, store);
+					f[1] = CreateDouble(fieldNameY, point.GetY(), index, store);
 				}
 				if (store)
 				{
-					f[f.Length - 1] = new Field(fieldInfo.GetFieldName(), ctx.ToString(shape), Field.Store.YES,
Field.Index.NOT_ANALYZED_NO_NORMS);
+					f[f.Length - 1] = new Field(GetFieldName(), ctx.ToString(shape), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
 				}
 				return f;
 			}
@@ -68,18 +90,30 @@ namespace Lucene.Net.Spatial.Vector
 			return new AbstractField[0]; // nothing (solr does not support null) 
 		}
 
-		public override Field CreateField(TwoDoublesFieldInfo fieldInfo, Shape shape, bool index,
bool store)
+		private AbstractField CreateDouble(String name, double v, bool index, bool store)
+		{
+			if (!store && !index)
+				throw new ArgumentException("field must be indexed or stored");
+
+			var fieldType = new NumericField(name, precisionStep, store ? Field.Store.YES : Field.Store.NO,
index);
+			fieldType.SetDoubleValue(v);
+			//fieldType.SetOmitTermFreqAndPositions(true);
+			fieldType.OmitNorms = true;
+			return fieldType;
+		}
+
+		public override Field CreateField(Shape shape, bool index, bool store)
 		{
 			throw new InvalidOperationException("Point is poly field");
 		}
 
-		public override ValueSource MakeValueSource(SpatialArgs args, TwoDoublesFieldInfo fieldInfo)
+		public override ValueSource MakeValueSource(SpatialArgs args)
 		{
 			Point p = args.GetShape().GetCenter();
-			return new DistanceValueSource(p, ctx.GetDistCalc(), fieldInfo, parser);
+			return new DistanceValueSource(this, p, ctx.GetDistCalc());
 		}
 
-		public override Query MakeQuery(SpatialArgs args, TwoDoublesFieldInfo fieldInfo)
+		public override Query MakeQuery(SpatialArgs args)
 		{
 			// For starters, just limit the bbox
 			var shape = args.GetShape();
@@ -102,18 +136,18 @@ namespace Lucene.Net.Spatial.Vector
 				SpatialOperation.BBoxWithin,
 				SpatialOperation.BBoxIntersects))
 			{
-				spatial = MakeWithin(bbox, fieldInfo);
+				spatial = MakeWithin(bbox);
 			}
 			else if (SpatialOperation.Is(op,
 			  SpatialOperation.Intersects,
 			  SpatialOperation.IsWithin))
 			{
-				spatial = MakeWithin(bbox, fieldInfo);
+				spatial = MakeWithin(bbox);
 				var circle = args.GetShape() as Circle;
 				if (circle != null)
 				{
 					// Make the ValueSource
-					valueSource = MakeValueSource(args, fieldInfo);
+					valueSource = MakeValueSource(args);
 
 					var vsf = new ValueSourceFilter(
 						new QueryWrapperFilter(spatial), valueSource, 0, circle.GetRadius());
@@ -123,7 +157,7 @@ namespace Lucene.Net.Spatial.Vector
 			}
 			else if (op == SpatialOperation.IsDisjointTo)
 			{
-				spatial = MakeDisjoint(bbox, fieldInfo);
+				spatial = MakeDisjoint(bbox);
 			}
 
 			if (spatial == null)
@@ -137,7 +171,7 @@ namespace Lucene.Net.Spatial.Vector
 			}
 			else
 			{
-				valueSource = MakeValueSource(args, fieldInfo);
+				valueSource = MakeValueSource(args);
 			}
 			Query spatialRankingQuery = new FunctionQuery(valueSource);
 			var bq = new BooleanQuery();
@@ -147,7 +181,7 @@ namespace Lucene.Net.Spatial.Vector
 
 		}
 
-		public override Filter MakeFilter(SpatialArgs args, TwoDoublesFieldInfo fieldInfo)
+		public override Filter MakeFilter(SpatialArgs args)
 		{
 			var circle = args.GetShape() as Circle;
 			if (circle != null)
@@ -156,17 +190,16 @@ namespace Lucene.Net.Spatial.Vector
 					SpatialOperation.Intersects,
 					SpatialOperation.IsWithin))
 				{
-					Query bbox = MakeWithin(circle.GetBoundingBox(), fieldInfo);
+					Query bbox = MakeWithin(circle.GetBoundingBox());
 
 					// Make the ValueSource
-					ValueSource valueSource = MakeValueSource(args, fieldInfo);
+					ValueSource valueSource = MakeValueSource(args);
 
 					return new ValueSourceFilter(
 						new QueryWrapperFilter(bbox), valueSource, 0, circle.GetRadius());
 				}
 			}
-			return new QueryWrapperFilter(MakeQuery(args, fieldInfo));
-
+			return new QueryWrapperFilter(MakeQuery(args));
 		}
 
 		/// <summary>
@@ -175,26 +208,24 @@ namespace Lucene.Net.Spatial.Vector
 		/// <param name="bbox"></param>
 		/// <param name="fieldInfo"></param>
 		/// <returns>The spatial query</returns>
-		private Query MakeWithin(Rectangle bbox, TwoDoublesFieldInfo fieldInfo)
+		private Query MakeWithin(Rectangle bbox)
 		{
 			Query qX = NumericRangeQuery.NewDoubleRange(
-			  fieldInfo.GetFieldNameX(),
-			  finfo.precisionStep,
+			  fieldNameX,
+			  precisionStep,
 			  bbox.GetMinX(),
 			  bbox.GetMaxX(),
 			  true,
 			  true);
 			Query qY = NumericRangeQuery.NewDoubleRange(
-			  fieldInfo.GetFieldNameY(),
-			  finfo.precisionStep,
+			  fieldNameY,
+			  precisionStep,
 			  bbox.GetMinY(),
 			  bbox.GetMaxY(),
 			  true,
 			  true);
 
-			var bq = new BooleanQuery();
-			bq.Add(qX, Occur.MUST);
-			bq.Add(qY, Occur.MUST);
+			var bq = new BooleanQuery {{qX, Occur.MUST}, {qY, Occur.MUST}};
 			return bq;
 		}
 
@@ -204,26 +235,24 @@ namespace Lucene.Net.Spatial.Vector
 		/// <param name="bbox"></param>
 		/// <param name="fieldInfo"></param>
 		/// <returns>The spatial query</returns>
-		Query MakeDisjoint(Rectangle bbox, TwoDoublesFieldInfo fieldInfo)
+		Query MakeDisjoint(Rectangle bbox)
 		{
 			Query qX = NumericRangeQuery.NewDoubleRange(
-			  fieldInfo.GetFieldNameX(),
-			  finfo.precisionStep,
+			  fieldNameX,
+			  precisionStep,
 			  bbox.GetMinX(),
 			  bbox.GetMaxX(),
 			  true,
 			  true);
 			Query qY = NumericRangeQuery.NewDoubleRange(
-			  fieldInfo.GetFieldNameY(),
-			  finfo.precisionStep,
+			  fieldNameY,
+			  precisionStep,
 			  bbox.GetMinY(),
 			  bbox.GetMaxY(),
 			  true,
 			  true);
 
-			var bq = new BooleanQuery();
-			bq.Add(qX, Occur.MUST_NOT);
-			bq.Add(qY, Occur.MUST_NOT);
+			var bq = new BooleanQuery {{qX, Occur.MUST_NOT}, {qY, Occur.MUST_NOT}};
 			return bq;
 		}
 

Modified: incubator/lucene.net/trunk/src/core/Document/NumericField.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Document/NumericField.cs?rev=1375248&r1=1375247&r2=1375248&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Document/NumericField.cs (original)
+++ incubator/lucene.net/trunk/src/core/Document/NumericField.cs Mon Aug 20 21:46:47 2012
@@ -145,7 +145,7 @@ namespace Lucene.Net.Documents
 	public sealed class NumericField:AbstractField
 	{
 		
-		new private NumericTokenStream tokenStream;
+		new private readonly NumericTokenStream tokenStream;
 		
 		/// <summary> Creates a field for numeric values using the default <c>precisionStep</c>
 		/// <see cref="NumericUtils.PRECISION_STEP_DEFAULT" /> (4). The instance is not yet
initialized with

Modified: incubator/lucene.net/trunk/test/contrib/Spatial/StrategyTestCase.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/Spatial/StrategyTestCase.cs?rev=1375248&r1=1375247&r2=1375248&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/Spatial/StrategyTestCase.cs (original)
+++ incubator/lucene.net/trunk/test/contrib/Spatial/StrategyTestCase.cs Mon Aug 20 21:46:47
2012
@@ -20,16 +20,16 @@ using System.Collections.Generic;
 using System.IO;
 using Lucene.Net.Documents;
 using Lucene.Net.Spatial;
+using Lucene.Net.Spatial.Queries;
 using Lucene.Net.Util;
 using NUnit.Framework;
 using Spatial4n.Core.Context;
 using Spatial4n.Core.Io.Samples;
-using Spatial4n.Core.Query;
 using Spatial4n.Core.Shapes;
 
 namespace Lucene.Net.Contrib.Spatial.Test
 {
-	public abstract class StrategyTestCase<T> : SpatialTestCase where T : SpatialFieldInfo
+	public abstract class StrategyTestCase : SpatialTestCase
 	{
 		public static readonly String DATA_STATES_POLY = "states-poly.txt";
 		public static readonly String DATA_STATES_BBOX = "states-bbox.txt";
@@ -46,9 +46,8 @@ namespace Lucene.Net.Contrib.Spatial.Tes
 
 		protected readonly SpatialArgsParser argsParser = new SpatialArgsParser();
 
-		protected SpatialStrategy<T> strategy;
+		protected SpatialStrategy strategy;
 		protected SpatialContext ctx;
-		protected T fieldInfo;
 		protected bool storeShape = true;
 
 		protected void executeQueries(SpatialMatchConcern concern, params String[] testQueryFile)
@@ -79,7 +78,7 @@ namespace Lucene.Net.Contrib.Spatial.Tes
 				document.Add(new Field("id", data.id, Field.Store.YES, Field.Index.ANALYZED));
 				document.Add(new Field("name", data.name, Field.Store.YES, Field.Index.ANALYZED));
 				Shape shape = ctx.ReadShape(data.shape);
-				foreach (var f in strategy.CreateFields(fieldInfo, shape, true, storeShape))
+				foreach (var f in strategy.CreateFields(shape, true, storeShape))
 				{
 					if (f != null)
 					{ // null if incompatibleGeometry && ignore
@@ -112,7 +111,7 @@ namespace Lucene.Net.Contrib.Spatial.Tes
 				SpatialTestQuery q = queries.Current;
 
 				String msg = q.line; //"Query: " + q.args.toString(ctx);
-				SearchResults got = executeQuery(strategy.MakeQuery(q.args, fieldInfo), 100);
+				SearchResults got = executeQuery(strategy.MakeQuery(q.args), 100);
 				if (concern.orderIsImportant)
 				{
 					var ids = q.ids.GetEnumerator();

Modified: incubator/lucene.net/trunk/test/contrib/Spatial/Vector/BaseTwoDoublesStrategyTestCase.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/Spatial/Vector/BaseTwoDoublesStrategyTestCase.cs?rev=1375248&r1=1375247&r2=1375248&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/Spatial/Vector/BaseTwoDoublesStrategyTestCase.cs
(original)
+++ incubator/lucene.net/trunk/test/contrib/Spatial/Vector/BaseTwoDoublesStrategyTestCase.cs
Mon Aug 20 21:46:47 2012
@@ -23,7 +23,7 @@ using Spatial4n.Core.Context;
 
 namespace Lucene.Net.Contrib.Spatial.Test.Vector
 {
-	public abstract class BaseTwoDoublesStrategyTestCase : StrategyTestCase<TwoDoublesFieldInfo>
+	public abstract class BaseTwoDoublesStrategyTestCase : StrategyTestCase
 	{
 		protected abstract SpatialContext getSpatialContext();
 
@@ -32,9 +32,8 @@ namespace Lucene.Net.Contrib.Spatial.Tes
 		{
 			base.SetUp();
 			this.ctx = getSpatialContext();
-			this.strategy = new TwoDoublesStrategy(ctx,
+			this.strategy = new TwoDoublesStrategy(ctx, 
 				new NumericFieldInfo(), FieldCache_Fields.NUMERIC_UTILS_DOUBLE_PARSER);
-			this.fieldInfo = new TwoDoublesFieldInfo(GetType().Name);
 		}
 
 		[Test]



Mime
View raw message