lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject svn commit: r1375251 - in /incubator/lucene.net/trunk: src/contrib/Spatial/ src/contrib/Spatial/BBox/ src/contrib/Spatial/Prefix/ src/contrib/Spatial/Vector/ test/contrib/Spatial/ test/contrib/Spatial/Queries/ test/contrib/Spatial/Query/
Date Mon, 20 Aug 2012 21:48:37 GMT
Author: synhershko
Date: Mon Aug 20 21:48:36 2012
New Revision: 1375251

URL: http://svn.apache.org/viewvc?rev=1375251&view=rev
Log:
LUCENE-4188 remove field storage from createField

Added:
    incubator/lucene.net/trunk/test/contrib/Spatial/Queries/
    incubator/lucene.net/trunk/test/contrib/Spatial/Queries/SpatialArgsParserTest.cs
      - copied, changed from r1375249, incubator/lucene.net/trunk/test/contrib/Spatial/Query/SpatialArgsParserTest.cs
Removed:
    incubator/lucene.net/trunk/test/contrib/Spatial/Query/SpatialArgsParserTest.cs
Modified:
    incubator/lucene.net/trunk/src/contrib/Spatial/BBox/BBoxStrategy.cs
    incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/PrefixTreeStrategy.cs
    incubator/lucene.net/trunk/src/contrib/Spatial/SpatialStrategy.cs
    incubator/lucene.net/trunk/src/contrib/Spatial/Vector/TwoDoublesStrategy.cs
    incubator/lucene.net/trunk/test/contrib/Spatial/Contrib.Spatial.Test.csproj
    incubator/lucene.net/trunk/test/contrib/Spatial/SpatialTestQuery.cs
    incubator/lucene.net/trunk/test/contrib/Spatial/StrategyTestCase.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=1375251&r1=1375250&r2=1375251&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:48:36
2012
@@ -70,7 +70,7 @@ namespace Lucene.Net.Spatial.BBox
 		// Indexing
 		//---------------------------------
 
-		public override Field CreateField(Shape shape, bool index, bool store)
+		public override Field CreateField(Shape shape)
 		{
 			throw new NotImplementedException();
 		}

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=1375251&r1=1375250&r2=1375251&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:48:36 2012
@@ -61,7 +61,7 @@ namespace Lucene.Net.Spatial.Prefix
 			this.distErrPct = distErrPct;
 		}
 
-		public override Field CreateField(Shape shape, bool index, bool store)
+		public override Field CreateField(Shape shape)
 		{
 			int detailLevel = grid.GetMaxLevelForPrecision(shape, distErrPct);
 			var cells = grid.GetNodes(shape, detailLevel, true);//true=intermediates cells
@@ -78,52 +78,9 @@ 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 = GetFieldName();
-			if (store)
-			{
-				//TODO figure out how to re-use original string instead of reconstituting it.
-				var wkt = grid.GetSpatialContext().ToString(shape);
-				if (index)
-				{
-					var f = new Field(fname, wkt, Field.Store.YES, Field.Index.ANALYZED); // TYPE_STORED
is indexed, stored and tokenized
-					f.OmitNorms = true;
-					f.SetTokenStream(new CellTokenStream(cells.GetEnumerator()));
-					return f;
-				}
-				return new Field(fname, wkt, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS); //
StoredField is only stored
-			}
-
-			if (index)
-			{
-				// TYPE_NOT_STORED is indexed and tokenized but not stored, and this is what this ctor
returns
-				var f = new Field(fname, new CellTokenStream(cells.GetEnumerator()), Field.TermVector.NO);
-				f.OmitNorms = true;
-				return f;
-			}
-
-			throw new InvalidOperationException("Fields need to be indexed or store [" + fname + "]");
+			return new Field(GetFieldName(), new CellTokenStream(cells.GetEnumerator())) {OmitNorms
= true};
 		}
 
-		///* Indexed, tokenized, not stored. */
-		//public static final FieldType TYPE_NOT_STORED = new FieldType();
-
-		///* Indexed, tokenized, stored. */
-		//public static final FieldType TYPE_STORED = new FieldType();
-
-		//static {
-		//  TYPE_UNSTORED.setIndexed(true);
-		//  TYPE_UNSTORED.setTokenized(true);
-		//  TYPE_UNSTORED.setOmitNorms(true);
-		//  TYPE_UNSTORED.freeze();
-
-		//  TYPE_STORED.setStored(true);
-		//  TYPE_STORED.setIndexed(true);
-		//  TYPE_STORED.setTokenized(true);
-		//  TYPE_STORED.setOmitNorms(true);
-		//  TYPE_STORED.freeze();
-		//}
-
-
 		/// <summary>
 		/// Outputs the tokenString of a cell, and if its a leaf, outputs it again with the leaf
byte.
 		/// </summary>

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=1375251&r1=1375250&r2=1375251&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:48:36
2012
@@ -26,7 +26,14 @@ using Spatial4n.Core.Shapes;
 
 namespace Lucene.Net.Spatial
 {
-	/* must be thread safe */
+	/// <summary>
+	/// The SpatialStrategy encapsulates an approach to indexing and searching based on shapes.
+	/// <p/>
+	/// Note that a SpatialStrategy is not involved with the Lucene stored field values of shapes,
which is
+	/// immaterial to indexing & search.
+	/// <p/>
+	/// Thread-safe.
+	/// </summary>
 	public abstract class SpatialStrategy
 	{
 		protected bool ignoreIncompatibleGeometry;
@@ -68,19 +75,36 @@ namespace Lucene.Net.Spatial
 			return fieldName;
 		}
 
-		/**
-		 * Corresponds with Solr's FieldType.createField().
-		 *
-		 * This may return a null field if it does not want to make anything.
-		 * This is reasonable behavior if 'ignoreIncompatibleGeometry=true' and the
-		 * geometry is incompatible
-		 */
-		public abstract Field CreateField(Shape shape, bool index, bool store);
+		/// <summary>
+		/// Corresponds with Solr's FieldType.createField().
+		/// 
+		/// This may return a null field if it does not want to make anything.
+		/// This is reasonable behavior if 'ignoreIncompatibleGeometry=true' and the
+		/// geometry is incompatible
+		/// </summary>
+		/// <param name="shape"></param>
+		/// <returns></returns>
+		public abstract Field CreateField(Shape shape);
+
+		/// <summary>
+		/// Corresponds with Solr's FieldType.createFields().
+		/// <p/>
+		/// Note: If you want to <i>store</i> the shape as a string for retrieval in
search
+		/// results, you could add it like this:
+		/// <pre>document.add(new StoredField(fieldName,ctx.toString(shape)));</pre>
+		/// The particular string representation used doesn't matter to the Strategy since it
+		/// doesn't use it.
+		/// </summary>
+		/// <param name="shape"></param>
+		/// <returns></returns>
+		public virtual AbstractField[] CreateFields(Shape shape)
+		{
+			return new AbstractField[] { CreateField(shape) };
+		}
 
-		/** Corresponds with Solr's FieldType.createFields(). */
-		public virtual AbstractField[] CreateFields(Shape shape, bool index, bool store)
+		public AbstractField CreateStoredField(Shape shape)
 		{
-			return new AbstractField[] { CreateField(shape, index, store) };
+			return new Field(GetFieldName(), ctx.ToString(shape), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS,
Field.TermVector.NO);
 		}
 
 		/// <summary>

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=1375251&r1=1375250&r2=1375251&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:48:36 2012
@@ -66,21 +66,23 @@ namespace Lucene.Net.Spatial.Vector
 			return true;
 		}
 
-		public override AbstractField[] CreateFields(Shape shape, bool index, bool store)
+		public override AbstractField[] CreateFields(Shape shape)
 		{
 			var point = shape as Point;
 			if (point != null)
 			{
-				var f = new AbstractField[(index ? 2 : 0) + (store ? 1 : 0)];
-				if (index)
-				{
-					f[0] = CreateDouble(fieldNameX, point.GetX(), index, store);
-					f[1] = CreateDouble(fieldNameY, point.GetY(), index, store);
-				}
-				if (store)
-				{
-					f[f.Length - 1] = new Field(GetFieldName(), ctx.ToString(shape), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
-				}
+				var f = new AbstractField[2];
+
+				var f0 = new NumericField(fieldNameX, precisionStep, Field.Store.NO, true)
+				         	{OmitNorms = true, OmitTermFreqAndPositions = true};
+				f0.SetDoubleValue(point.GetX());
+				f[0] = f0;
+
+				var f1 = new NumericField(fieldNameY, precisionStep, Field.Store.NO, true)
+				         	{OmitNorms = true, OmitTermFreqAndPositions = true};
+				f1.SetDoubleValue(point.GetY());
+				f[1] = f1;
+
 				return f;
 			}
 			if (!ignoreIncompatibleGeometry)
@@ -90,19 +92,7 @@ namespace Lucene.Net.Spatial.Vector
 			return new AbstractField[0]; // nothing (solr does not support null) 
 		}
 
-		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)
+		public override Field CreateField(Shape shape)
 		{
 			throw new InvalidOperationException("Point is poly field");
 		}

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=1375251&r1=1375250&r2=1375251&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:48:36 2012
@@ -123,7 +123,7 @@
     <Compile Include="Prefix\TestTermQueryPrefixGridStrategy.cs" />
     <Compile Include="Prefix\Tree\SpatialPrefixTreeTest.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
-    <Compile Include="Query\SpatialArgsParserTest.cs" />
+    <Compile Include="Queries\SpatialArgsParserTest.cs" />
     <Compile Include="SpatialMatchConcern.cs" />
     <Compile Include="SpatialTestCase.cs" />
     <Compile Include="SpatialTestQuery.cs" />

Copied: incubator/lucene.net/trunk/test/contrib/Spatial/Queries/SpatialArgsParserTest.cs (from
r1375249, incubator/lucene.net/trunk/test/contrib/Spatial/Query/SpatialArgsParserTest.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/Spatial/Queries/SpatialArgsParserTest.cs?p2=incubator/lucene.net/trunk/test/contrib/Spatial/Queries/SpatialArgsParserTest.cs&p1=incubator/lucene.net/trunk/test/contrib/Spatial/Query/SpatialArgsParserTest.cs&r1=1375249&r2=1375251&rev=1375251&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/Spatial/Query/SpatialArgsParserTest.cs (original)
+++ incubator/lucene.net/trunk/test/contrib/Spatial/Queries/SpatialArgsParserTest.cs Mon Aug
20 21:48:36 2012
@@ -1,10 +1,10 @@
 using System;
+using Lucene.Net.Spatial.Queries;
 using NUnit.Framework;
 using Spatial4n.Core.Context;
-using Spatial4n.Core.Query;
 using Spatial4n.Core.Shapes;
 
-namespace Lucene.Net.Contrib.Spatial.Test.Query
+namespace Lucene.Net.Contrib.Spatial.Test.Queries
 {
 	public class SpatialArgsParserTest
 	{

Modified: incubator/lucene.net/trunk/test/contrib/Spatial/SpatialTestQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/Spatial/SpatialTestQuery.cs?rev=1375251&r1=1375250&r2=1375251&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/Spatial/SpatialTestQuery.cs (original)
+++ incubator/lucene.net/trunk/test/contrib/Spatial/SpatialTestQuery.cs Mon Aug 20 21:48:36
2012
@@ -19,9 +19,9 @@ using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Text;
+using Lucene.Net.Spatial.Queries;
 using Spatial4n.Core.Context;
 using Spatial4n.Core.Io;
-using Spatial4n.Core.Query;
 
 namespace Lucene.Net.Contrib.Spatial.Test
 {

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=1375251&r1=1375250&r2=1375251&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:48:36
2012
@@ -78,13 +78,16 @@ 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(shape, true, storeShape))
+				foreach (var f in strategy.CreateFields(shape))
 				{
 					if (f != null)
 					{ // null if incompatibleGeometry && ignore
 						document.Add(f);
 					}
 				}
+				if (storeShape)
+					document.Add(strategy.CreateStoredField(shape));
+
 				documents.Add(document);
 			}
 			return documents;
@@ -112,6 +115,11 @@ namespace Lucene.Net.Contrib.Spatial.Tes
 
 				String msg = q.line; //"Query: " + q.args.toString(ctx);
 				SearchResults got = executeQuery(strategy.MakeQuery(q.args), 100);
+				if (storeShape && got.numFound > 0)
+				{
+					//check stored value is there & parses
+					Assert.NotNull(ctx.ReadShape(got.results.Get(0).document.get(strategy.GetFieldName())));
+				}
 				if (concern.orderIsImportant)
 				{
 					var ids = q.ids.GetEnumerator();



Mime
View raw message