You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2016/11/25 11:07:11 UTC
[06/26] lucenenet git commit: Changed namespace Lucene.Net.Query ->
Lucene.Net.Queries to avoid naming conflicts with the Query class.
Changed namespace Lucene.Net.Query -> Lucene.Net.Queries to avoid naming conflicts with the Query class.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/415cd5c0
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/415cd5c0
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/415cd5c0
Branch: refs/heads/master
Commit: 415cd5c07e45356ed85c31c86dac5c787505cdf2
Parents: d554792
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Wed Nov 16 00:18:01 2016 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Wed Nov 16 00:18:01 2016 +0700
----------------------------------------------------------------------
src/Lucene.Net.Spatial/DisjointSpatialFilter.cs | 2 +-
.../Prefix/ContainsPrefixTreeFilter.cs | 2 +-
.../Prefix/PrefixTreeStrategy.cs | 2 +-
.../Prefix/RecursivePrefixTreeStrategy.cs | 4 +-
.../Prefix/TermQueryPrefixTreeStrategy.cs | 4 +-
.../Prefix/Tree/SpatialPrefixTreeFactory.cs | 4 +-
.../Prefix/WithinPrefixTreeFilter.cs | 2 +-
src/Lucene.Net.Spatial/Query/SpatialArgs.cs | 2 +-
.../Query/SpatialArgsParser.cs | 2 +-
.../Query/SpatialOperation.cs | 140 ++++++++++++++++---
.../Query/UnsupportedSpatialOperation.cs | 2 +-
.../Serialized/SerializedDVStrategy.cs | 2 +-
src/Lucene.Net.Spatial/SpatialStrategy.cs | 2 +-
.../Vector/PointVectorStrategy.cs | 2 +-
14 files changed, 139 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/415cd5c0/src/Lucene.Net.Spatial/DisjointSpatialFilter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Spatial/DisjointSpatialFilter.cs b/src/Lucene.Net.Spatial/DisjointSpatialFilter.cs
index 3ad309e..e36a97b 100644
--- a/src/Lucene.Net.Spatial/DisjointSpatialFilter.cs
+++ b/src/Lucene.Net.Spatial/DisjointSpatialFilter.cs
@@ -18,7 +18,7 @@ using System;
using Lucene.Net.Index;
using Lucene.Net.Queries;
using Lucene.Net.Search;
-using Lucene.Net.Spatial.Query;
+using Lucene.Net.Spatial.Queries;
using Lucene.Net.Util;
namespace Lucene.Net.Spatial
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/415cd5c0/src/Lucene.Net.Spatial/Prefix/ContainsPrefixTreeFilter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Spatial/Prefix/ContainsPrefixTreeFilter.cs b/src/Lucene.Net.Spatial/Prefix/ContainsPrefixTreeFilter.cs
index 017b518..76a95b8 100644
--- a/src/Lucene.Net.Spatial/Prefix/ContainsPrefixTreeFilter.cs
+++ b/src/Lucene.Net.Spatial/Prefix/ContainsPrefixTreeFilter.cs
@@ -22,7 +22,7 @@ using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Spatial.Prefix;
using Lucene.Net.Spatial.Prefix.Tree;
-using Lucene.Net.Spatial.Query;
+using Lucene.Net.Spatial.Queries;
using Lucene.Net.Util;
namespace Lucene.Net.Spatial.Prefix
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/415cd5c0/src/Lucene.Net.Spatial/Prefix/PrefixTreeStrategy.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Spatial/Prefix/PrefixTreeStrategy.cs b/src/Lucene.Net.Spatial/Prefix/PrefixTreeStrategy.cs
index 003b428..4a21ebc 100644
--- a/src/Lucene.Net.Spatial/Prefix/PrefixTreeStrategy.cs
+++ b/src/Lucene.Net.Spatial/Prefix/PrefixTreeStrategy.cs
@@ -27,7 +27,7 @@ using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.Spatial.Prefix.Tree;
using Lucene.Net.Queries.Function;
-using Lucene.Net.Spatial.Query;
+using Lucene.Net.Spatial.Queries;
using Lucene.Net.Spatial.Util;
using Lucene.Net.Support;
using Spatial4n.Core.Shapes;
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/415cd5c0/src/Lucene.Net.Spatial/Prefix/RecursivePrefixTreeStrategy.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Spatial/Prefix/RecursivePrefixTreeStrategy.cs b/src/Lucene.Net.Spatial/Prefix/RecursivePrefixTreeStrategy.cs
index 8740476..37b4d41 100644
--- a/src/Lucene.Net.Spatial/Prefix/RecursivePrefixTreeStrategy.cs
+++ b/src/Lucene.Net.Spatial/Prefix/RecursivePrefixTreeStrategy.cs
@@ -18,7 +18,7 @@
using Lucene.Net.Queries.Function;
using Lucene.Net.Search;
using Lucene.Net.Spatial.Prefix.Tree;
-using Lucene.Net.Spatial.Query;
+using Lucene.Net.Spatial.Queries;
using Spatial4n.Core.Shapes;
namespace Lucene.Net.Spatial.Prefix
@@ -78,7 +78,7 @@ namespace Lucene.Net.Spatial.Prefix
{
return new DisjointSpatialFilter(this, args, FieldName);
}
- Shape shape = args.Shape;
+ IShape shape = args.Shape;
int detailLevel = grid.GetLevelForDistance(args.ResolveDistErr(ctx, distErrPct));
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/415cd5c0/src/Lucene.Net.Spatial/Prefix/TermQueryPrefixTreeStrategy.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Spatial/Prefix/TermQueryPrefixTreeStrategy.cs b/src/Lucene.Net.Spatial/Prefix/TermQueryPrefixTreeStrategy.cs
index aa67eeb..d4b5d25 100644
--- a/src/Lucene.Net.Spatial/Prefix/TermQueryPrefixTreeStrategy.cs
+++ b/src/Lucene.Net.Spatial/Prefix/TermQueryPrefixTreeStrategy.cs
@@ -18,7 +18,7 @@ using System.Collections.Generic;
using Lucene.Net.Queries;
using Lucene.Net.Search;
using Lucene.Net.Spatial.Prefix.Tree;
-using Lucene.Net.Spatial.Query;
+using Lucene.Net.Spatial.Queries;
using Lucene.Net.Util;
using Spatial4n.Core.Shapes;
@@ -56,7 +56,7 @@ namespace Lucene.Net.Spatial.Prefix
{
throw new UnsupportedSpatialOperation(op);
}
- Shape shape = args.Shape;
+ IShape shape = args.Shape;
int detailLevel = grid.GetLevelForDistance(args.ResolveDistErr(ctx, distErrPct));
IList<Cell> cells = grid.GetCells(shape, detailLevel, false, true);
//no parents
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/415cd5c0/src/Lucene.Net.Spatial/Prefix/Tree/SpatialPrefixTreeFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Spatial/Prefix/Tree/SpatialPrefixTreeFactory.cs b/src/Lucene.Net.Spatial/Prefix/Tree/SpatialPrefixTreeFactory.cs
index 1702e29..a1c7011 100644
--- a/src/Lucene.Net.Spatial/Prefix/Tree/SpatialPrefixTreeFactory.cs
+++ b/src/Lucene.Net.Spatial/Prefix/Tree/SpatialPrefixTreeFactory.cs
@@ -57,7 +57,7 @@ namespace Lucene.Net.Spatial.Prefix.Tree
string cname = args[PrefixTree];
if (cname == null)
{
- cname = ctx.IsGeo() ? "geohash" : "quad";
+ cname = ctx.IsGeo ? "geohash" : "quad";
}
if ("geohash".Equals(cname, StringComparison.OrdinalIgnoreCase))
{
@@ -106,7 +106,7 @@ namespace Lucene.Net.Spatial.Prefix.Tree
string maxDetailDistStr = args[MaxDistErr];
if (maxDetailDistStr == null)
{
- if (!ctx.IsGeo())
+ if (!ctx.IsGeo)
{
return;
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/415cd5c0/src/Lucene.Net.Spatial/Prefix/WithinPrefixTreeFilter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Spatial/Prefix/WithinPrefixTreeFilter.cs b/src/Lucene.Net.Spatial/Prefix/WithinPrefixTreeFilter.cs
index 3081bbe..11cfc46 100644
--- a/src/Lucene.Net.Spatial/Prefix/WithinPrefixTreeFilter.cs
+++ b/src/Lucene.Net.Spatial/Prefix/WithinPrefixTreeFilter.cs
@@ -20,7 +20,7 @@ using System.Diagnostics;
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Spatial.Prefix.Tree;
-using Lucene.Net.Spatial.Query;
+using Lucene.Net.Spatial.Queries;
using Lucene.Net.Util;
using Spatial4n.Core.Context;
using Spatial4n.Core.Distance;
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/415cd5c0/src/Lucene.Net.Spatial/Query/SpatialArgs.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Spatial/Query/SpatialArgs.cs b/src/Lucene.Net.Spatial/Query/SpatialArgs.cs
index 64e08aa..0ac68d2 100644
--- a/src/Lucene.Net.Spatial/Query/SpatialArgs.cs
+++ b/src/Lucene.Net.Spatial/Query/SpatialArgs.cs
@@ -19,7 +19,7 @@ using System;
using Spatial4n.Core.Context;
using Spatial4n.Core.Shapes;
-namespace Lucene.Net.Spatial.Query
+namespace Lucene.Net.Spatial.Queries
{
public class SpatialArgs
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/415cd5c0/src/Lucene.Net.Spatial/Query/SpatialArgsParser.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Spatial/Query/SpatialArgsParser.cs b/src/Lucene.Net.Spatial/Query/SpatialArgsParser.cs
index 6f0b433..8ffad19 100644
--- a/src/Lucene.Net.Spatial/Query/SpatialArgsParser.cs
+++ b/src/Lucene.Net.Spatial/Query/SpatialArgsParser.cs
@@ -21,7 +21,7 @@ using System.Text;
using Lucene.Net.Support;
using Spatial4n.Core.Context;
-namespace Lucene.Net.Spatial.Query
+namespace Lucene.Net.Spatial.Queries
{
public class SpatialArgsParser
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/415cd5c0/src/Lucene.Net.Spatial/Query/SpatialOperation.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Spatial/Query/SpatialOperation.cs b/src/Lucene.Net.Spatial/Query/SpatialOperation.cs
index 16c28a4..8d33ecf 100644
--- a/src/Lucene.Net.Spatial/Query/SpatialOperation.cs
+++ b/src/Lucene.Net.Spatial/Query/SpatialOperation.cs
@@ -13,17 +13,19 @@
* limitations under the License.
*/
+using Spatial4n.Core.Shapes;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
-namespace Lucene.Net.Spatial.Query
+namespace Lucene.Net.Spatial.Queries
{
- public class SpatialOperation
+ [Serializable]
+ public abstract class SpatialOperation
{
// Private registry
- private static readonly Dictionary<String, SpatialOperation> registry = new Dictionary<string, SpatialOperation>();
+ private static readonly Dictionary<string, SpatialOperation> registry = new Dictionary<string, SpatialOperation>();
private static readonly IList<SpatialOperation> list = new List<SpatialOperation>();
// Geometry Operations
@@ -31,27 +33,130 @@ namespace Lucene.Net.Spatial.Query
/// <summary>
/// Bounding box of the *indexed* shape.
/// </summary>
- public static readonly SpatialOperation BBoxIntersects = new SpatialOperation("BBoxIntersects", true, false, false);
+ public static readonly SpatialOperation BBoxIntersects = new BBoxIntersectsSpatialOperation();
+
+ private sealed class BBoxIntersectsSpatialOperation : SpatialOperation
+ {
+ internal BBoxIntersectsSpatialOperation()
+ : base("BBoxIntersects", true, false, false)
+ { }
+
+ public override bool Evaluate(IShape indexedShape, IShape queryShape)
+ {
+ return indexedShape.BoundingBox.Relate(queryShape).Intersects();
+ }
+ }
/// <summary>
/// Bounding box of the *indexed* shape.
/// </summary>
- public static readonly SpatialOperation BBoxWithin = new SpatialOperation("BBoxWithin", true, false, false);
+ public static readonly SpatialOperation BBoxWithin = new BBoxWithinSpatialOperation();
+
+ private sealed class BBoxWithinSpatialOperation : SpatialOperation
+ {
+ internal BBoxWithinSpatialOperation()
+ : base("BBoxWithin", true, false, false)
+ { }
+
+ public override bool Evaluate(IShape indexedShape, IShape queryShape)
+ {
+ IRectangle bbox = indexedShape.BoundingBox;
+ return bbox.Relate(queryShape) == SpatialRelation.WITHIN || bbox.Equals(queryShape);
+ }
+ }
+
+ public static readonly SpatialOperation Contains = new ContainsSpatialOperation();
+
+ private sealed class ContainsSpatialOperation : SpatialOperation
+ {
+ internal ContainsSpatialOperation()
+ : base("Contains", true, true, false)
+ { }
+
+ public override bool Evaluate(IShape indexedShape, IShape queryShape)
+ {
+ return indexedShape.HasArea && indexedShape.Relate(queryShape) == SpatialRelation.CONTAINS || indexedShape.Equals(queryShape);
+ }
+ }
+
+ public static readonly SpatialOperation Intersects = new IntersectsSpatialOperation();
+
+ private sealed class IntersectsSpatialOperation : SpatialOperation
+ {
+ internal IntersectsSpatialOperation()
+ : base("Intersects", true, false, false)
+ { }
+
+ public override bool Evaluate(IShape indexedShape, IShape queryShape)
+ {
+ return indexedShape.Relate(queryShape).Intersects();
+ }
+ }
+
+ public static readonly SpatialOperation IsEqualTo = new IsEqualToSpatialOperation();
+
+ private sealed class IsEqualToSpatialOperation : SpatialOperation
+ {
+ internal IsEqualToSpatialOperation()
+ : base("IsEqualTo", false, false, false)
+ { }
+
+ public override bool Evaluate(IShape indexedShape, IShape queryShape)
+ {
+ return indexedShape.Equals(queryShape);
+ }
+ }
+
+ public static readonly SpatialOperation IsDisjointTo = new IsDisjointToSpatialOperation();
+
+ private sealed class IsDisjointToSpatialOperation : SpatialOperation
+ {
+ internal IsDisjointToSpatialOperation()
+ : base("IsDisjointTo", false, false, false)
+ { }
+
+ public override bool Evaluate(IShape indexedShape, IShape queryShape)
+ {
+ return !indexedShape.Relate(queryShape).Intersects();
+ }
+ }
+
+ public static readonly SpatialOperation IsWithin = new IsWithinSpatialOperation();
+
+ private sealed class IsWithinSpatialOperation : SpatialOperation
+ {
+ internal IsWithinSpatialOperation()
+ : base("IsWithin", true, false, true)
+ { }
+
+ public override bool Evaluate(IShape indexedShape, IShape queryShape)
+ {
+ return queryShape.HasArea && (indexedShape.Relate(queryShape) == SpatialRelation.WITHIN || indexedShape.Equals(queryShape));
+ }
+ }
+
+ public static readonly SpatialOperation Overlaps = new OverlapsSpatialOperation();
+
+ private sealed class OverlapsSpatialOperation : SpatialOperation
+ {
+ internal OverlapsSpatialOperation()
+ : base("Overlaps", true, false, true)
+ { }
- public static readonly SpatialOperation Contains = new SpatialOperation("Contains", true, true, false);
- public static readonly SpatialOperation Intersects = new SpatialOperation("Intersects", true, false, false);
- public static readonly SpatialOperation IsEqualTo = new SpatialOperation("IsEqualTo", false, false, false);
- public static readonly SpatialOperation IsDisjointTo = new SpatialOperation("IsDisjointTo", false, false, false);
- public static readonly SpatialOperation IsWithin = new SpatialOperation("IsWithin", true, false, true);
- public static readonly SpatialOperation Overlaps = new SpatialOperation("Overlaps", true, false, true);
+ public override bool Evaluate(IShape indexedShape, IShape queryShape)
+ {
+ return queryShape.HasArea && indexedShape.Relate(queryShape).Intersects();
+ }
+ }
// Member variables
private readonly bool scoreIsMeaningful;
private readonly bool sourceNeedsArea;
private readonly bool targetNeedsArea;
- private readonly String name;
+ private readonly string name;
- protected SpatialOperation(String name, bool scoreIsMeaningful, bool sourceNeedsArea, bool targetNeedsArea)
+
+ protected SpatialOperation(string name, bool scoreIsMeaningful, bool sourceNeedsArea, bool targetNeedsArea)
{
this.name = name;
this.scoreIsMeaningful = scoreIsMeaningful;
@@ -62,7 +167,7 @@ namespace Lucene.Net.Spatial.Query
list.Add(this);
}
- public static SpatialOperation Get(String v)
+ public static SpatialOperation Get(string v)
{
SpatialOperation op;
if (!registry.TryGetValue(v, out op) || op == null)
@@ -83,6 +188,8 @@ namespace Lucene.Net.Spatial.Query
return tst.Any(t => op == t);
}
+ public abstract bool Evaluate(IShape indexedShape, IShape queryShape);
+
// ================================================= Getters / Setters =============================================
public bool IsScoreIsMeaningful()
@@ -100,15 +207,14 @@ namespace Lucene.Net.Spatial.Query
return targetNeedsArea;
}
- public String Name
+ public string Name
{
get { return name; }
}
- public override String ToString()
+ public override string ToString()
{
return name;
}
-
}
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/415cd5c0/src/Lucene.Net.Spatial/Query/UnsupportedSpatialOperation.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Spatial/Query/UnsupportedSpatialOperation.cs b/src/Lucene.Net.Spatial/Query/UnsupportedSpatialOperation.cs
index 92ae852..35949bc 100644
--- a/src/Lucene.Net.Spatial/Query/UnsupportedSpatialOperation.cs
+++ b/src/Lucene.Net.Spatial/Query/UnsupportedSpatialOperation.cs
@@ -17,7 +17,7 @@
using System;
-namespace Lucene.Net.Spatial.Query
+namespace Lucene.Net.Spatial.Queries
{
[Serializable]
public class UnsupportedSpatialOperation : InvalidOperationException
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/415cd5c0/src/Lucene.Net.Spatial/Serialized/SerializedDVStrategy.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Spatial/Serialized/SerializedDVStrategy.cs b/src/Lucene.Net.Spatial/Serialized/SerializedDVStrategy.cs
index c0692d6..92e4aaf 100644
--- a/src/Lucene.Net.Spatial/Serialized/SerializedDVStrategy.cs
+++ b/src/Lucene.Net.Spatial/Serialized/SerializedDVStrategy.cs
@@ -25,7 +25,7 @@ using Lucene.Net.Documents;
using Lucene.Net.Queries.Function;
using Lucene.Net.Search;
using Lucene.Net.Spatial;
-using Lucene.Net.Spatial.Query;
+using Lucene.Net.Spatial.Queries;
using Lucene.Net.Support;
using Lucene.Net.Util;
using Spatial4n.Core.Context;
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/415cd5c0/src/Lucene.Net.Spatial/SpatialStrategy.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Spatial/SpatialStrategy.cs b/src/Lucene.Net.Spatial/SpatialStrategy.cs
index f2de112..5f16c71 100644
--- a/src/Lucene.Net.Spatial/SpatialStrategy.cs
+++ b/src/Lucene.Net.Spatial/SpatialStrategy.cs
@@ -20,7 +20,7 @@ using Lucene.Net.Documents;
using Lucene.Net.Queries.Function;
using Lucene.Net.Queries.Function.ValueSources;
using Lucene.Net.Search;
-using Lucene.Net.Spatial.Query;
+using Lucene.Net.Spatial.Queries;
using Spatial4n.Core.Context;
using Spatial4n.Core.Shapes;
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/415cd5c0/src/Lucene.Net.Spatial/Vector/PointVectorStrategy.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Spatial/Vector/PointVectorStrategy.cs b/src/Lucene.Net.Spatial/Vector/PointVectorStrategy.cs
index 25672b9..5c0d264 100644
--- a/src/Lucene.Net.Spatial/Vector/PointVectorStrategy.cs
+++ b/src/Lucene.Net.Spatial/Vector/PointVectorStrategy.cs
@@ -19,7 +19,7 @@ using System;
using Lucene.Net.Documents;
using Lucene.Net.Queries.Function;
using Lucene.Net.Search;
-using Lucene.Net.Spatial.Query;
+using Lucene.Net.Spatial.Queries;
using Lucene.Net.Spatial.Util;
using Spatial4n.Core.Context;
using Spatial4n.Core.Shapes;