Author: synhershko
Date: Mon Aug 20 21:40:03 2012
New Revision: 1375236
URL: http://svn.apache.org/viewvc?rev=1375236&view=rev
Log:
Catching up the spatial module (core, not tests yet)
LUCENE-4166, LUCENE-4157. Still need to port TermsFilter.
Modified:
incubator/lucene.net/trunk/build/vs2010/contrib/Contrib.Spatial.sln
incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/RecursivePrefixTreeStrategy.cs
incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/TermQueryPrefixTreeStrategy.cs
incubator/lucene.net/trunk/src/contrib/Spatial/SpatialStrategy.cs
incubator/lucene.net/trunk/src/contrib/Spatial/Vector/TwoDoublesStrategy.cs
Modified: incubator/lucene.net/trunk/build/vs2010/contrib/Contrib.Spatial.sln
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/build/vs2010/contrib/Contrib.Spatial.sln?rev=1375236&r1=1375235&r2=1375236&view=diff
==============================================================================
--- incubator/lucene.net/trunk/build/vs2010/contrib/Contrib.Spatial.sln (original)
+++ incubator/lucene.net/trunk/build/vs2010/contrib/Contrib.Spatial.sln Mon Aug 20 21:40:03 2012
@@ -1,34 +1,34 @@

-Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual C# Express 2010
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net", "..\..\..\src\core\Lucene.Net.csproj", "{5D4AD9BE-1FFB-41AB-9943-25737971BF57}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contrib.Spatial", "..\..\..\src\contrib\Spatial\Contrib.Spatial.csproj", "{35C347F4-24B2-4BE5-8117-A0E3001551CE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug35|Any CPU = Debug35|Any CPU
Debug|Any CPU = Debug|Any CPU
- Release35|Any CPU = Release35|Any CPU
+ Debug35|Any CPU = Debug35|Any CPU
Release|Any CPU = Release|Any CPU
+ Release35|Any CPU = Release35|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Debug35|Any CPU.ActiveCfg = Debug35|Any CPU
- {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Debug35|Any CPU.Build.0 = Debug35|Any CPU
- {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Release35|Any CPU.ActiveCfg = Release35|Any CPU
- {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Release35|Any CPU.Build.0 = Release35|Any CPU
- {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Release|Any CPU.Build.0 = Release|Any CPU
- {5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Debug35|Any CPU.ActiveCfg = Debug35|Any CPU
- {5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Debug35|Any CPU.Build.0 = Debug35|Any CPU
{5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Release35|Any CPU.ActiveCfg = Release35|Any CPU
- {5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Release35|Any CPU.Build.0 = Release35|Any CPU
+ {5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Debug35|Any CPU.ActiveCfg = Debug35|Any CPU
+ {5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Debug35|Any CPU.Build.0 = Debug35|Any CPU
{5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Release35|Any CPU.ActiveCfg = Release35|Any CPU
+ {5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Release35|Any CPU.Build.0 = Release35|Any CPU
+ {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Debug35|Any CPU.ActiveCfg = Debug35|Any CPU
+ {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Debug35|Any CPU.Build.0 = Debug35|Any CPU
+ {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Release|Any CPU.Build.0 = Release|Any CPU
+ {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Release35|Any CPU.ActiveCfg = Release35|Any CPU
+ {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Release35|Any CPU.Build.0 = Release35|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Modified: incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/RecursivePrefixTreeStrategy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/RecursivePrefixTreeStrategy.cs?rev=1375236&r1=1375235&r2=1375236&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/RecursivePrefixTreeStrategy.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/RecursivePrefixTreeStrategy.cs Mon Aug 20 21:40:03 2012
@@ -25,6 +25,9 @@ using Spatial4n.Core.Shapes;
namespace Lucene.Net.Spatial.Prefix
{
+ ///
+ /// Based on {@link RecursivePrefixTreeFilter}.
+ ///
public class RecursivePrefixTreeStrategy : PrefixTreeStrategy
{
private int prefixGridScanLevel;//TODO how is this customized?
@@ -40,25 +43,17 @@ namespace Lucene.Net.Spatial.Prefix
this.prefixGridScanLevel = prefixGridScanLevel;
}
- public override Query MakeQuery(SpatialArgs args, SimpleSpatialFieldInfo fieldInfo)
- {
- Filter f = MakeFilter(args, fieldInfo);
-
- ValueSource vs = MakeValueSource(args, fieldInfo);
- return new FilteredQuery(new FunctionQuery(vs), f);
- }
-
public override Filter MakeFilter(SpatialArgs args, SimpleSpatialFieldInfo fieldInfo)
{
var op = args.Operation;
- if (!SpatialOperation.Is(op, SpatialOperation.IsWithin, SpatialOperation.Intersects, SpatialOperation.BBoxWithin))
+ if (!SpatialOperation.Is(op, SpatialOperation.IsWithin, SpatialOperation.Intersects, SpatialOperation.BBoxWithin, SpatialOperation.BBoxIntersects))
throw new UnsupportedSpatialOperation(op);
- Shape qshape = args.GetShape();
+ Shape shape = args.GetShape();
- int detailLevel = grid.GetMaxLevelForPrecision(qshape, args.GetDistPrecision());
+ int detailLevel = grid.GetMaxLevelForPrecision(shape, args.GetDistPrecision());
- return new RecursivePrefixTreeFilter(fieldInfo.GetFieldName(), grid, qshape, prefixGridScanLevel, detailLevel);
+ return new RecursivePrefixTreeFilter(fieldInfo.GetFieldName(), grid, shape, prefixGridScanLevel, detailLevel);
}
public override string ToString()
Modified: incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/TermQueryPrefixTreeStrategy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/TermQueryPrefixTreeStrategy.cs?rev=1375236&r1=1375235&r2=1375236&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/TermQueryPrefixTreeStrategy.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Spatial/Prefix/TermQueryPrefixTreeStrategy.cs Mon Aug 20 21:40:03 2012
@@ -20,9 +20,14 @@ using Lucene.Net.Search;
using Lucene.Net.Spatial.Prefix.Tree;
using Spatial4n.Core.Exceptions;
using Spatial4n.Core.Query;
+using Spatial4n.Core.Shapes;
namespace Lucene.Net.Spatial.Prefix
{
+ ///
+ /// A basic implementation using a large {@link TermsFilter} of all the nodes from
+ /// {@link SpatialPrefixTree#getNodes(com.spatial4j.core.shape.Shape, int, boolean)}.
+ ///
public class TermQueryPrefixTreeStrategy : PrefixTreeStrategy
{
public TermQueryPrefixTreeStrategy(SpatialPrefixTree grid)
@@ -30,30 +35,23 @@ namespace Lucene.Net.Spatial.Prefix
{
}
- public override Query MakeQuery(SpatialArgs args, SimpleSpatialFieldInfo fieldInfo)
+ public override Filter MakeFilter(SpatialArgs args, SimpleSpatialFieldInfo fieldInfo)
{
- if (args.Operation != SpatialOperation.Intersects &&
- args.Operation != SpatialOperation.IsWithin &&
- args.Operation != SpatialOperation.Overlaps)
- {
- // TODO -- can translate these other query types
- throw new UnsupportedSpatialOperation(args.Operation);
- }
- var qshape = args.GetShape();
- int detailLevel = grid.GetMaxLevelForPrecision(qshape, args.GetDistPrecision());
- var cells = grid.GetNodes(qshape, detailLevel, false);
+ SpatialOperation op = args.Operation;
+ if (
+ !SpatialOperation.Is(op, SpatialOperation.IsWithin, SpatialOperation.Intersects, SpatialOperation.BBoxWithin,
+ SpatialOperation.BBoxIntersects))
+ throw new UnsupportedSpatialOperation(op);
- var booleanQuery = new BooleanQuery();
- foreach (var cell in cells)
+ Shape shape = args.GetShape();
+ int detailLevel = grid.GetMaxLevelForPrecision(shape, args.GetDistPrecision());
+ var cells = grid.GetNodes(shape, detailLevel, false);
+ var filter = new TermsFilter();
+ foreach (Node cell in cells)
{
- booleanQuery.Add(new TermQuery(new Term(fieldInfo.GetFieldName(), cell.GetTokenString())), Occur.SHOULD);
+ filter.AddTerm(new Term(fieldInfo.GetFieldName(), cell.GetTokenString()));
}
- return booleanQuery;
- }
-
- public override Filter MakeFilter(SpatialArgs args, SimpleSpatialFieldInfo fieldInfo)
- {
- return new QueryWrapperFilter(MakeQuery(args, fieldInfo));
+ return filter;
}
}
}
Modified: incubator/lucene.net/trunk/src/contrib/Spatial/SpatialStrategy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Spatial/SpatialStrategy.cs?rev=1375236&r1=1375235&r2=1375236&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:40:03 2012
@@ -18,6 +18,7 @@
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.Query;
using Spatial4n.Core.Shapes;
@@ -61,15 +62,29 @@ namespace Lucene.Net.Spatial
return new AbstractField[] { CreateField(fieldInfo, shape, index, store) };
}
+ ///
+ /// The value source yields a number that is proportional to the distance between the query shape and indexed data.
+ ///
+ ///
+ ///
+ ///
public abstract ValueSource MakeValueSource(SpatialArgs args, T fieldInfo);
///
- /// Make a query
+ /// Make a query which has a score based on the distance from the data to the query shape.
+ /// The default implementation constructs a {@link FilteredQuery} based on
+ /// {@link #makeFilter(com.spatial4j.core.query.SpatialArgs, SpatialFieldInfo)} and
+ /// {@link #makeValueSource(com.spatial4j.core.query.SpatialArgs, SpatialFieldInfo)}.
///
///
///
///
- public abstract Query MakeQuery(SpatialArgs args, T fieldInfo);
+ public virtual Query MakeQuery(SpatialArgs args, T fieldInfo)
+ {
+ Filter filter = MakeFilter(args, fieldInfo);
+ ValueSource vs = MakeValueSource(args, fieldInfo);
+ return new FilteredQuery(new FunctionQuery(vs), filter);
+ }
///
/// Make a Filter
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=1375236&r1=1375235&r2=1375236&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:40:03 2012
@@ -83,12 +83,11 @@ namespace Lucene.Net.Spatial.Vector
{
// 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 (!(shape is Rectangle || shape is Circle))
+ throw new InvalidShapeException("Only Rectangles and Circles are currently supported, found ["
+ + shape.GetType().Name + "]");//TODO
+ Rectangle bbox = shape.GetBoundingBox();
if (bbox.GetCrossesDateLine())
{
throw new InvalidOperationException("Crossing dateline not yet supported");