lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject svn commit: r1344182 [2/9] - in /incubator/lucene.net/trunk: ./ build/vs2010/test/ lib/Spatial4n/ src/contrib/Analyzers/ src/contrib/Analyzers/Filters/ src/contrib/Spatial/ src/contrib/Spatial/Prefix/ src/contrib/Spatial/Prefix/Tree/ src/contrib/Spatia...
Date Wed, 30 May 2012 10:17:21 GMT
Modified: incubator/lucene.net/trunk/src/contrib/Spatial/Properties/AssemblyInfo.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Properties/AssemblyInfo.cs?rev=1344182&r1=1344181&r2=1344182&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Properties/AssemblyInfo.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Properties/AssemblyInfo.cs Wed May 30 10:17:16 2012
@@ -26,8 +26,8 @@ using System.Runtime.InteropServices;
 [assembly: AssemblyConfiguration("")]
 [assembly: AssemblyCompany("The Apache Software Foundation")]
 [assembly: AssemblyProduct("Lucene.Net.Contrib.Spatial")]
-[assembly: AssemblyCopyright("Copyright 2009 - 2011 The Apache Software Foundation")]
-[assembly: AssemblyTrademark("Copyright 2009 - 2011 The Apache Software Foundation")]
+[assembly: AssemblyCopyright("Copyright 2009 - 2012 The Apache Software Foundation")]
+[assembly: AssemblyTrademark("Copyright 2009 - 2012 The Apache Software Foundation")]
 [assembly: AssemblyDefaultAlias("Lucene.Net.Spatial")]
 [assembly: AssemblyCulture("")]
 
@@ -49,10 +49,10 @@ using System.Runtime.InteropServices;
 // You can specify all the values or you can default the Build and Revision Numbers 
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyInformationalVersionAttribute("2.9.0")]
+[assembly: AssemblyInformationalVersionAttribute("2.9.9")]
 
-[assembly: AssemblyVersion("2.9.1.002")]
-[assembly: AssemblyFileVersion("2.9.1.002")]
+[assembly: AssemblyVersion("2.9.9.0")]
+[assembly: AssemblyFileVersion("2.9.9.0")]
 
 
 [assembly: AssemblyDelaySign(false)]

Added: incubator/lucene.net/trunk/src/contrib/Spatial/SimpleSpatialFieldInfo.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/SimpleSpatialFieldInfo.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/SimpleSpatialFieldInfo.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/SimpleSpatialFieldInfo.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+namespace Lucene.Net.Spatial
+{
+	public class SimpleSpatialFieldInfo : SpatialFieldInfo
+	{
+		private readonly string fieldName;
+
+		public SimpleSpatialFieldInfo(string fieldName)
+		{
+			this.fieldName = fieldName;
+		}
+
+		public string GetFieldName()
+		{
+			return fieldName;
+		}
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/SpatialFieldInfo.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/SpatialFieldInfo.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/SpatialFieldInfo.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/SpatialFieldInfo.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+namespace Lucene.Net.Spatial
+{
+	/// <summary>
+	/// Information the strategy needs for the lucene fields
+	/// </summary>
+	public interface SpatialFieldInfo
+	{
+	}
+}

Added: 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=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/SpatialStrategy.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/SpatialStrategy.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,93 @@
+/*
+ * 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 Lucene.Net.Documents;
+using Lucene.Net.Search;
+using Lucene.Net.Search.Function;
+using Spatial4n.Core.Context;
+using Spatial4n.Core.Query;
+using Spatial4n.Core.Shapes;
+
+namespace Lucene.Net.Spatial
+{
+	/* must be thread safe */
+	public abstract class SpatialStrategy<T> where T : SpatialFieldInfo
+	{
+		protected bool ignoreIncompatibleGeometry = false;
+		protected readonly SpatialContext ctx;
+
+		protected SpatialStrategy(SpatialContext ctx)
+		{
+			this.ctx = ctx;
+		}
+
+		public SpatialContext GetSpatialContext()
+		{
+			return ctx;
+		}
+
+		/** Corresponds with Solr's  FieldType.isPolyField(). */
+		public virtual bool IsPolyField()
+		{
+			return false;
+		}
+
+		/**
+		 * 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(T fieldInfo, Shape shape, bool index, bool store);
+
+		/** Corresponds with Solr's FieldType.createFields(). */
+		public virtual AbstractField[] CreateFields(T fieldInfo, Shape shape, bool index, bool store)
+		{
+			return new AbstractField[] { CreateField(fieldInfo, shape, index, store) };
+		}
+
+		public abstract ValueSource MakeValueSource(SpatialArgs args, T fieldInfo);
+
+		/// <summary>
+		/// Make a query
+		/// </summary>
+		/// <param name="args"></param>
+		/// <param name="fieldInfo"></param>
+		/// <returns></returns>
+		public abstract Query MakeQuery(SpatialArgs args, T fieldInfo);
+
+		/// <summary>
+		/// Make a Filter
+		/// </summary>
+		/// <param name="args"></param>
+		/// <param name="fieldInfo"></param>
+		/// <returns></returns>
+		public abstract Filter MakeFilter(SpatialArgs args, T fieldInfo);
+
+		public bool IsIgnoreIncompatibleGeometry()
+		{
+			return ignoreIncompatibleGeometry;
+		}
+
+		public void SetIgnoreIncompatibleGeometry(bool ignoreIncompatibleGeometry)
+		{
+			this.ignoreIncompatibleGeometry = ignoreIncompatibleGeometry;
+		}
+
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Util/Bits.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Util/Bits.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Util/Bits.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Util/Bits.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+namespace Lucene.Net.Spatial.Util
+{
+	/// <summary>
+	/// Interface for Bitset-like structures.
+	/// </summary>
+	public abstract class Bits
+	{
+		public abstract bool Get(int index);
+		public abstract int Length();
+
+		public static readonly Bits[] EMPTY_ARRAY = new Bits[0];
+
+		/// <summary>
+		/// Bits impl of the specified length with all bits set.
+		/// </summary>
+		public class MatchAllBits : Bits
+		{
+			readonly int len;
+
+			public MatchAllBits(int len)
+			{
+				this.len = len;
+			}
+
+			public override bool Get(int index)
+			{
+				return true;
+			}
+
+			public override int Length()
+			{
+				return len;
+			}
+		}
+
+		/// <summary>
+		/// Bits impl of the specified length with no bits set. 
+		/// </summary>
+		public class MatchNoBits : Bits
+		{
+			readonly int len;
+
+			public MatchNoBits(int len)
+			{
+				this.len = len;
+			}
+
+			public override bool Get(int index)
+			{
+				return false;
+			}
+
+			public override int Length()
+			{
+				return len;
+			}
+		}
+	}
+}
\ No newline at end of file

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Util/CachedDistanceValueSource.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Util/CachedDistanceValueSource.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Util/CachedDistanceValueSource.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Util/CachedDistanceValueSource.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,110 @@
+/*
+ * 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 Lucene.Net.Index;
+using Lucene.Net.Search.Function;
+using Spatial4n.Core.Distance;
+using Spatial4n.Core.Shapes;
+
+namespace Lucene.Net.Spatial.Util
+{
+	/// <summary>
+	/// An implementation of the Lucene ValueSource model to support spatial relevance ranking.
+	/// </summary>
+	public class CachedDistanceValueSource : ValueSource
+	{
+		private readonly ShapeFieldCacheProvider<Point> provider;
+		private readonly DistanceCalculator calculator;
+		private readonly Point from;
+
+		public CachedDistanceValueSource(Point from, DistanceCalculator calc, ShapeFieldCacheProvider<Point> provider)
+		{
+			this.from = from;
+			this.provider = provider;
+			this.calculator = calc;
+		}
+
+		public class CachedDistanceDocValues : DocValues
+		{
+			private readonly CachedDistanceValueSource enclosingInstance;
+			private readonly ShapeFieldCache<Point> cache;
+
+			public CachedDistanceDocValues(ShapeFieldCache<Point> cache, CachedDistanceValueSource enclosingInstance)
+			{
+				this.enclosingInstance = enclosingInstance;
+				this.cache = cache;
+			}
+
+			public override float FloatVal(int doc)
+			{
+				return (float)DoubleVal(doc);
+			}
+
+			public override double DoubleVal(int doc)
+			{
+				var vals = cache.GetShapes(doc);
+				if (vals != null)
+				{
+					double v = enclosingInstance.calculator.Distance(enclosingInstance.from, vals[0]);
+					for (int i = 1; i < vals.Count; i++)
+					{
+						v = Math.Min(v, enclosingInstance.calculator.Distance(enclosingInstance.from, vals[i]));
+					}
+					return v;
+				}
+				return Double.NaN; // ?? maybe max?
+			}
+
+			public override string ToString(int doc)
+			{
+				return enclosingInstance.Description() + "=" + FloatVal(doc);
+			}
+		}
+
+		public override DocValues GetValues(IndexReader reader)
+		{
+			ShapeFieldCache<Point> cache = provider.GetCache(reader);
+			return new CachedDistanceDocValues(cache, this);
+		}
+
+		public override string Description()
+		{
+			return "DistanceValueSource(" + calculator + ")";
+		}
+
+		public override bool Equals(object o)
+		{
+			if (this == o) return true;
+
+			var that = o as CachedDistanceValueSource;
+
+			if (that == null) return false;
+			if (calculator != null ? !calculator.Equals(that.calculator) : that.calculator != null) return false;
+			if (from != null ? !from.Equals(that.from) : that.from != null) return false;
+
+			return true;
+		}
+
+		public override int GetHashCode()
+		{
+			var result = calculator != null ? calculator.GetHashCode() : 0;
+			result = 31 * result + (from != null ? from.GetHashCode() : 0);
+			return result;
+		}
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Util/CachingDoubleValueSource.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Util/CachingDoubleValueSource.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Util/CachingDoubleValueSource.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Util/CachingDoubleValueSource.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,101 @@
+/*
+ * 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.Collections.Generic;
+using Lucene.Net.Index;
+using Lucene.Net.Search.Function;
+
+namespace Lucene.Net.Spatial.Util
+{
+	public class CachingDoubleValueSource : ValueSource
+	{
+		protected readonly ValueSource source;
+		protected readonly Dictionary<int, double> cache;
+
+		public CachingDoubleValueSource(ValueSource source)
+		{
+			this.source = source;
+			cache = new Dictionary<int, double>();
+		}
+
+		public class CachingDoubleDocValue : DocValues
+		{
+			private readonly int docBase;
+			private readonly DocValues values;
+			private readonly Dictionary<int, double> cache;
+
+			public CachingDoubleDocValue(int docBase, DocValues vals, Dictionary<int, double> cache)
+			{
+				this.docBase = docBase;
+				this.values = vals;
+				this.cache = cache;
+			}
+
+			public override double DoubleVal(int doc)
+			{
+				var key = docBase + doc;
+				double v;
+				if (!cache.TryGetValue(key, out v))
+				{
+					v = values.DoubleVal(doc);
+					cache[key] = v;
+				}
+				return v;
+			}
+
+			public override float FloatVal(int doc)
+			{
+				return (float)DoubleVal(doc);
+			}
+
+			public override string ToString(int doc)
+			{
+				return DoubleVal(doc) + string.Empty;
+			}
+		}
+
+		public override DocValues GetValues(IndexReader reader)
+		{
+			var @base = 0; //reader.DocBase;
+			var vals = source.GetValues(reader);
+			return new CachingDoubleDocValue(@base, vals, cache);
+
+		}
+
+		public override string Description()
+		{
+			return "Cached[" + source.Description() + "]";
+		}
+
+		public override bool Equals(object o)
+		{
+			if (this == o) return true;
+
+			var that = o as CachingDoubleValueSource;
+
+			if (that == null) return false;
+			if (source != null ? !source.Equals(that.source) : that.source != null) return false;
+
+			return true;
+		}
+
+		public override int GetHashCode()
+		{
+			return source != null ? source.GetHashCode() : 0;
+		}
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Util/CompatibilityExtensions.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Util/CompatibilityExtensions.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Util/CompatibilityExtensions.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Util/CompatibilityExtensions.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,192 @@
+/*
+ * 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.Concurrent;
+using System.Collections.Generic;
+using System.Diagnostics;
+using Lucene.Net.Analysis.Tokenattributes;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+
+namespace Lucene.Net.Spatial.Util
+{
+	public static class CompatibilityExtensions
+	{
+		public static void Append(this ITermAttribute termAtt, string str)
+		{
+			termAtt.SetTermBuffer(termAtt.Term() + str); // TODO: Not optimal, but works
+		}
+
+		public static void Append(this ITermAttribute termAtt, char ch)
+		{
+			termAtt.SetTermBuffer(termAtt.Term() + new string(new[] { ch })); // TODO: Not optimal, but works
+		}
+
+		private static readonly ConcurrentDictionary<string, Bits> _docsWithFieldCache = new ConcurrentDictionary<string, Bits>();
+
+		internal static Bits GetDocsWithField(this FieldCache fc, IndexReader reader, String field)
+		{
+			return _docsWithFieldCache.GetOrAdd(field, f => DocsWithFieldCacheEntry_CreateValue(reader, new Entry(field, null), false));
+		}
+
+		private static Bits DocsWithFieldCacheEntry_CreateValue(IndexReader reader, Entry entryKey, bool setDocsWithField /* ignored */)
+		{
+			var field = entryKey.field;
+			FixedBitSet res = null;
+			var terms = new TermsEnumCompatibility(reader, field);
+			var maxDoc = reader.MaxDoc;
+
+			var term = terms.Next();
+			if (term != null)
+			{
+				int termsDocCount = terms.GetDocCount();
+				Debug.Assert(termsDocCount <= maxDoc);
+				if (termsDocCount == maxDoc)
+				{
+					// Fast case: all docs have this field:
+					return new Bits.MatchAllBits(maxDoc);
+				}
+
+				while (true)
+				{
+					if (res == null)
+					{
+						// lazy init
+						res = new FixedBitSet(maxDoc);
+					}
+
+					var termDocs = reader.TermDocs(term);
+					while (termDocs.Next())
+					{
+						res.Set(termDocs.Doc);
+					}
+		
+					term = terms.Next();
+					if (term == null)
+					{
+						break;
+					}
+				}
+			}
+			if (res == null)
+			{
+				return new Bits.MatchNoBits(maxDoc);
+			}
+			int numSet = res.Cardinality();
+			if (numSet >= maxDoc)
+			{
+				// The cardinality of the BitSet is maxDoc if all documents have a value.
+				Debug.Assert(numSet == maxDoc);
+				return new Bits.MatchAllBits(maxDoc);
+			}
+			return res;
+		}
+
+		/** table of number of leading zeros in a byte */
+		public static readonly byte[] nlzTable = { 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+
+		/// <summary>
+		/// Returns the number of leading zero bits.
+		/// </summary>
+		/// <param name="x"></param>
+		/// <returns></returns>
+		public static int BitUtilNlz(long x)
+		{
+			int n = 0;
+			// do the first step as a long
+			int y = (int)((ulong)x >> 32);
+			if (y == 0) { n += 32; y = (int)(x); }
+			if ((y & 0xFFFF0000) == 0) { n += 16; y <<= 16; }
+			if ((y & 0xFF000000) == 0) { n += 8; y <<= 8; }
+			return n + nlzTable[(uint)y >> 24];
+			/* implementation without table:
+			  if ((y & 0xF0000000) == 0) { n+=4; y<<=4; }
+			  if ((y & 0xC0000000) == 0) { n+=2; y<<=2; }
+			  if ((y & 0x80000000) == 0) { n+=1; y<<=1; }
+			  if ((y & 0x80000000) == 0) { n+=1;}
+			  return n;
+			 */
+		}
+	}
+
+	public static class Arrays
+	{
+		public static void Fill<T>(T[] array, int fromIndex, int toIndex, T value)
+		{
+			if (array == null)
+			{
+				throw new ArgumentNullException("array");
+			}
+			if (fromIndex < 0 || fromIndex > toIndex)
+			{
+				throw new ArgumentOutOfRangeException("fromIndex");
+			}
+			if (toIndex > array.Length)
+			{
+				throw new ArgumentOutOfRangeException("toIndex");
+			}
+			for (var i = fromIndex; i < toIndex; i++)
+			{
+				array[i] = value;
+			}
+		}
+	}
+
+	/// <summary>
+	/// Expert: Every composite-key in the internal cache is of this type.
+	/// </summary>
+	internal class Entry
+	{
+		internal readonly String field;        // which Fieldable
+		internal readonly Object custom;       // which custom comparator or parser
+
+		/** Creates one of these objects for a custom comparator/parser. */
+		public Entry(String field, Object custom)
+		{
+			this.field = field;
+			this.custom = custom;
+		}
+
+		/** Two of these are equal iff they reference the same field and type. */
+		public override bool Equals(Object o)
+		{
+			var other = o as Entry;
+			if (other != null)
+			{
+				if (other.field.Equals(field))
+				{
+					if (other.custom == null)
+					{
+						if (custom == null) return true;
+					}
+					else if (other.custom.Equals(custom))
+					{
+						return true;
+					}
+				}
+			}
+			return false;
+		}
+
+		/** Composes a hashcode based on the field and type. */
+		public override int GetHashCode()
+		{
+			return field.GetHashCode() ^ (custom == null ? 0 : custom.GetHashCode());
+		}
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Util/FixedBitSet.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Util/FixedBitSet.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Util/FixedBitSet.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Util/FixedBitSet.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,414 @@
+/**
+ * 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;
+using System.Diagnostics;
+using System.Linq;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
+
+namespace Lucene.Net.Spatial.Util
+{
+	/** BitSet of fixed length (numBits), backed by accessible
+ *  ({@link #getBits}) long[], accessed with an int index,
+ *  implementing Bits and DocIdSet.  Unlike {@link
+ *  OpenBitSet} this bit set does not auto-expand, cannot
+ *  handle long index, and does not have fastXX/XX variants
+ *  (just X).
+ *
+ * @lucene.internal
+ **/
+	public class FixedBitSet : Bits
+	{
+		private readonly BitArray bits;
+
+		/// <summary>
+		/// returns the number of 64 bit words it would take to hold numBits
+		/// </summary>
+		/// <param name="numBits"></param>
+		/// <returns></returns>
+		public static int bits2words(int numBits)
+		{
+			var numLong = (int)((uint)numBits >> 6);
+			if ((numBits & 63) != 0)
+			{
+				numLong++;
+			}
+			return numLong;
+		}
+
+		public FixedBitSet(int numBits)
+		{
+			bits = new BitArray(numBits);
+		}
+
+		/// <summary>
+		/// Makes full copy.
+		/// </summary>
+		/// <param name="other"></param>
+		public FixedBitSet(FixedBitSet other)
+		{
+			bits = new BitArray(other.bits);
+		}
+
+		public Bits Bits()
+		{
+			return this;
+		}
+
+		public override int Length()
+		{
+			return bits.Length;
+		}
+
+		public bool IsCacheable()
+		{
+			return true;
+		}
+
+		/// <summary>
+		/// Returns number of set bits.  NOTE: this visits every
+		/// long in the backing bits array, and the result is not
+		/// internally cached!
+		/// </summary>
+		/// <returns></returns>
+		public int Cardinality()
+		{
+			int ret = 0;
+			for (var i = 0; i < bits.Length; i++)
+			{
+				if (bits[i]) ret++;
+			}
+			return ret;
+		}
+
+		public override bool Get(int index)
+		{
+			return bits[index];
+		}
+
+		public void Set(int index)
+		{
+			bits.Set(index, true);
+		}
+
+		public bool GetAndSet(int index)
+		{
+			var ret = bits[index];
+			bits.Set(index, true);
+			return ret;
+		}
+
+		public void Clear(int index)
+		{
+			bits.Set(index, false);
+		}
+
+		public bool GetAndClear(int index)
+		{
+			var ret = bits[index];
+			bits.Set(index, false);
+			return ret;
+		}
+
+		/// <summary>
+		/// Returns the index of the first set bit starting at the index specified.
+		/// -1 is returned if there are no more set bits.
+		/// </summary>
+		/// <param name="index"></param>
+		/// <returns></returns>
+		public int NextSetBit(int index)
+		{
+			if (index >= bits.Length || index < 0)
+				throw new ArgumentException("Invalid index", "index");
+
+			for (var i = index; i < bits.Length; i++)
+			{
+				if (bits[i]) return i;
+			}
+
+			return -1;
+		}
+
+		/** Returns the index of the last set bit before or on the index specified.
+		 *  -1 is returned if there are no more set bits.
+		 */
+		public int PrevSetBit(int index)
+		{
+			if (index >= bits.Length || index < 0)
+				throw new ArgumentException("Invalid index", "index");
+
+			for (var i = index; i >= 0; i--)
+			{
+				if (bits[i]) return i;
+			}
+
+			return -1;
+		}
+
+		/** Does in-place OR of the bits provided by the
+		 *  iterator. */
+		//public void Or(DocIdSetIterator iter)
+		//{
+		//    if (iter is OpenBitSetIterator && iter.DocID() == -1)
+		//    {
+		//        var obs = (OpenBitSetIterator)iter;
+		//        Or(obs.arr, obs.words);
+		//        // advance after last doc that would be accepted if standard
+		//        // iteration is used (to exhaust it):
+		//        obs.Advance(bits.Length);
+		//    }
+		//    else
+		//    {
+		//        int doc;
+		//        while ((doc = iter.NextDoc()) < bits.Length)
+		//        {
+		//            Set(doc);
+		//        }
+		//    }
+		//}
+
+		/** this = this OR other */
+		public void Or(FixedBitSet other)
+		{
+			Or(other.bits, other.bits.Length);
+		}
+
+		private void Or(BitArray otherArr, int otherLen)
+		{
+			var thisArr = this.bits;
+			int pos = Math.Min(thisArr.Length, otherLen);
+			while (--pos >= 0)
+			{
+				thisArr[pos] |= otherArr[pos];
+			}
+		}
+
+		/** Does in-place AND of the bits provided by the
+		 *  iterator. */
+		//public void And(DocIdSetIterator iter)
+		//{
+		//    if (iter is OpenBitSetIterator && iter.DocID() == -1)
+		//    {
+		//        var obs = (OpenBitSetIterator)iter;
+		//        And(obs.arr, obs.words);
+		//        // advance after last doc that would be accepted if standard
+		//        // iteration is used (to exhaust it):
+		//        obs.Advance(bits.Length);
+		//    }
+		//    else
+		//    {
+		//        if (bits.Length == 0) return;
+		//        int disiDoc, bitSetDoc = NextSetBit(0);
+		//        while (bitSetDoc != -1 && (disiDoc = iter.Advance(bitSetDoc)) < bits.Length)
+		//        {
+		//            Clear(bitSetDoc, disiDoc);
+		//            disiDoc++;
+		//            bitSetDoc = (disiDoc < bits.Length) ? NextSetBit(disiDoc) : -1;
+		//        }
+		//        if (bitSetDoc != -1)
+		//        {
+		//            Clear(bitSetDoc, bits.Length);
+		//        }
+		//    }
+		//}
+
+		/** this = this AND other */
+		public void And(FixedBitSet other)
+		{
+			And(other.bits, other.bits.Length);
+		}
+
+		private void And(BitArray otherArr, int otherLen)
+		{
+			var thisArr = this.bits;
+			int pos = Math.Min(thisArr.Length, otherLen);
+			while (--pos >= 0)
+			{
+				thisArr[pos] &= otherArr[pos];
+			}
+			if (thisArr.Length > otherLen)
+			{
+				for (var i = otherLen; i < thisArr.Length; i++)
+				{
+					thisArr[i] = false;
+				}
+			}
+		}
+
+		/** Does in-place AND NOT of the bits provided by the
+		 *  iterator. */
+		//public void AndNot(DocIdSetIterator iter)
+		//{
+		//    var obs = iter as OpenBitSetIterator;
+		//    if (obs != null && iter.DocID() == -1)
+		//    {
+		//        AndNot(obs.arr, obs.words);
+		//        // advance after last doc that would be accepted if standard
+		//        // iteration is used (to exhaust it):
+		//        obs.Advance(bits.Length);
+		//    }
+		//    else
+		//    {
+		//        int doc;
+		//        while ((doc = iter.NextDoc()) < bits.Length)
+		//        {
+		//            Clear(doc);
+		//        }
+		//    }
+		//}
+
+		/** this = this AND NOT other */
+		public void AndNot(FixedBitSet other)
+		{
+			AndNot(other.bits, other.bits.Length);
+		}
+
+		private void AndNot(BitArray otherArr, int otherLen)
+		{
+			var thisArr = this.bits;
+			int pos = Math.Min(thisArr.Length, otherLen);
+			while (--pos >= 0)
+			{
+				thisArr[pos] &= !otherArr[pos];
+			}
+		}
+
+		// NOTE: no .isEmpty() here because that's trappy (ie,
+		// typically isEmpty is low cost, but this one wouldn't
+		// be)
+
+		/** Flips a range of bits
+		 *
+		 * @param startIndex lower index
+		 * @param endIndex one-past the last bit to flip
+		 */
+		//      public void Flip(int startIndex, int endIndex) {
+		//  Debug.Assert(startIndex >= 0 && startIndex < numBits);
+		//  Debug.Assert(endIndex >= 0 && endIndex <= numBits);
+		//  if (endIndex <= startIndex) {
+		//    return;
+		//  }
+
+		//  int startWord = startIndex >> 6;
+		//  int endWord = (endIndex-1) >> 6;
+
+		//  /*** Grrr, java shifting wraps around so -1L>>>64 == -1
+		//   * for that reason, make sure not to use endmask if the bits to flip will
+		//   * be zero in the last word (redefine endWord to be the last changed...)
+		//  long startmask = -1L << (startIndex & 0x3f);     // example: 11111...111000
+		//  long endmask = -1L >>> (64-(endIndex & 0x3f));   // example: 00111...111111
+		//  ***/
+
+		//  long startmask = -1L << startIndex;
+		//  long endmask =  -1L >>> -endIndex;  // 64-(endIndex&0x3f) is the same as -endIndex due to wrap
+
+		//  if (startWord == endWord) {
+		//    bits[startWord] ^= (startmask & endmask);
+		//    return;
+		//  }
+
+		//  bits[startWord] ^= startmask;
+
+		//  for (var i=startWord+1; i<endWord; i++) {
+		//    bits[i] = ~bits[i];
+		//  }
+
+		//  bits[endWord] ^= endmask;
+		//}
+
+		/** Sets a range of bits
+		 *
+		 * @param startIndex lower index
+		 * @param endIndex one-past the last bit to set
+		 */
+		public void Set(int startIndex, int endIndex)
+		{
+			// Naive implementation
+			for (int i = startIndex; i < endIndex; i++)
+			{
+				Set(i);
+			}
+		}
+
+		//      public void Set(int startIndex, int endIndex) {
+		//  Debug.Assert(startIndex >= 0 && startIndex < numBits);
+		//  Debug.Assert(endIndex >= 0 && endIndex <= numBits);
+		//  if (endIndex <= startIndex) {
+		//    return;
+		//  }
+
+		//  int startWord = startIndex >> 6;
+		//  int endWord = (endIndex-1) >> 6;
+
+		//  long startmask = -1L << startIndex;
+		//  long endmask = -1L >>> -endIndex;  // 64-(endIndex&0x3f) is the same as -endIndex due to wrap
+
+		//  if (startWord == endWord) {
+		//    bits[startWord] |= (startmask & endmask);
+		//    return;
+		//  }
+
+		//  bits[startWord] |= startmask;
+		//  Arrays.Fill(bits, startWord+1, endWord, -1L);
+		//  bits[endWord] |= endmask;
+		//}
+
+		/** Clears a range of bits.
+		 *
+		 * @param startIndex lower index
+		 * @param endIndex one-past the last bit to clear
+		 */
+		public void Clear(int startIndex, int endIndex)
+		{
+			for (int i = startIndex; i < endIndex; i++)
+			{
+				Clear(i);
+			}
+		}
+
+		//@Override
+		public FixedBitSet Clone()
+		{
+			return new FixedBitSet(this);
+		}
+
+		/** returns true if both sets have the same bits set */
+		public override bool Equals(Object o)
+		{
+			if (this == o)
+			{
+				return true;
+			}
+
+			var other = o as FixedBitSet;
+			if (other == null)
+			{
+				return false;
+			}
+
+			return bits.Equals(other.bits);
+		}
+
+		public override int GetHashCode()
+		{
+			return bits.GetHashCode();
+		}
+
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Util/FunctionQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Util/FunctionQuery.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Util/FunctionQuery.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Util/FunctionQuery.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,215 @@
+/**
+ * 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 Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.Search.Function;
+
+namespace Lucene.Net.Spatial.Util
+{
+	/// <summary>
+	/// Port of Solr's FunctionQuery (v1.4)
+	/// 
+	/// Returns a score for each document based on a ValueSource,
+	/// often some function of the value of a field.
+	/// 
+	/// <b>Note: This API is experimental and may change in non backward-compatible ways in the future</b>
+	/// </summary>
+	public class FunctionQuery : Query
+	{
+		protected readonly ValueSource func;
+
+		public FunctionQuery(ValueSource func)
+		{
+			this.func = func;
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <returns>The associated ValueSource</returns>
+		public ValueSource GetValueSource()
+		{
+			return func;
+		}
+
+		public override Query Rewrite(Index.IndexReader reader)
+		{
+			return this;
+		}
+
+		public override void ExtractTerms(System.Collections.Generic.ISet<Term> terms)
+		{
+			//base.ExtractTerms(terms);
+		}
+
+		protected class FunctionWeight : Weight
+		{
+			protected Searcher searcher;
+			protected float queryNorm;
+			protected float queryWeight;
+			protected readonly FunctionQuery enclosingInstance;
+
+			public FunctionWeight(Searcher searcher, FunctionQuery q)
+			{
+				enclosingInstance = q;
+				this.searcher = searcher;
+				//q.func.CreateWeight(searcher);
+			}
+
+			internal float GetQueryNorm()
+			{
+				return queryNorm;
+			}
+
+			public override Query Query
+			{
+				get { return enclosingInstance; }
+			}
+
+			public override float Value
+			{
+				get { return queryWeight; }
+			}
+
+			public override float GetSumOfSquaredWeights()
+			{
+				queryWeight = enclosingInstance.Boost;
+				return queryWeight * queryWeight;
+			}
+
+			public override void Normalize(float norm)
+			{
+				this.queryNorm = norm;
+				queryWeight *= this.queryNorm;
+			}
+
+			public override Scorer Scorer(IndexReader reader, bool scoreDocsInOrder, bool topScorer)
+			{
+				return new AllScorer(enclosingInstance.GetSimilarity(searcher), reader, this);
+			}
+
+			public override Explanation Explain(IndexReader reader, int doc)
+			{
+				return ((AllScorer)Scorer(reader, true, true)).Explain(doc);
+			}
+		}
+
+		protected class AllScorer : Scorer
+		{
+			readonly IndexReader reader;
+			readonly FunctionWeight weight;
+			readonly int maxDoc;
+			readonly float qWeight;
+			int doc = -1;
+			readonly DocValues vals;
+			readonly bool hasDeletions;
+
+			public AllScorer(Similarity similarity, IndexReader reader, FunctionWeight w)
+				: base(similarity)
+			{
+				this.weight = w;
+				this.qWeight = w.Value;
+				this.reader = reader;
+				this.maxDoc = reader.MaxDoc;
+				this.hasDeletions = reader.HasDeletions;
+				vals = ((FunctionQuery)w.Query).func.GetValues(reader);
+			}
+
+			public override int DocID()
+			{
+				return doc;
+			}
+
+			// instead of matching all docs, we could also embed a query.
+			// the score could either ignore the subscore, or boost it.
+			// Containment:  floatline(foo:myTerm, "myFloatField", 1.0, 0.0f)
+			// Boost:        foo:myTerm^floatline("myFloatField",1.0,0.0f)
+			public override int NextDoc()
+			{
+				for (; ; )
+				{
+					++doc;
+					if (doc >= maxDoc)
+					{
+						return doc = NO_MORE_DOCS;
+					}
+					if (hasDeletions && reader.IsDeleted(doc)) continue;
+					return doc;
+				}
+			}
+
+			public override int Advance(int target)
+			{
+				// this will work even if target==NO_MORE_DOCS
+				doc = target - 1;
+				return NextDoc();
+			}
+
+			public override float Score()
+			{
+				float score = qWeight * vals.FloatVal(doc);
+
+				// Current Lucene priority queues can't handle NaN and -Infinity, so
+				// map to -Float.MAX_VALUE. This conditional handles both -infinity
+				// and NaN since comparisons with NaN are always false.
+				return score > float.NegativeInfinity ? score : -float.MaxValue;
+			}
+
+			public /*override*/ Explanation Explain(int doc)
+			{
+				float sc = qWeight * vals.FloatVal(doc);
+
+				Explanation result = new ComplexExplanation
+				  (true, sc, "FunctionQuery(" + ((FunctionQuery)weight.Query).func + "), product of:");
+
+				result.AddDetail(vals.Explain(doc));
+				result.AddDetail(new Explanation(weight.Query.Boost, "boost"));
+				result.AddDetail(new Explanation(weight.GetQueryNorm(), "queryNorm"));
+				return result;
+			}
+		}
+
+		public override Weight CreateWeight(Searcher searcher)
+		{
+			return new FunctionQuery.FunctionWeight(searcher, this);
+		}
+
+		public override string ToString(string field)
+		{
+			float boost = Boost;
+			return (boost != 1.0 ? "(" : "") + func.ToString()
+					+ (boost == 1.0 ? "" : ")^" + boost);
+		}
+
+		public override bool Equals(object o)
+		{
+			var other = o as FunctionQuery;
+
+			if (other == null) return false;
+
+			return this.Boost == other.Boost && this.func.Equals(other.func);
+		}
+
+		public override int GetHashCode()
+		{
+			return (int) (func.GetHashCode() * 31 + BitConverter.DoubleToInt64Bits(Boost));
+		}
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Util/NumericFieldInfo.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Util/NumericFieldInfo.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Util/NumericFieldInfo.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Util/NumericFieldInfo.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,51 @@
+/*
+ * 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 Lucene.Net.Documents;
+
+namespace Lucene.Net.Spatial.Util
+{
+	/// <summary>
+	/// Hold some of the parameters used by solr...
+	/// </summary>
+	public class NumericFieldInfo
+	{
+		public int precisionStep = 8; // same as solr default
+		public bool store = true;
+		public bool index = true;
+
+		public void SetPrecisionStep(int p)
+		{
+			precisionStep = p;
+			if (precisionStep <= 0 || precisionStep >= 64)
+				precisionStep = int.MaxValue;
+		}
+
+		public AbstractField CreateDouble(String name, double v)
+		{
+			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;
+		}
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Util/OpenBitSetIterator.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Util/OpenBitSetIterator.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Util/OpenBitSetIterator.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Util/OpenBitSetIterator.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,194 @@
+/* 
+ * 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 Lucene.Net.Search;
+using Lucene.Net.Util;
+
+namespace Lucene.Net.Spatial.Util
+{
+
+	/// <summary>An iterator to iterate over set bits in an OpenBitSet.
+	/// This is faster than nextSetBit() for iterating over the complete set of bits,
+	/// especially when the density of the bits set is high.
+	/// 
+	/// </summary>
+	/// <version>  $Id$
+	/// </version>
+	public class OpenBitSetIterator : DocIdSetIterator
+	{
+
+		// The General Idea: instead of having an array per byte that has
+		// the offsets of the next set bit, that array could be
+		// packed inside a 32 bit integer (8 4 bit numbers).  That
+		// should be faster than accessing an array for each index, and
+		// the total array size is kept smaller (256*sizeof(int))=1K
+		protected internal static readonly uint[] bitlist = new uint[]{0x0, 0x1, 0x2, 0x21, 0x3, 0x31, 0x32, 0x321, 0x4, 0x41, 0x42, 0x421, 0x43, 0x431, 0x432, 0x4321, 0x5, 0x51, 0x52, 0x521, 0x53, 0x531, 0x532, 0x5321, 0x54, 0x541, 0x542, 0x5421, 0x543, 0x5431, 0x5432, 0x54321, 0x6, 0x61, 0x62, 0x621, 0x63, 0x631, 0x632, 0x6321, 0x64, 0x641, 0x642, 0x6421, 0x643, 0x6431, 0x6432, 0x64321, 0x65, 0x651, 0x652, 0x6521, 0x653, 0x6531, 0x6532, 0x65321, 0x654, 0x6541, 0x6542, 0x65421, 0x6543, 0x65431, 0x65432, 0x654321, 0x7, 0x71, 0x72, 0x721, 0x73, 0x731, 0x732, 0x7321, 0x74, 0x741, 0x742, 0x7421, 0x743, 0x7431, 0x7432, 0x74321, 0x75, 0x751, 0x752, 0x7521, 0x753, 0x7531, 0x7532, 0x75321, 0x754, 0x7541, 0x7542, 0x75421, 0x7543, 0x75431, 0x75432, 0x754321, 0x76, 0x761, 0x762, 0x7621, 0x763, 0x7631, 0x7632, 0x76321, 0x764, 0x7641, 0x7642, 0x76421, 0x7643, 0x76431, 0x76432, 0x764321, 0x765, 0x7651, 0x7652, 0x76521, 0x7653, 0x76531, 0x76532, 0x765321, 0x7654, 0x76541, 0x76542, 0x765421, 0x7
 6543, 0x765431, 0x765432, 0x7654321, 0x8, 0x81, 0x82, 0x821, 0x83, 0x831, 0x832, 0x8321, 0x84, 0x841, 0x842, 0x8421, 0x843, 0x8431, 0x8432, 0x84321, 0x85, 0x851, 0x852, 0x8521, 0x853, 0x8531, 0x8532, 0x85321, 0x854, 0x8541, 0x8542, 0x85421, 0x8543, 0x85431, 0x85432, 0x854321, 0x86, 0x861, 0x862, 0x8621, 0x863, 0x8631, 0x8632, 0x86321, 0x864, 0x8641, 0x8642, 0x86421, 0x8643, 0x86431, 0x86432, 0x864321, 0x865, 0x8651, 0x8652, 0x86521, 0x8653, 0x86531, 0x86532, 0x865321, 0x8654, 0x86541, 0x86542, 0x865421, 0x86543, 0x865431, 0x865432, 0x8654321, 0x87, 0x871, 0x872, 0x8721, 0x873, 0x8731, 0x8732, 0x87321, 0x874, 0x8741, 0x8742, 0x87421, 0x8743, 0x87431, 0x87432, 0x874321, 0x875, 0x8751, 0x8752, 0x87521, 0x8753, 0x87531, 0x87532, 0x875321, 0x8754, 0x87541, 0x87542, 0x875421, 0x87543, 0x875431, 0x875432, 0x8754321, 0x876, 0x8761, 0x8762, 0x87621, 0x8763, 0x87631, 0x87632, 0x876321, 0x8764, 0x87641, 0x87642, 0x876421, 0x87643, 0x876431, 0x876432, 0x8764321, 0x8765, 0x87651, 0x87652
 , 0x876521, 0x87653, 0x876531, 0x876532, 0x8765321, 0x87654, 
+			0x876541, 0x876542, 0x8765421, 0x876543, 0x8765431, 0x8765432, 0x87654321};
+		/// <summary>** the python code that generated bitlist
+		/// def bits2int(val):
+		/// arr=0
+		/// for shift in range(8,0,-1):
+		/// if val &amp; 0x80:
+		/// arr = (arr &lt;&lt; 4) | shift
+		/// val = val &lt;&lt; 1
+		/// return arr
+		/// def int_table():
+		/// tbl = [ hex(bits2int(val)).strip('L') for val in range(256) ]
+		/// return ','.join(tbl)
+		/// ****
+		/// </summary>
+
+		// hmmm, what about an iterator that finds zeros though,
+		// or a reverse iterator... should they be separate classes
+		// for efficiency, or have a common root interface?  (or
+		// maybe both?  could ask for a SetBitsIterator, etc...
+
+		private readonly long[] arr;
+		private readonly int words;
+		private int i = -1;
+		private long word;
+		private int wordShift;
+		private int indexArray;
+		private int curDocId = -1;
+
+		public OpenBitSetIterator(OpenBitSet obs)
+			: this(obs.Bits, obs.NumWords)
+		{
+		}
+
+		public OpenBitSetIterator(long[] bits, int numWords)
+		{
+			arr = bits;
+			words = numWords;
+		}
+
+		// 64 bit shifts
+		private void Shift()
+		{
+			if ((int)word == 0)
+			{
+				wordShift += 32; word = (long)((ulong)word >> 32);
+			}
+			if ((word & 0x0000FFFF) == 0)
+			{
+				wordShift += 16; word = (long)((ulong)word >> 16);
+			}
+			if ((word & 0x000000FF) == 0)
+			{
+				wordShift += 8; word = (long)((ulong)word >> 8);
+			}
+			indexArray = (int)bitlist[word & 0xff];
+		}
+
+		/*/// <summary>** alternate shift implementations
+		/// // 32 bit shifts, but a long shift needed at the end
+		/// private void shift2() {
+		/// int y = (int)word;
+		/// if (y==0) {wordShift +=32; y = (int)(word >>>32); }
+		/// if ((y & 0x0000FFFF) == 0) { wordShift +=16; y>>>=16; }
+		/// if ((y & 0x000000FF) == 0) { wordShift +=8; y>>>=8; }
+		/// indexArray = bitlist[y & 0xff];
+		/// word >>>= (wordShift +1);
+		/// }
+		/// private void shift3() {
+		/// int lower = (int)word;
+		/// int lowByte = lower & 0xff;
+		/// if (lowByte != 0) {
+		/// indexArray=bitlist[lowByte];
+		/// return;
+		/// }
+		/// shift();
+		/// }
+		/// ****
+		/// </summary>*/
+
+		public override int NextDoc()
+		{
+			if (indexArray == 0)
+			{
+				if (word != 0)
+				{
+					word = (long)((ulong)word >> 8);
+					wordShift += 8;
+				}
+
+				while (word == 0)
+				{
+					if (++i >= words)
+					{
+						return curDocId = NO_MORE_DOCS;
+					}
+					word = arr[i];
+					wordShift = -1; // loop invariant code motion should move this
+				}
+
+				// after the first time, should I go with a linear search, or
+				// stick with the binary search in shift?
+				Shift();
+			}
+
+			int bitIndex = (indexArray & 0x0f) + wordShift;
+			indexArray = (int)((uint)indexArray >> 4);
+			// should i<<6 be cached as a separate variable?
+			// it would only save one cycle in the best circumstances.
+			return curDocId = (i << 6) + bitIndex;
+		}
+
+		public override int Advance(int target)
+		{
+			indexArray = 0;
+			i = target >> 6;
+			if (i >= words)
+			{
+				word = 0; // setup so next() will also return -1
+				return curDocId = NO_MORE_DOCS;
+			}
+			wordShift = target & 0x3f;
+			word = (long)((ulong)arr[i] >> wordShift);
+			if (word != 0)
+			{
+				wordShift--; // compensate for 1 based arrIndex
+			}
+			else
+			{
+				while (word == 0)
+				{
+					if (++i >= words)
+					{
+						return curDocId = NO_MORE_DOCS;
+					}
+					word = arr[i];
+				}
+				wordShift = -1;
+			}
+
+			Shift();
+
+			int bitIndex = (indexArray & 0x0f) + wordShift;
+			indexArray = (int)((uint)indexArray >> 4);
+			// should i<<6 be cached as a separate variable?
+			// it would only save one cycle in the best circumstances.
+			return curDocId = (i << 6) + bitIndex;
+		}
+
+		public override int DocID()
+		{
+			return curDocId;
+		}
+	}
+}
\ No newline at end of file

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Util/ShapeFieldCache.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Util/ShapeFieldCache.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Util/ShapeFieldCache.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Util/ShapeFieldCache.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,50 @@
+/*
+ * 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.Collections.Generic;
+using Spatial4n.Core.Shapes;
+
+namespace Lucene.Net.Spatial.Util
+{
+	public class ShapeFieldCache<T> where T : Shape
+	{
+		private readonly IList<T>[] cache;
+		public int defaultLength;
+
+		public ShapeFieldCache(int length, int defaultLength)
+		{
+			cache = new IList<T>[length];
+			this.defaultLength = defaultLength;
+		}
+
+		public void Add(int docid, T s)
+		{
+			IList<T> list = cache[docid];
+			if (list == null)
+			{
+				list = cache[docid] = new List<T>(defaultLength);
+			}
+			list.Add(s);
+		}
+
+		public IList<T> GetShapes(int docid)
+		{
+			return cache[docid];
+		}
+
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Util/ShapeFieldCacheProvider.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Util/ShapeFieldCacheProvider.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Util/ShapeFieldCacheProvider.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Util/ShapeFieldCacheProvider.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,89 @@
+/*
+ * 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.Runtime.CompilerServices;
+using Lucene.Net.Index;
+using Spatial4n.Core.Shapes;
+
+namespace Lucene.Net.Spatial.Util
+{
+	public abstract class ShapeFieldCacheProvider<T> where T : Shape
+	{
+		//private Logger log = Logger.getLogger(getClass().getName());
+
+		// it may be a List<T> or T
+		private readonly ConditionalWeakTable<IndexReader, ShapeFieldCache<T>> sidx =
+			new ConditionalWeakTable<IndexReader, ShapeFieldCache<T>>(); // WeakHashMap
+
+		protected readonly int defaultSize;
+		protected readonly String shapeField;
+
+		protected ShapeFieldCacheProvider(String shapeField, int defaultSize)
+		{
+			this.shapeField = shapeField;
+			this.defaultSize = defaultSize;
+		}
+
+		protected abstract T ReadShape(/*BytesRef*/ Term term);
+
+		private readonly object locker = new object();
+
+		public ShapeFieldCache<T> GetCache(IndexReader reader)
+		{
+			lock (locker)
+			{
+				ShapeFieldCache<T> idx;
+				if (sidx.TryGetValue(reader, out idx) && idx != null)
+				{
+					return idx;
+				}
+
+				//long startTime = System.CurrentTimeMillis();
+				//log.fine("Building Cache [" + reader.MaxDoc() + "]");
+
+				idx = new ShapeFieldCache<T>(reader.MaxDoc, defaultSize);
+				var count = 0;
+				var tec = new TermsEnumCompatibility(reader, shapeField);
+
+				var term = tec.Next();
+				while (term != null)
+				{
+					var shape = ReadShape(term);
+					if (shape != null)
+					{
+						var docs = reader.TermDocs(new Term(shapeField, tec.Term().Text));
+						while (docs.Next())
+						{
+							idx.Add(docs.Doc, shape);
+							docs.Next();
+							count++;
+						}
+					}
+					term = tec.Next();
+				}
+
+				sidx.Add(reader, idx);
+				tec.Close();
+
+				//long elapsed = System.CurrentTimeMillis() - startTime;
+				//log.fine("Cached: [" + count + " in " + elapsed + "ms] " + idx);
+				return idx;
+			}
+		}
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Util/StringListTokenizer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Util/StringListTokenizer.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Util/StringListTokenizer.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Util/StringListTokenizer.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,68 @@
+/*
+ * 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 Lucene.Net.Analysis;
+using Lucene.Net.Analysis.Tokenattributes;
+
+namespace Lucene.Net.Spatial.Util
+{
+	/// <summary>
+	/// Put a list of strings directly into the token stream
+	/// </summary>
+	public class StringListTokenizer : TokenStream
+	{
+		private TermAttribute termAtt;
+
+		private readonly IEnumerable<String> tokens;
+		private IEnumerator<String> iter = null;
+
+		public StringListTokenizer(IEnumerable<String> tokens)
+		{
+			this.tokens = tokens;
+			Init();
+		}
+
+		private void Init()
+		{
+			termAtt = AddAttribute<TermAttribute>();
+		}
+
+		public override bool IncrementToken()
+		{
+			if (iter.MoveNext())
+			{
+				ClearAttributes();
+				var t = iter.Current;
+				termAtt.Append(t);
+				return true;
+			}
+			return false;
+		}
+
+		public override void Reset()
+		{
+			base.Reset();
+			iter = tokens.GetEnumerator();
+		}
+
+		protected override void Dispose(bool disposing)
+		{
+		}
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Util/TermsEnumCompatibility.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Util/TermsEnumCompatibility.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Util/TermsEnumCompatibility.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Util/TermsEnumCompatibility.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,110 @@
+using System;
+using System.Collections.Generic;
+using Lucene.Net.Index;
+using Lucene.Net.Util;
+
+namespace Lucene.Net.Spatial.Util
+{
+	/// <summary>
+	/// Wraps Lucene 3 TermEnum to make it look like a Lucene 4 TermsEnum
+	/// SOLR-2155
+	/// @author dsmiley
+	/// </summary>
+	public class TermsEnumCompatibility
+	{
+		private readonly IndexReader reader;
+		private readonly String fieldName;
+		private TermEnum termEnum;
+		private bool initialState = true;
+
+		public TermsEnumCompatibility(IndexReader reader, String fieldName)
+		{
+			this.reader = reader;
+			this.fieldName = string.Intern(fieldName);
+			this.termEnum = reader.Terms(new Term(this.fieldName));
+		}
+
+		public TermEnum GetTermEnum()
+		{
+			return termEnum;
+		}
+
+		public Term Term()
+		{
+			Term t = termEnum.Term();
+			return t != null && t.Field == fieldName ? t : null;
+		}
+
+		public Term Next()
+		{
+			//in Lucene 3, a call to reader.terms(term) is already pre-positioned, you don't call next first
+			if (initialState)
+			{
+				initialState = false;
+				return Term();
+			}
+			else
+			{
+				return termEnum.Next() ? Term() : null;
+			}
+		}
+
+		public void Close()
+		{
+			termEnum.Close();
+		}
+
+		public enum SeekStatus
+		{
+			END,
+			FOUND,
+			NOT_FOUND
+		}
+
+		public SeekStatus Seek(String value)
+		{
+			termEnum = reader.Terms(new Term(this.fieldName, value));
+			Term t = Term();
+			if (t == null)
+				return SeekStatus.END;
+			return (t.Text.Equals(value)) ? SeekStatus.FOUND : SeekStatus.NOT_FOUND;
+		}
+
+		/// <summary>
+		/// Seeks to the specified term, if it exists, or to the
+		/// next (ceiling) term.  Returns SeekStatus to
+		/// indicate whether exact term was found, a different
+		/// term was found, or EOF was hit.  The target term may
+		/// be before or after the current term.  If this returns
+		/// SeekStatus.END, the enum is unpositioned.
+		/// </summary>
+		/// <param name="value"></param>
+		/// <returns></returns>
+		public SeekStatus SeekCeil(String value)
+		{
+			return Seek(value);
+		}
+
+		/// <summary>
+		/// Returns the number of documents that have at least one
+		/// term for this field, or -1 if this measure isn't
+		/// stored by the codec.  Note that, just like other term
+		/// measures, this measure does not take deleted documents
+		/// into account.
+		/// </summary>
+		/// <returns></returns>
+		public int GetDocCount()
+		{
+			return -1; // TODO find a way to efficiently determine this
+		}
+
+		public void Docs(OpenBitSet bits)
+		{
+			var termDocs = reader.TermDocs(new Term(fieldName, Term().Text));
+			while (termDocs.Next())
+			{
+				bits.FastSet(termDocs.Doc);
+			}
+		}
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Util/TruncateFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Util/TruncateFilter.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Util/TruncateFilter.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Util/TruncateFilter.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,52 @@
+/*
+ * 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 Lucene.Net.Analysis;
+using Lucene.Net.Analysis.Tokenattributes;
+
+namespace Lucene.Net.Spatial.Util
+{
+	public class TruncateFilter : TokenFilter
+	{
+		private readonly int maxTokenLength;
+
+		// TODO using TermAttribute for now since CharTermAttribute is not available
+		// TODO in 3.1+ https://issues.apache.org/jira/browse/LUCENE-2302
+		private readonly TermAttribute termAttr;
+
+		public TruncateFilter(TokenStream input, int maxTokenLength)
+			: base(input)
+		{
+			termAttr = AddAttribute<TermAttribute>();
+			this.maxTokenLength = maxTokenLength;
+		}
+
+		public override bool IncrementToken()
+		{
+			if (!input.IncrementToken())
+			{
+				return false;
+			}
+
+			if (termAttr.TermLength() > maxTokenLength)
+			{
+				termAttr.SetTermLength(maxTokenLength);
+			}
+			return true;
+		}
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Util/ValueSourceFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Util/ValueSourceFilter.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Util/ValueSourceFilter.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Util/ValueSourceFilter.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,68 @@
+/*
+ * 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 Lucene.Net.Search;
+using Lucene.Net.Search.Function;
+
+namespace Lucene.Net.Spatial.Util
+{
+	public class ValueSourceFilter : Filter
+	{
+		public class ValueSourceFilteredDocIdSet : FilteredDocIdSet
+		{
+			private readonly ValueSourceFilter enclosingFilter;
+			private readonly DocValues values;
+
+			public ValueSourceFilteredDocIdSet(DocIdSet innerSet, DocValues values, ValueSourceFilter caller) : base(innerSet)
+			{
+				this.enclosingFilter = caller;
+				this.values = values;
+			}
+
+			public override bool Match(int docid)
+			{
+				double val = values.DoubleVal(docid);
+				return val > enclosingFilter.min && val < enclosingFilter.max;
+			}
+		}
+
+		readonly Filter startingFilter;
+		readonly ValueSource source;
+
+		public readonly double min;
+		public readonly double max;
+
+		public ValueSourceFilter(Filter startingFilter, ValueSource source, double min, double max)
+		{
+			if (startingFilter == null)
+			{
+				throw new ArgumentException("please provide a non-null startingFilter; you can use QueryWrapperFilter(MatchAllDocsQuery) as a no-op filter", "startingFilter");
+			}
+			this.startingFilter = startingFilter;
+			this.source = source;
+			this.min = min;
+			this.max = max;
+		}
+
+		public override DocIdSet GetDocIdSet(Index.IndexReader reader)
+		{
+			var values = source.GetValues(reader);
+			return new ValueSourceFilteredDocIdSet(startingFilter.GetDocIdSet(reader), values, this);
+		}
+	}
+}

Added: 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=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Vector/DistanceValueSource.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Vector/DistanceValueSource.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,117 @@
+/*
+ * 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 Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.Search.Function;
+using Lucene.Net.Spatial.Util;
+using Spatial4n.Core.Distance;
+using Spatial4n.Core.Shapes;
+using Spatial4n.Core.Shapes.Impl;
+
+namespace Lucene.Net.Spatial.Vector
+{
+	/// <summary>
+	/// An implementation of the Lucene ValueSource model to support spatial relevance ranking.
+	/// </summary>
+	public class DistanceValueSource : ValueSource
+	{
+		private readonly TwoDoublesFieldInfo fields;
+		private readonly DistanceCalculator calculator;
+		private readonly Point from;
+		private readonly DoubleParser parser;
+
+		public DistanceValueSource(Point from, DistanceCalculator calc, TwoDoublesFieldInfo fields, DoubleParser parser)
+		{
+			this.from = from;
+			this.fields = fields;
+			this.calculator = calc;
+			this.parser = parser;
+		}
+
+		public class DistanceDocValues : DocValues
+		{
+			private readonly DistanceValueSource enclosingInstance;
+
+			private readonly double[] ptX, ptY;
+			private readonly Bits validX, validY;
+
+			public DistanceDocValues(DistanceValueSource enclosingInstance, IndexReader reader)
+			{
+				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());
+			}
+
+			public override float FloatVal(int doc)
+			{
+				return (float)DoubleVal(doc);
+			}
+
+			public override double DoubleVal(int doc)
+			{
+				// make sure it has minX and area
+				if (validX.Get(doc) && validY.Get(doc))
+				{
+					var pt = new PointImpl(ptX[doc], ptY[doc]);
+					return enclosingInstance.calculator.Distance(enclosingInstance.from, pt);
+				}
+				return 0;
+			}
+
+			public override string ToString(int doc)
+			{
+				return enclosingInstance.Description() + "=" + FloatVal(doc);
+			}
+		}
+
+		public override DocValues GetValues(IndexReader reader)
+		{
+			return new DistanceDocValues(this, reader);
+		}
+
+		public override string Description()
+		{
+			return "DistanceValueSource(" + calculator + ")";
+		}
+
+		public override bool Equals(object o)
+		{
+			if (this == o) return true;
+
+			var that = o as DistanceValueSource;
+			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 (from != null ? !from.Equals(that.from) : that.from != null) return false;
+
+			return true;
+		}
+
+		public override int GetHashCode()
+		{
+			int result = fields != null ? fields.GetHashCode() : 0;
+			result = 31 * result + (calculator != null ? calculator.GetHashCode() : 0);
+			result = 31 * result + (from != null ? from.GetHashCode() : 0);
+			return result;
+		}
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Spatial/Vector/TwoDoublesFieldInfo.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Vector/TwoDoublesFieldInfo.cs?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Vector/TwoDoublesFieldInfo.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Vector/TwoDoublesFieldInfo.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,54 @@
+/*
+ * 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.Vector
+{
+	public class TwoDoublesFieldInfo : SpatialFieldInfo
+	{
+		public static String SUFFIX_X = "__x";
+		public static String SUFFIX_Y = "__y";
+
+		private readonly String fieldName;
+		private readonly String fieldNameX;
+		private readonly String fieldNameY;
+
+		public TwoDoublesFieldInfo(String fieldNamePrefix)
+		{
+			fieldName = fieldNamePrefix;
+			fieldNameX = fieldNamePrefix + SUFFIX_X;
+			fieldNameY = fieldNamePrefix + SUFFIX_Y;
+		}
+
+		public String GetFieldName()
+		{
+			return fieldName;
+		}
+
+		public String GetFieldNameX()
+		{
+			return fieldNameX;
+		}
+
+		public String GetFieldNameY()
+		{
+			return fieldNameY;
+		}
+
+	}
+}

Added: 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=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Vector/TwoDoublesStrategy.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Vector/TwoDoublesStrategy.cs Wed May 30 10:17:16 2012
@@ -0,0 +1,232 @@
+/*
+ * 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 Lucene.Net.Documents;
+using Lucene.Net.Search;
+using Lucene.Net.Search.Function;
+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
+{
+	public class TwoDoublesStrategy : SpatialStrategy<TwoDoublesFieldInfo>
+	{
+		private readonly NumericFieldInfo finfo;
+		private readonly DoubleParser parser;
+
+		public TwoDoublesStrategy(SpatialContext ctx, NumericFieldInfo finfo, DoubleParser parser)
+			: base(ctx)
+		{
+			this.finfo = finfo;
+			this.parser = parser;
+		}
+
+		public override bool IsPolyField()
+		{
+			return true;
+		}
+
+		public override AbstractField[] CreateFields(TwoDoublesFieldInfo fieldInfo, Shape shape, bool index, bool store)
+		{
+			var point = shape as Point;
+			if (point != null)
+			{
+				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());
+				}
+				if (store)
+				{
+					f[f.Length - 1] = new Field(fieldInfo.GetFieldName(), ctx.ToString(shape), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
+				}
+				return f;
+			}
+			if (!ignoreIncompatibleGeometry)
+			{
+				throw new ArgumentException("TwoDoublesStrategy can not index: " + shape);
+			}
+			return new AbstractField[0]; // nothing (solr does not support null) 
+		}
+
+		public override Field CreateField(TwoDoublesFieldInfo fieldInfo, Shape shape, bool index, bool store)
+		{
+			throw new InvalidOperationException("Point is poly field");
+		}
+
+		public override ValueSource MakeValueSource(SpatialArgs args, TwoDoublesFieldInfo fieldInfo)
+		{
+			Point p = args.GetShape().GetCenter();
+			return new DistanceValueSource(p, ctx.GetDistCalc(), fieldInfo, parser);
+		}
+
+		public override Query MakeQuery(SpatialArgs args, TwoDoublesFieldInfo fieldInfo)
+		{
+			// For starters, just limit the bbox
+			var shape = args.GetShape();
+			var bbox = shape as Rectangle;
+			if (bbox == null)
+			{
+				throw new InvalidShapeException("A rectangle is the only supported shape (so far), not " + shape.GetType().Name);//TODO
+			}
+
+			if (bbox.GetCrossesDateLine())
+			{
+				throw new InvalidOperationException("Crossing dateline not yet supported");
+			}
+
+			ValueSource valueSource = null;
+
+			Query spatial = null;
+			SpatialOperation op = args.Operation;
+
+			if (SpatialOperation.Is(op,
+				SpatialOperation.BBoxWithin,
+				SpatialOperation.BBoxIntersects))
+			{
+				spatial = MakeWithin(bbox, fieldInfo);
+			}
+			else if (SpatialOperation.Is(op,
+			  SpatialOperation.Intersects,
+			  SpatialOperation.IsWithin))
+			{
+				spatial = MakeWithin(bbox, fieldInfo);
+				var circle = args.GetShape() as Circle;
+				if (circle != null)
+				{
+					// Make the ValueSource
+					valueSource = MakeValueSource(args, fieldInfo);
+
+					var vsf = new ValueSourceFilter(
+						new QueryWrapperFilter(spatial), valueSource, 0, circle.GetDistance());
+
+					spatial = new FilteredQuery(new MatchAllDocsQuery(), vsf);
+				}
+			}
+			else if (op == SpatialOperation.IsDisjointTo)
+			{
+				spatial = MakeDisjoint(bbox, fieldInfo);
+			}
+
+			if (spatial == null)
+			{
+				throw new UnsupportedSpatialOperation(args.Operation);
+			}
+
+			if (valueSource != null)
+			{
+				valueSource = new CachingDoubleValueSource(valueSource);
+			}
+			else
+			{
+				valueSource = MakeValueSource(args, fieldInfo);
+			}
+			Query spatialRankingQuery = new FunctionQuery(valueSource);
+			var bq = new BooleanQuery();
+			bq.Add(spatial, Occur.MUST);
+			bq.Add(spatialRankingQuery, Occur.MUST);
+			return bq;
+
+		}
+
+		public override Filter MakeFilter(SpatialArgs args, TwoDoublesFieldInfo fieldInfo)
+		{
+			var circle = args.GetShape() as Circle;
+			if (circle != null)
+			{
+				if (SpatialOperation.Is(args.Operation,
+					SpatialOperation.Intersects,
+					SpatialOperation.IsWithin))
+				{
+					Query bbox = MakeWithin(circle.GetBoundingBox(), fieldInfo);
+
+					// Make the ValueSource
+					ValueSource valueSource = MakeValueSource(args, fieldInfo);
+
+					return new ValueSourceFilter(
+						new QueryWrapperFilter(bbox), valueSource, 0, circle.GetDistance());
+				}
+			}
+			return new QueryWrapperFilter(MakeQuery(args, fieldInfo));
+
+		}
+
+		/// <summary>
+		/// Constructs a query to retrieve documents that fully contain the input envelope.
+		/// </summary>
+		/// <param name="bbox"></param>
+		/// <param name="fieldInfo"></param>
+		/// <returns>The spatial query</returns>
+		private Query MakeWithin(Rectangle bbox, TwoDoublesFieldInfo fieldInfo)
+		{
+			Query qX = NumericRangeQuery.NewDoubleRange(
+			  fieldInfo.GetFieldNameX(),
+			  finfo.precisionStep,
+			  bbox.GetMinX(),
+			  bbox.GetMaxX(),
+			  true,
+			  true);
+			Query qY = NumericRangeQuery.NewDoubleRange(
+			  fieldInfo.GetFieldNameY(),
+			  finfo.precisionStep,
+			  bbox.GetMinY(),
+			  bbox.GetMaxY(),
+			  true,
+			  true);
+
+			var bq = new BooleanQuery();
+			bq.Add(qX, Occur.MUST);
+			bq.Add(qY, Occur.MUST);
+			return bq;
+		}
+
+		/// <summary>
+		/// Constructs a query to retrieve documents that fully contain the input envelope.
+		/// </summary>
+		/// <param name="bbox"></param>
+		/// <param name="fieldInfo"></param>
+		/// <returns>The spatial query</returns>
+		Query MakeDisjoint(Rectangle bbox, TwoDoublesFieldInfo fieldInfo)
+		{
+			Query qX = NumericRangeQuery.NewDoubleRange(
+			  fieldInfo.GetFieldNameX(),
+			  finfo.precisionStep,
+			  bbox.GetMinX(),
+			  bbox.GetMaxX(),
+			  true,
+			  true);
+			Query qY = NumericRangeQuery.NewDoubleRange(
+			  fieldInfo.GetFieldNameY(),
+			  finfo.precisionStep,
+			  bbox.GetMinY(),
+			  bbox.GetMaxY(),
+			  true,
+			  true);
+
+			var bq = new BooleanQuery();
+			bq.Add(qX, Occur.MUST_NOT);
+			bq.Add(qY, Occur.MUST_NOT);
+			return bq;
+		}
+
+	}
+}

Modified: incubator/lucene.net/trunk/src/core/Lucene.Net.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Lucene.Net.csproj?rev=1344182&r1=1344181&r2=1344182&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Lucene.Net.csproj (original)
+++ incubator/lucene.net/trunk/src/core/Lucene.Net.csproj Wed May 30 10:17:16 2012
@@ -971,4 +971,4 @@
     <PostBuildEvent>
     </PostBuildEvent>
   </PropertyGroup>
-</Project>
\ No newline at end of file
+</Project>

Added: incubator/lucene.net/trunk/test-files/spatial/cities-IsWithin-BBox.txt
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test-files/spatial/cities-IsWithin-BBox.txt?rev=1344182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/test-files/spatial/cities-IsWithin-BBox.txt (added)
+++ incubator/lucene.net/trunk/test-files/spatial/cities-IsWithin-BBox.txt Wed May 30 10:17:16 2012
@@ -0,0 +1,7 @@
+[San Francisco] G5391959 @ IsWithin(-122.524918 37.674973 -122.360123 37.817108)
+[Wellington] G2179537 @ IsWithin(174.711456 -41.360779 174.854279 -41.213837)
+[Barcelona] G6544100 G3128760  @  IsWithin(2.127228 41.333313 2.226105 41.408844)
+
+
+
+



Mime
View raw message