Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1B432200C57 for ; Sat, 15 Apr 2017 17:45:21 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 19D91160B9D; Sat, 15 Apr 2017 15:45:21 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id EFE15160BA0 for ; Sat, 15 Apr 2017 17:45:18 +0200 (CEST) Received: (qmail 51153 invoked by uid 500); 15 Apr 2017 15:45:18 -0000 Mailing-List: contact commits-help@lucenenet.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@lucenenet.apache.org Delivered-To: mailing list commits@lucenenet.apache.org Received: (qmail 51078 invoked by uid 99); 15 Apr 2017 15:45:17 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 15 Apr 2017 15:45:17 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1FC26DFB94; Sat, 15 Apr 2017 15:45:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: nightowl888@apache.org To: commits@lucenenet.apache.org Date: Sat, 15 Apr 2017 15:45:19 -0000 Message-Id: <1798bb884cc44e81a7d7dcdf563dac1f@git.apache.org> In-Reply-To: <4fe62279252540f88f54bc2f84d359f4@git.apache.org> References: <4fe62279252540f88f54bc2f84d359f4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/9] lucenenet git commit: Lucene.Net.Spatial: Deleted unused BBox directory, Prefix\RecursivePrefixTreeFilter.cs, Prefix\Tree\Node.cs and Util\TermsEnumCompatibility.cs archived-at: Sat, 15 Apr 2017 15:45:21 -0000 Lucene.Net.Spatial: Deleted unused BBox directory, Prefix\RecursivePrefixTreeFilter.cs, Prefix\Tree\Node.cs and Util\TermsEnumCompatibility.cs Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/19c150ae Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/19c150ae Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/19c150ae Branch: refs/heads/api-work Commit: 19c150ae7d3914c84a08a250921aa31ec3fe911c Parents: 3d5ee7d Author: Shad Storhaug Authored: Sat Apr 15 20:37:19 2017 +0700 Committer: Shad Storhaug Committed: Sat Apr 15 20:40:45 2017 +0700 ---------------------------------------------------------------------- src/Lucene.Net.Spatial/BBox/AreaSimilarity.cs | 231 --------- src/Lucene.Net.Spatial/BBox/BBoxSimilarity.cs | 30 -- .../BBox/BBoxSimilarityValueSource.cs | 126 ----- src/Lucene.Net.Spatial/BBox/BBoxStrategy.cs | 483 ------------------- .../BBox/DistanceSimilarity.cs | 63 --- .../Prefix/RecursivePrefixTreeFilter.cs | 189 -------- src/Lucene.Net.Spatial/Prefix/Tree/Node.cs | 222 --------- .../Util/TermsEnumCompatibility.cs | 140 ------ src/Lucene.Net.Spatial/project.json | 16 - 9 files changed, 1500 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/19c150ae/src/Lucene.Net.Spatial/BBox/AreaSimilarity.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Spatial/BBox/AreaSimilarity.cs b/src/Lucene.Net.Spatial/BBox/AreaSimilarity.cs deleted file mode 100644 index 88c8aaa..0000000 --- a/src/Lucene.Net.Spatial/BBox/AreaSimilarity.cs +++ /dev/null @@ -1,231 +0,0 @@ -/* - * 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 Spatial4n.Core.Context; -using Spatial4n.Core.Shapes; - -namespace Lucene.Net.Spatial.BBox -{ - /// - /// The algorithm is implemented as envelope on envelope overlays rather than - /// complex polygon on complex polygon overlays. - ///

- ///

- /// Spatial relevance scoring algorithm: - ///

- ///
queryArea = the area of the input query envelope - ///
targetArea = the area of the target envelope (per Lucene document) - ///
intersectionArea = the area of the intersection for the query/target envelopes - ///
queryPower = the weighting power associated with the query envelope (default = 1.0) - ///
targetPower = the weighting power associated with the target envelope (default = 1.0) - ///

- ///
queryRatio = intersectionArea / queryArea; - ///
targetRatio = intersectionArea / targetArea; - ///
queryFactor = Math.pow(queryRatio,queryPower); - ///
targetFactor = Math.pow(targetRatio,targetPower); - ///
score = queryFactor /// targetFactor; - ///

- /// Based on Geoportal's - /// - /// SpatialRankingValueSource. - /// - /// @lucene.experimental - ///

- public class AreaSimilarity : BBoxSimilarity - { - /* - * Properties associated with the query envelope - */ - private readonly Rectangle queryExtent; - private readonly double queryArea; - - private readonly double targetPower; - private readonly double queryPower; - - public AreaSimilarity(Rectangle queryExtent, double queryPower, double targetPower) - { - this.queryExtent = queryExtent; - this.queryArea = queryExtent.GetArea(null); - - this.queryPower = queryPower; - this.targetPower = targetPower; - - // if (this.qryMinX > queryExtent.getMaxX()) { - // this.qryCrossedDateline = true; - // this.qryArea = Math.abs(qryMaxX + 360.0 - qryMinX) * Math.abs(qryMaxY - qryMinY); - // } else { - // this.qryArea = Math.abs(qryMaxX - qryMinX) * Math.abs(qryMaxY - qryMinY); - // } - } - - public AreaSimilarity(Rectangle queryExtent) - : this(queryExtent, 2.0, 0.5) - { - } - - public String GetDelimiterQueryParameters() - { - return queryExtent + ";" + queryPower + ";" + targetPower; - } - - public double Score(Rectangle target, Explanation exp) - { - if (target == null || queryArea <= 0) - { - return 0; - } - double targetArea = target.GetArea(null); - if (targetArea <= 0) - { - return 0; - } - double score = 0; - - double top = Math.Min(queryExtent.GetMaxY(), target.GetMaxY()); - double bottom = Math.Max(queryExtent.GetMinY(), target.GetMinY()); - double height = top - bottom; - double width = 0; - - // queries that cross the date line - if (queryExtent.GetCrossesDateLine()) - { - // documents that cross the date line - if (target.GetCrossesDateLine()) - { - double left = Math.Max(queryExtent.GetMinX(), target.GetMinX()); - double right = Math.Min(queryExtent.GetMaxX(), target.GetMaxX()); - width = right + 360.0 - left; - } - else - { - double qryWestLeft = Math.Max(queryExtent.GetMinX(), target.GetMaxX()); - double qryWestRight = Math.Min(target.GetMaxX(), 180.0); - double qryWestWidth = qryWestRight - qryWestLeft; - if (qryWestWidth > 0) - { - width = qryWestWidth; - } - else - { - double qryEastLeft = Math.Max(target.GetMaxX(), -180.0); - double qryEastRight = Math.Min(queryExtent.GetMaxX(), target.GetMaxX()); - double qryEastWidth = qryEastRight - qryEastLeft; - if (qryEastWidth > 0) - { - width = qryEastWidth; - } - } - } - } - else - { // queries that do not cross the date line - - if (target.GetCrossesDateLine()) - { - double tgtWestLeft = Math.Max(queryExtent.GetMinX(), target.GetMinX()); - double tgtWestRight = Math.Min(queryExtent.GetMaxX(), 180.0); - double tgtWestWidth = tgtWestRight - tgtWestLeft; - if (tgtWestWidth > 0) - { - width = tgtWestWidth; - } - else - { - double tgtEastLeft = Math.Max(queryExtent.GetMinX(), -180.0); - double tgtEastRight = Math.Min(queryExtent.GetMaxX(), target.GetMaxX()); - double tgtEastWidth = tgtEastRight - tgtEastLeft; - if (tgtEastWidth > 0) - { - width = tgtEastWidth; - } - } - } - else - { - double left = Math.Max(queryExtent.GetMinX(), target.GetMinX()); - double right = Math.Min(queryExtent.GetMaxX(), target.GetMaxX()); - width = right - left; - } - } - - - // calculate the score - if ((width > 0) && (height > 0)) - { - double intersectionArea = width * height; - double queryRatio = intersectionArea / queryArea; - double targetRatio = intersectionArea / targetArea; - double queryFactor = Math.Pow(queryRatio, queryPower); - double targetFactor = Math.Pow(targetRatio, targetPower); - score = queryFactor * targetFactor * 10000.0; - - if (exp != null) - { - // StringBuilder sb = new StringBuilder(); - // sb.append("\nscore=").append(score); - // sb.append("\n query=").append(); - // sb.append("\n target=").append(target.toString()); - // sb.append("\n intersectionArea=").append(intersectionArea); - // - // sb.append(" queryArea=").append(queryArea).append(" targetArea=").append(targetArea); - // sb.append("\n queryRatio=").append(queryRatio).append(" targetRatio=").append(targetRatio); - // sb.append("\n queryFactor=").append(queryFactor).append(" targetFactor=").append(targetFactor); - // sb.append(" (queryPower=").append(queryPower).append(" targetPower=").append(targetPower).append(")"); - - exp.Value = (float)score; - exp.Description = GetType().Name; - - Explanation e = null; - - exp.AddDetail(e = new Explanation((float)intersectionArea, "IntersectionArea")); - e.AddDetail(new Explanation((float)width, "width; Query: " + queryExtent)); - e.AddDetail(new Explanation((float)height, "height; Target: " + target)); - - exp.AddDetail(e = new Explanation((float)queryFactor, "Query")); - e.AddDetail(new Explanation((float)queryArea, "area")); - e.AddDetail(new Explanation((float)queryRatio, "ratio")); - e.AddDetail(new Explanation((float)queryPower, "power")); - - exp.AddDetail(e = new Explanation((float)targetFactor, "Target")); - e.AddDetail(new Explanation((float)targetArea, "area")); - e.AddDetail(new Explanation((float)targetRatio, "ratio")); - e.AddDetail(new Explanation((float)targetPower, "power")); - } - } - else if (exp != null) - { - exp.Value = 0; - exp.Description = "Shape does not intersect"; - } - return score; - } - - public override bool Equals(object obj) - { - var other = obj as AreaSimilarity; - if (other == null) return false; - return GetDelimiterQueryParameters().Equals(other.GetDelimiterQueryParameters()); - } - - public override int GetHashCode() - { - return GetDelimiterQueryParameters().GetHashCode(); - } - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/19c150ae/src/Lucene.Net.Spatial/BBox/BBoxSimilarity.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Spatial/BBox/BBoxSimilarity.cs b/src/Lucene.Net.Spatial/BBox/BBoxSimilarity.cs deleted file mode 100644 index 6636961..0000000 --- a/src/Lucene.Net.Spatial/BBox/BBoxSimilarity.cs +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.Search; -using Spatial4n.Core.Shapes; - -namespace Lucene.Net.Spatial.BBox -{ - /// - /// Abstraction of the calculation used to determine how similar two Bounding Boxes are. - /// - public interface BBoxSimilarity - { - double Score(Rectangle extent, Explanation exp); - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/19c150ae/src/Lucene.Net.Spatial/BBox/BBoxSimilarityValueSource.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Spatial/BBox/BBoxSimilarityValueSource.cs b/src/Lucene.Net.Spatial/BBox/BBoxSimilarityValueSource.cs deleted file mode 100644 index fee54ad..0000000 --- a/src/Lucene.Net.Spatial/BBox/BBoxSimilarityValueSource.cs +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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; -using Lucene.Net.Search.Function; -using Lucene.Net.Util; -using Spatial4n.Core.Shapes; - -namespace Lucene.Net.Spatial.BBox -{ - public class BBoxSimilarityValueSource : ValueSource - { - private readonly BBoxSimilarity similarity; - private readonly BBoxStrategy strategy; - - public BBoxSimilarityValueSource(BBoxStrategy strategy, BBoxSimilarity similarity) - { - this.strategy = strategy; - this.similarity = similarity; - } - - public override string Description - { - get { return "BBoxSimilarityValueSource(" + similarity + ")"; } - } - - public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext) - { - return new BBoxSimilarityValueSourceFunctionValue(readerContext.AtomicReader, this); - } - - public override bool Equals(object o) - { - var other = o as BBoxSimilarityValueSource; - if (other == null) return false; - return similarity.Equals(other.similarity); - } - - public override int GetHashCode() - { - return typeof(BBoxSimilarityValueSource).GetHashCode() + similarity.GetHashCode(); - } - - #region Nested type: BBoxSimilarityValueSourceFunctionValue - - private class BBoxSimilarityValueSourceFunctionValue : FunctionValues - { - private readonly BBoxSimilarityValueSource _enclosingInstance; - private readonly FieldCache.Doubles maxX, maxY; - private readonly FieldCache.Doubles minX, minY; - private readonly Rectangle rect; - - private readonly IBits validMaxX; - private readonly IBits validMinX; - - public BBoxSimilarityValueSourceFunctionValue(AtomicReader reader, - BBoxSimilarityValueSource enclosingInstance) - { - _enclosingInstance = enclosingInstance; - rect = _enclosingInstance.strategy.SpatialContext.MakeRectangle(0, 0, 0, 0); //reused - - minX = FieldCache.DEFAULT.GetDoubles(reader, enclosingInstance.strategy.field_minX, true); - minY = FieldCache.DEFAULT.GetDoubles(reader, enclosingInstance.strategy.field_minY, true); - maxX = FieldCache.DEFAULT.GetDoubles(reader, enclosingInstance.strategy.field_maxX, true); - maxY = FieldCache.DEFAULT.GetDoubles(reader, enclosingInstance.strategy.field_maxY, true); - - validMinX = FieldCache.DEFAULT.GetDocsWithField(reader, enclosingInstance.strategy.field_minX); - validMaxX = FieldCache.DEFAULT.GetDocsWithField(reader, enclosingInstance.strategy.field_maxX); - } - - public override float FloatVal(int doc) - { - // make sure it has minX and area - if (validMinX[doc] && validMaxX[doc]) - { - rect.Reset( - minX.Get(doc), maxX.Get(doc), - minY.Get(doc), maxY.Get(doc)); - return (float)_enclosingInstance.similarity.Score(rect, null); - } - else - { - return (float)_enclosingInstance.similarity.Score(null, null); - } - } - - public override Explanation Explain(int doc) - { - // make sure it has minX and area - if (validMinX[doc] && validMaxX[doc]) - { - rect.Reset( - minX.Get(doc), maxX.Get(doc), - minY.Get(doc), maxY.Get(doc)); - var exp = new Explanation(); - _enclosingInstance.similarity.Score(rect, exp); - return exp; - } - return new Explanation(0, "No BBox"); - } - - public override string ToString(int doc) - { - return _enclosingInstance.Description + "=" + FloatVal(doc); - } - } - - #endregion - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/lucenenet/blob/19c150ae/src/Lucene.Net.Spatial/BBox/BBoxStrategy.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Spatial/BBox/BBoxStrategy.cs b/src/Lucene.Net.Spatial/BBox/BBoxStrategy.cs deleted file mode 100644 index d2acf1a..0000000 --- a/src/Lucene.Net.Spatial/BBox/BBoxStrategy.cs +++ /dev/null @@ -1,483 +0,0 @@ -/* - * 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.Index; -using Lucene.Net.Search; -using Lucene.Net.Search.Function; -using Lucene.Net.Spatial.Queries; -using Lucene.Net.Spatial.Util; -using Spatial4n.Core.Context; -using Spatial4n.Core.Shapes; - -namespace Lucene.Net.Spatial.BBox -{ - public class BBoxStrategy : SpatialStrategy - { - public static String SUFFIX_MINX = "__minX"; - public static String SUFFIX_MAXX = "__maxX"; - public static String SUFFIX_MINY = "__minY"; - public static String SUFFIX_MAXY = "__maxY"; - public static String SUFFIX_XDL = "__xdl"; - - /* - * The Bounding Box gets stored as four fields for x/y min/max and a flag - * that says if the box crosses the dateline (xdl). - */ - public readonly String field_bbox; - public readonly String field_minX; - public readonly String field_minY; - public readonly String field_maxX; - public readonly String field_maxY; - public readonly String field_xdl; // crosses dateline - - public readonly double queryPower = 1.0; - public readonly double targetPower = 1.0f; - public int precisionStep = 8; // same as solr default - - public BBoxStrategy(SpatialContext ctx, String fieldNamePrefix) - : base(ctx, fieldNamePrefix) - { - field_bbox = fieldNamePrefix; - field_minX = fieldNamePrefix + SUFFIX_MINX; - field_maxX = fieldNamePrefix + SUFFIX_MAXX; - field_minY = fieldNamePrefix + SUFFIX_MINY; - field_maxY = fieldNamePrefix + SUFFIX_MAXY; - field_xdl = fieldNamePrefix + SUFFIX_XDL; - } - - public void SetPrecisionStep(int p) - { - precisionStep = p; - if (precisionStep <= 0 || precisionStep >= 64) - precisionStep = int.MaxValue; - } - - //--------------------------------- - // Indexing - //--------------------------------- - - public override Field[] CreateIndexableFields(Shape shape) - { - var rect = shape as Rectangle; - if (rect != null) - return CreateIndexableFields(rect); - throw new InvalidOperationException("Can only index Rectangle, not " + shape); - } - - public Field[] CreateIndexableFields(Rectangle bbox) - { - var fields = new Field[5]; - fields[0] = DoubleField(field_minX, bbox.GetMinX()); - fields[1] = DoubleField(field_maxX, bbox.GetMaxX()); - fields[2] = DoubleField(field_minY, bbox.GetMinY()); - fields[3] = DoubleField(field_maxY, bbox.GetMaxY()); - fields[4] = new StringField(field_xdl, bbox.GetCrossesDateLine() ? "T" : "F", Field.Store.NO); - return fields; - } - - private Field DoubleField(string field, double value) - { - return new DoubleField(field, value, new FieldType(Documents.DoubleField.TYPE_NOT_STORED) - { - NumericPrecisionStep = precisionStep - }); - } - - public override ValueSource MakeDistanceValueSource(Point queryPoint) - { - return new BBoxSimilarityValueSource(this, new DistanceSimilarity(this.SpatialContext, queryPoint)); - } - - public ValueSource MakeBBoxAreaSimilarityValueSource(Rectangle queryBox) - { - return new BBoxSimilarityValueSource( - this, new AreaSimilarity(queryBox, queryPower, targetPower)); - } - - public override ConstantScoreQuery MakeQuery(SpatialArgs args) - { - return new ConstantScoreQuery(new QueryWrapperFilter(MakeSpatialQuery(args))); - } - - public Query MakeQueryWithValueSource(SpatialArgs args, ValueSource valueSource) - { - - var bq = new BooleanQuery(); - var spatial = MakeFilter(args); - bq.Add(new ConstantScoreQuery(spatial), Occur.MUST); - - // This part does the scoring - Query spatialRankingQuery = new FunctionQuery(valueSource); - bq.Add(spatialRankingQuery, Occur.MUST); - return bq; - } - - public override Filter MakeFilter(SpatialArgs args) - { - return new QueryWrapperFilter(MakeSpatialQuery(args)); - } - - private Query MakeSpatialQuery(SpatialArgs args) - { - var bbox = args.Shape as Rectangle; - if (bbox == null) - throw new InvalidOperationException("Can only query by Rectangle, not " + args.Shape); - - Query spatial = null; - - // Useful for understanding Relations: - // http://edndoc.esri.com/arcsde/9.1/general_topics/understand_spatial_relations.htm - SpatialOperation op = args.Operation; - if (op == SpatialOperation.BBoxIntersects) spatial = MakeIntersects(bbox); - else if (op == SpatialOperation.BBoxWithin) spatial = MakeWithin(bbox); - else if (op == SpatialOperation.Contains) spatial = MakeContains(bbox); - else if (op == SpatialOperation.Intersects) spatial = MakeIntersects(bbox); - else if (op == SpatialOperation.IsEqualTo) spatial = MakeEquals(bbox); - else if (op == SpatialOperation.IsDisjointTo) spatial = MakeDisjoint(bbox); - else if (op == SpatialOperation.IsWithin) spatial = MakeWithin(bbox); - else if (op == SpatialOperation.Overlaps) spatial = MakeIntersects(bbox); - else - { - throw new UnsupportedSpatialOperation(op); - } - return spatial; - } - - //------------------------------------------------------------------------------- - // - //------------------------------------------------------------------------------- - - /// - /// Constructs a query to retrieve documents that fully contain the input envelope. - /// - /// - /// The spatial query - protected Query MakeContains(Rectangle bbox) - { - - // general case - // docMinX <= queryExtent.GetMinX() AND docMinY <= queryExtent.GetMinY() AND docMaxX >= queryExtent.GetMaxX() AND docMaxY >= queryExtent.GetMaxY() - - // Y conditions - // docMinY <= queryExtent.GetMinY() AND docMaxY >= queryExtent.GetMaxY() - Query qMinY = NumericRangeQuery.NewDoubleRange(field_minY, precisionStep, null, bbox.GetMinY(), false, true); - Query qMaxY = NumericRangeQuery.NewDoubleRange(field_maxY, precisionStep, bbox.GetMaxY(), null, true, false); - Query yConditions = this.MakeQuery(new Query[] { qMinY, qMaxY }, Occur.MUST); - - // X conditions - Query xConditions = null; - - // queries that do not cross the date line - if (!bbox.GetCrossesDateLine()) - { - - // X Conditions for documents that do not cross the date line, - // documents that contain the min X and max X of the query envelope, - // docMinX <= queryExtent.GetMinX() AND docMaxX >= queryExtent.GetMaxX() - Query qMinX = NumericRangeQuery.NewDoubleRange(field_minX, precisionStep, null, bbox.GetMinX(), false, true); - Query qMaxX = NumericRangeQuery.NewDoubleRange(field_maxX, precisionStep, bbox.GetMaxX(), null, true, false); - Query qMinMax = this.MakeQuery(new Query[] { qMinX, qMaxX }, Occur.MUST); - Query qNonXDL = this.MakeXDL(false, qMinMax); - - // X Conditions for documents that cross the date line, - // the left portion of the document contains the min X of the query - // OR the right portion of the document contains the max X of the query, - // docMinXLeft <= queryExtent.GetMinX() OR docMaxXRight >= queryExtent.GetMaxX() - Query qXDLLeft = NumericRangeQuery.NewDoubleRange(field_minX, precisionStep, null, bbox.GetMinX(), false, true); - Query qXDLRight = NumericRangeQuery.NewDoubleRange(field_maxX, precisionStep, bbox.GetMaxX(), null, true, false); - Query qXDLLeftRight = this.MakeQuery(new Query[] { qXDLLeft, qXDLRight }, Occur.SHOULD); - Query qXDL = this.MakeXDL(true, qXDLLeftRight); - - // apply the non-XDL and XDL conditions - xConditions = this.MakeQuery(new Query[] { qNonXDL, qXDL }, Occur.SHOULD); - - // queries that cross the date line - } - else - { - - // No need to search for documents that do not cross the date line - - // X Conditions for documents that cross the date line, - // the left portion of the document contains the min X of the query - // AND the right portion of the document contains the max X of the query, - // docMinXLeft <= queryExtent.GetMinX() AND docMaxXRight >= queryExtent.GetMaxX() - Query qXDLLeft = NumericRangeQuery.NewDoubleRange(field_minX, precisionStep, null, bbox.GetMinX(), false, true); - Query qXDLRight = NumericRangeQuery.NewDoubleRange(field_maxX, precisionStep, bbox.GetMaxX(), null, true, false); - Query qXDLLeftRight = this.MakeQuery(new Query[] { qXDLLeft, qXDLRight }, Occur.MUST); - - xConditions = this.MakeXDL(true, qXDLLeftRight); - } - - // both X and Y conditions must occur - return this.MakeQuery(new Query[] { xConditions, yConditions }, Occur.MUST); - } - - /// - /// Constructs a query to retrieve documents that are disjoint to the input envelope. - /// - /// - /// the spatial query - Query MakeDisjoint(Rectangle bbox) - { - - // general case - // docMinX > queryExtent.GetMaxX() OR docMaxX < queryExtent.GetMinX() OR docMinY > queryExtent.GetMaxY() OR docMaxY < queryExtent.GetMinY() - - // Y conditions - // docMinY > queryExtent.GetMaxY() OR docMaxY < queryExtent.GetMinY() - Query qMinY = NumericRangeQuery.NewDoubleRange(field_minY, precisionStep, bbox.GetMaxY(), null, false, false); - Query qMaxY = NumericRangeQuery.NewDoubleRange(field_maxY, precisionStep, null, bbox.GetMinY(), false, false); - Query yConditions = this.MakeQuery(new Query[] { qMinY, qMaxY }, Occur.SHOULD); - - // X conditions - Query xConditions = null; - - // queries that do not cross the date line - if (!bbox.GetCrossesDateLine()) - { - - // X Conditions for documents that do not cross the date line, - // docMinX > queryExtent.GetMaxX() OR docMaxX < queryExtent.GetMinX() - Query qMinX = NumericRangeQuery.NewDoubleRange(field_minX, precisionStep, bbox.GetMaxX(), null, false, false); - Query qMaxX = NumericRangeQuery.NewDoubleRange(field_maxX, precisionStep, null, bbox.GetMinX(), false, false); - Query qMinMax = this.MakeQuery(new Query[] { qMinX, qMaxX }, Occur.SHOULD); - Query qNonXDL = this.MakeXDL(false, qMinMax); - - // X Conditions for documents that cross the date line, - // both the left and right portions of the document must be disjoint to the query - // (docMinXLeft > queryExtent.GetMaxX() OR docMaxXLeft < queryExtent.GetMinX()) AND - // (docMinXRight > queryExtent.GetMaxX() OR docMaxXRight < queryExtent.GetMinX()) - // where: docMaxXLeft = 180.0, docMinXRight = -180.0 - // (docMaxXLeft < queryExtent.GetMinX()) equates to (180.0 < queryExtent.GetMinX()) and is ignored - // (docMinXRight > queryExtent.GetMaxX()) equates to (-180.0 > queryExtent.GetMaxX()) and is ignored - Query qMinXLeft = NumericRangeQuery.NewDoubleRange(field_minX, precisionStep, bbox.GetMaxX(), null, false, false); - Query qMaxXRight = NumericRangeQuery.NewDoubleRange(field_maxX, precisionStep, null, bbox.GetMinX(), false, false); - Query qLeftRight = this.MakeQuery(new Query[] { qMinXLeft, qMaxXRight }, Occur.MUST); - Query qXDL = this.MakeXDL(true, qLeftRight); - - // apply the non-XDL and XDL conditions - xConditions = this.MakeQuery(new Query[] { qNonXDL, qXDL }, Occur.SHOULD); - - // queries that cross the date line - } - else - { - - // X Conditions for documents that do not cross the date line, - // the document must be disjoint to both the left and right query portions - // (docMinX > queryExtent.GetMaxX()Left OR docMaxX < queryExtent.GetMinX()) AND (docMinX > queryExtent.GetMaxX() OR docMaxX < queryExtent.GetMinX()Left) - // where: queryExtent.GetMaxX()Left = 180.0, queryExtent.GetMinX()Left = -180.0 - Query qMinXLeft = NumericRangeQuery.NewDoubleRange(field_minX, precisionStep, 180.0, null, false, false); - Query qMaxXLeft = NumericRangeQuery.NewDoubleRange(field_maxX, precisionStep, null, bbox.GetMinX(), false, false); - Query qMinXRight = NumericRangeQuery.NewDoubleRange(field_minX, precisionStep, bbox.GetMaxX(), null, false, false); - Query qMaxXRight = NumericRangeQuery.NewDoubleRange(field_maxX, precisionStep, null, -180.0, false, false); - Query qLeft = this.MakeQuery(new Query[] { qMinXLeft, qMaxXLeft }, Occur.SHOULD); - Query qRight = this.MakeQuery(new Query[] { qMinXRight, qMaxXRight }, Occur.SHOULD); - Query qLeftRight = this.MakeQuery(new Query[] { qLeft, qRight }, Occur.MUST); - - // No need to search for documents that do not cross the date line - - xConditions = this.MakeXDL(false, qLeftRight); - } - - // either X or Y conditions should occur - return this.MakeQuery(new Query[] { xConditions, yConditions }, Occur.SHOULD); - } - - /* - * Constructs a query to retrieve documents that equal the input envelope. - * - * @return the spatial query - */ - public Query MakeEquals(Rectangle bbox) - { - - // docMinX = queryExtent.GetMinX() AND docMinY = queryExtent.GetMinY() AND docMaxX = queryExtent.GetMaxX() AND docMaxY = queryExtent.GetMaxY() - Query qMinX = NumericRangeQuery.NewDoubleRange(field_minX, precisionStep, bbox.GetMinX(), bbox.GetMinX(), true, true); - Query qMinY = NumericRangeQuery.NewDoubleRange(field_minY, precisionStep, bbox.GetMinY(), bbox.GetMinY(), true, true); - Query qMaxX = NumericRangeQuery.NewDoubleRange(field_maxX, precisionStep, bbox.GetMaxX(), bbox.GetMaxX(), true, true); - Query qMaxY = NumericRangeQuery.NewDoubleRange(field_maxY, precisionStep, bbox.GetMaxY(), bbox.GetMaxY(), true, true); - - var bq = new BooleanQuery - { - {qMinX, Occur.MUST}, - {qMinY, Occur.MUST}, - {qMaxX, Occur.MUST}, - {qMaxY, Occur.MUST} - }; - return bq; - } - - /// - /// Constructs a query to retrieve documents that intersect the input envelope. - /// - /// - /// the spatial query - Query MakeIntersects(Rectangle bbox) - { - - // the original intersects query does not work for envelopes that cross the date line, - // switch to a NOT Disjoint query - - // MUST_NOT causes a problem when it's the only clause type within a BooleanQuery, - // to get round it we add all documents as a SHOULD - - // there must be an envelope, it must not be disjoint - Query qDisjoint = MakeDisjoint(bbox); - Query qIsNonXDL = this.MakeXDL(false); - Query qIsXDL = this.MakeXDL(true); - Query qHasEnv = this.MakeQuery(new Query[] { qIsNonXDL, qIsXDL }, Occur.SHOULD); - var qNotDisjoint = new BooleanQuery { { qHasEnv, Occur.MUST }, { qDisjoint, Occur.MUST_NOT } }; - - //Query qDisjoint = makeDisjoint(); - //BooleanQuery qNotDisjoint = new BooleanQuery(); - //qNotDisjoint.add(new MatchAllDocsQuery(),BooleanClause.Occur.SHOULD); - //qNotDisjoint.add(qDisjoint,BooleanClause.Occur.MUST_NOT); - return qNotDisjoint; - } - - /* - * Makes a boolean query based upon a collection of queries and a logical operator. - * - * @param queries the query collection - * @param occur the logical operator - * @return the query - */ - BooleanQuery MakeQuery(Query[] queries, Occur occur) - { - var bq = new BooleanQuery(); - foreach (Query query in queries) - { - bq.Add(query, occur); - } - return bq; - } - - /* - * Constructs a query to retrieve documents are fully within the input envelope. - * - * @return the spatial query - */ - Query MakeWithin(Rectangle bbox) - { - - // general case - // docMinX >= queryExtent.GetMinX() AND docMinY >= queryExtent.GetMinY() AND docMaxX <= queryExtent.GetMaxX() AND docMaxY <= queryExtent.GetMaxY() - - // Y conditions - // docMinY >= queryExtent.GetMinY() AND docMaxY <= queryExtent.GetMaxY() - Query qMinY = NumericRangeQuery.NewDoubleRange(field_minY, precisionStep, bbox.GetMinY(), null, true, false); - Query qMaxY = NumericRangeQuery.NewDoubleRange(field_maxY, precisionStep, null, bbox.GetMaxY(), false, true); - Query yConditions = this.MakeQuery(new Query[] { qMinY, qMaxY }, Occur.MUST); - - // X conditions - Query xConditions = null; - - // X Conditions for documents that cross the date line, - // the left portion of the document must be within the left portion of the query, - // AND the right portion of the document must be within the right portion of the query - // docMinXLeft >= queryExtent.GetMinX() AND docMaxXLeft <= 180.0 - // AND docMinXRight >= -180.0 AND docMaxXRight <= queryExtent.GetMaxX() - Query qXDLLeft = NumericRangeQuery.NewDoubleRange(field_minX, precisionStep, bbox.GetMinX(), null, true, false); - Query qXDLRight = NumericRangeQuery.NewDoubleRange(field_maxX, precisionStep, null, bbox.GetMaxX(), false, true); - Query qXDLLeftRight = this.MakeQuery(new Query[] { qXDLLeft, qXDLRight }, Occur.MUST); - Query qXDL = this.MakeXDL(true, qXDLLeftRight); - - // queries that do not cross the date line - if (!bbox.GetCrossesDateLine()) - { - - // X Conditions for documents that do not cross the date line, - // docMinX >= queryExtent.GetMinX() AND docMaxX <= queryExtent.GetMaxX() - Query qMinX = NumericRangeQuery.NewDoubleRange(field_minX, precisionStep, bbox.GetMinX(), null, true, false); - Query qMaxX = NumericRangeQuery.NewDoubleRange(field_maxX, precisionStep, null, bbox.GetMaxX(), false, true); - Query qMinMax = this.MakeQuery(new Query[] { qMinX, qMaxX }, Occur.MUST); - Query qNonXDL = this.MakeXDL(false, qMinMax); - - // apply the non-XDL or XDL X conditions - if ((bbox.GetMinX() <= -180.0) && bbox.GetMaxX() >= 180.0) - { - xConditions = this.MakeQuery(new Query[] { qNonXDL, qXDL }, Occur.SHOULD); - } - else - { - xConditions = qNonXDL; - } - - // queries that cross the date line - } - else - { - - // X Conditions for documents that do not cross the date line - - // the document should be within the left portion of the query - // docMinX >= queryExtent.GetMinX() AND docMaxX <= 180.0 - Query qMinXLeft = NumericRangeQuery.NewDoubleRange(field_minX, precisionStep, bbox.GetMinX(), null, true, false); - Query qMaxXLeft = NumericRangeQuery.NewDoubleRange(field_maxX, precisionStep, null, 180.0, false, true); - Query qLeft = this.MakeQuery(new Query[] { qMinXLeft, qMaxXLeft }, Occur.MUST); - - // the document should be within the right portion of the query - // docMinX >= -180.0 AND docMaxX <= queryExtent.GetMaxX() - Query qMinXRight = NumericRangeQuery.NewDoubleRange(field_minX, precisionStep, -180.0, null, true, false); - Query qMaxXRight = NumericRangeQuery.NewDoubleRange(field_maxX, precisionStep, null, bbox.GetMaxX(), false, true); - Query qRight = this.MakeQuery(new Query[] { qMinXRight, qMaxXRight }, Occur.MUST); - - // either left or right conditions should occur, - // apply the left and right conditions to documents that do not cross the date line - Query qLeftRight = this.MakeQuery(new Query[] { qLeft, qRight }, Occur.SHOULD); - Query qNonXDL = this.MakeXDL(false, qLeftRight); - - // apply the non-XDL and XDL conditions - xConditions = this.MakeQuery(new Query[] { qNonXDL, qXDL }, Occur.SHOULD); - } - - // both X and Y conditions must occur - return this.MakeQuery(new Query[] { xConditions, yConditions }, Occur.MUST); - } - - /* - * Constructs a query to retrieve documents that do or do not cross the date line. - * - * - * @param crossedDateLine true for documents that cross the date line - * @return the query - */ - public Query MakeXDL(bool crossedDateLine) - { - // The 'T' and 'F' values match solr fields - return new TermQuery(new Term(field_xdl, crossedDateLine ? "T" : "F")); - } - - /* - * Constructs a query to retrieve documents that do or do not cross the date line - * and match the supplied spatial query. - * - * @param crossedDateLine true for documents that cross the date line - * @param query the spatial query - * @return the query - */ - public Query MakeXDL(bool crossedDateLine, Query query) - { - var bq = new BooleanQuery { { this.MakeXDL(crossedDateLine), Occur.MUST }, { query, Occur.MUST } }; - return bq; - } - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/19c150ae/src/Lucene.Net.Spatial/BBox/DistanceSimilarity.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Spatial/BBox/DistanceSimilarity.cs b/src/Lucene.Net.Spatial/BBox/DistanceSimilarity.cs deleted file mode 100644 index a9fe4b1..0000000 --- a/src/Lucene.Net.Spatial/BBox/DistanceSimilarity.cs +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.Search; -using Spatial4n.Core.Context; -using Spatial4n.Core.Distance; -using Spatial4n.Core.Shapes; - -namespace Lucene.Net.Spatial.BBox -{ - /// - /// Returns the distance between the center of the indexed rectangle and the - /// query shape. - /// - public class DistanceSimilarity : BBoxSimilarity - { - private readonly Point queryPoint; - private readonly DistanceCalculator distCalc; - private readonly double nullValue; - - public DistanceSimilarity(SpatialContext ctx, Point queryPoint) - { - this.queryPoint = queryPoint; - this.distCalc = ctx.GetDistCalc(); - this.nullValue = (ctx.IsGeo() ? 180 : double.MaxValue); - } - - public double Score(Rectangle indexRect, Explanation exp) - { - double score; - if (indexRect == null) - { - score = nullValue; - } - else - { - score = distCalc.Distance(queryPoint, indexRect.GetCenter()); - } - if (exp != null) - { - exp.Value = (float)score; - exp.Description = GetType().Name; - exp.AddDetail(new Explanation(-1f, "" + queryPoint)); - exp.AddDetail(new Explanation(-1f, "" + indexRect)); - } - return score; - } - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/19c150ae/src/Lucene.Net.Spatial/Prefix/RecursivePrefixTreeFilter.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Spatial/Prefix/RecursivePrefixTreeFilter.cs b/src/Lucene.Net.Spatial/Prefix/RecursivePrefixTreeFilter.cs deleted file mode 100644 index ad71d0c..0000000 --- a/src/Lucene.Net.Spatial/Prefix/RecursivePrefixTreeFilter.cs +++ /dev/null @@ -1,189 +0,0 @@ -/* - * 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 System.Diagnostics; -using Lucene.Net.Search; -using Lucene.Net.Spatial.Prefix.Tree; -using Lucene.Net.Spatial.Util; -using Lucene.Net.Util; -using Spatial4n.Core.Shapes; - -namespace Lucene.Net.Spatial.Prefix -{ - /// - /// Performs a spatial intersection filter against a field indexed with {@link SpatialPrefixTree}, a Trie. - /// SPT yields terms (grids) at length 1 and at greater lengths corresponding to greater precisions. - /// This filter recursively traverses each grid length and uses methods on {@link Shape} to efficiently know - /// that all points at a prefix fit in the shape or not to either short-circuit unnecessary traversals or to efficiently - /// load all enclosed points. - /// - public class RecursivePrefixTreeFilter : Filter - { - /* TODOs for future: - -Can a polygon query shape be optimized / made-simpler at recursive depths (e.g. intersection of shape + cell box) - -RE "scan" threshold: -// IF configured to do so, we could use term.freq() as an estimate on the number of places at this depth. OR, perhaps -// make estimates based on the total known term count at this level? -if (!scan) { - //Make some estimations on how many points there are at this level and how few there would need to be to set - // !scan to false. - long termsThreshold = (long) estimateNumberIndexedTerms(cell.length(),queryShape.getDocFreqExpenseThreshold(cell)); - long thisOrd = termsEnum.ord(); - scan = (termsEnum.seek(thisOrd+termsThreshold+1) == TermsEnum.SeekStatus.END - || !cell.contains(termsEnum.term())); - termsEnum.seek(thisOrd);//return to last position -} - -*/ - - private readonly String fieldName; - private readonly SpatialPrefixTree grid; - private readonly Shape queryShape; - private readonly int prefixGridScanLevel;//at least one less than grid.getMaxLevels() - private readonly int detailLevel; - - public RecursivePrefixTreeFilter(String fieldName, SpatialPrefixTree grid, Shape queryShape, int prefixGridScanLevel, - int detailLevel) - { - this.fieldName = fieldName; - this.grid = grid; - this.queryShape = queryShape; - this.prefixGridScanLevel = Math.Max(1, Math.Min(prefixGridScanLevel, grid.MaxLevels - 1)); - this.detailLevel = detailLevel; - Debug.Assert(detailLevel <= grid.MaxLevels); - } - - public override DocIdSet GetDocIdSet(Index.IndexReader reader /*, Bits acceptDocs*/) - { - var bits = new OpenBitSet(reader.MaxDoc); - var terms = new TermsEnumCompatibility(reader, fieldName); - var term = terms.Next(); - if (term == null) - return null; - Node scanCell = null; - - //cells is treated like a stack. LinkedList conveniently has bulk add to beginning. It's in sorted order so that we - // always advance forward through the termsEnum index. - var cells = new LinkedList( - grid.GetWorldNode().GetSubCells(queryShape)); - - //This is a recursive algorithm that starts with one or more "big" cells, and then recursively dives down into the - // first such cell that intersects with the query shape. It's a depth first traversal because we don't move onto - // the next big cell (breadth) until we're completely done considering all smaller cells beneath it. For a given - // cell, if it's *within* the query shape then we can conveniently short-circuit the depth traversal and - // grab all documents assigned to this cell/term. For an intersection of the cell and query shape, we either - // recursively step down another grid level or we decide heuristically (via prefixGridScanLevel) that there aren't - // that many points, and so we scan through all terms within this cell (i.e. the term starts with the cell's term), - // seeing which ones are within the query shape. - while (cells.Count > 0) - { - Node cell = cells.First.Value; cells.RemoveFirst(); - var cellTerm = cell.GetTokenString(); - var seekStat = terms.Seek(cellTerm); - if (seekStat == TermsEnumCompatibility.SeekStatus.END) - break; - if (seekStat == TermsEnumCompatibility.SeekStatus.NOT_FOUND) - continue; - if (cell.GetLevel() == detailLevel || cell.IsLeaf()) - { - terms.Docs(bits); - } - else - {//any other intersection - //If the next indexed term is the leaf marker, then add all of them - var nextCellTerm = terms.Next(); - Debug.Assert(nextCellTerm.Text.StartsWith(cellTerm)); - scanCell = grid.GetNode(nextCellTerm.Text, scanCell); - if (scanCell.IsLeaf()) - { - terms.Docs(bits); - term = terms.Next();//move pointer to avoid potential redundant addDocs() below - } - - //Decide whether to continue to divide & conquer, or whether it's time to scan through terms beneath this cell. - // Scanning is a performance optimization trade-off. - bool scan = cell.GetLevel() >= prefixGridScanLevel;//simple heuristic - - if (!scan) - { - //Divide & conquer - var lst = cell.GetSubCells(queryShape); - for (var i = lst.Count - 1; i >= 0; i--) //add to beginning - { - cells.AddFirst(lst[i]); - } - } - else - { - //Scan through all terms within this cell to see if they are within the queryShape. No seek()s. - for (var t = terms.Term(); t != null && t.Text.StartsWith(cellTerm); t = terms.Next()) - { - scanCell = grid.GetNode(t.Text, scanCell); - int termLevel = scanCell.GetLevel(); - if (termLevel > detailLevel) - continue; - if (termLevel == detailLevel || scanCell.IsLeaf()) - { - //TODO should put more thought into implications of box vs point - Shape cShape = termLevel == grid.GetMaxLevels() ? scanCell.GetCenter() : scanCell.GetShape(); - if (queryShape.Relate(cShape) == SpatialRelation.DISJOINT) - continue; - - terms.Docs(bits); - } - }//term loop - } - } - }//cell loop - - return bits; - } - - public override string ToString() - { - return "GeoFilter{fieldName='" + fieldName + '\'' + ", shape=" + queryShape + '}'; - } - - public override bool Equals(object o) - { - if (this == o) return true; - var that = o as RecursivePrefixTreeFilter; - - if (that == null) return false; - - if (!fieldName.Equals(that.fieldName)) return false; - //note that we don't need to look at grid since for the same field it should be the same - if (prefixGridScanLevel != that.prefixGridScanLevel) return false; - if (detailLevel != that.detailLevel) return false; - if (!queryShape.Equals(that.queryShape)) return false; - - return true; - } - - public override int GetHashCode() - { - int result = fieldName.GetHashCode(); - result = 31 * result + queryShape.GetHashCode(); - result = 31 * result + detailLevel; - return result; - } - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/19c150ae/src/Lucene.Net.Spatial/Prefix/Tree/Node.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Spatial/Prefix/Tree/Node.cs b/src/Lucene.Net.Spatial/Prefix/Tree/Node.cs deleted file mode 100644 index ccff798..0000000 --- a/src/Lucene.Net.Spatial/Prefix/Tree/Node.cs +++ /dev/null @@ -1,222 +0,0 @@ -/* - * 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 System.Collections.ObjectModel; -using System.Diagnostics; -using System.Runtime.CompilerServices; -using Spatial4n.Core.Shapes; - -namespace Lucene.Net.Spatial.Prefix.Tree -{ - public abstract class Node : IComparable - { - public static byte LEAF_BYTE = (byte)'+';//NOTE: must sort before letters & numbers - - // /* - //Holds a byte[] and/or String representation of the cell. Both are lazy constructed from the other. - //Neither contains the trailing leaf byte. - // */ - //private byte[] bytes; - //private int b_off; - //private int b_len; - - private String token;//this is the only part of equality - - protected SpatialRelation shapeRel;//set in getSubCells(filter), and via setLeaf(). - protected readonly SpatialPrefixTree spatialPrefixTree; - - protected Node(SpatialPrefixTree spatialPrefixTree, String token) - { - this.spatialPrefixTree = spatialPrefixTree; - this.token = token; - if (token.Length > 0 && token[token.Length - 1] == (char)LEAF_BYTE) - { - this.token = token.Substring(0, token.Length - 1); - SetLeaf(); - } - - if (GetLevel() == 0) - GetShape();//ensure any lazy instantiation completes to make this threadsafe - } - - public virtual void Reset(string newToken) - { - Debug.Assert(GetLevel() != 0); - this.token = newToken; - shapeRel = SpatialRelation.NULL_VALUE; - b_fixLeaf(); - } - - private void b_fixLeaf() - { - if (GetLevel() == spatialPrefixTree.MaxLevels) - { - SetLeaf(); - } - } - - public SpatialRelation GetShapeRel() - { - return shapeRel; - } - - public bool IsLeaf() - { - return shapeRel == SpatialRelation.WITHIN; - } - - public void SetLeaf() - { - Debug.Assert(GetLevel() != 0); - shapeRel = SpatialRelation.WITHIN; - } - - /* - * Note: doesn't contain a trailing leaf byte. - */ - public String GetTokenString() - { - if (token == null) - throw new InvalidOperationException("Somehow we got a null token"); - return token; - } - - ///// - ///// Note: doesn't contain a trailing leaf byte. - ///// - ///// - //public byte[] GetTokenBytes() - //{ - // if (bytes != null) - // { - // if (b_off != 0 || b_len != bytes.Length) - // { - // throw new IllegalStateException("Not supported if byte[] needs to be recreated."); - // } - // } - // else - // { - // bytes = token.GetBytes(SpatialPrefixTree.UTF8); - // b_off = 0; - // b_len = bytes.Length; - // } - // return bytes; - //} - - public int GetLevel() - { - return token.Length; - //return token != null ? token.Length : b_len; - } - - //TODO add getParent() and update some algorithms to use this? - //public Cell getParent(); - - /* - * Like {@link #getSubCells()} but with the results filtered by a shape. If that shape is a {@link com.spatial4j.core.shape.Point} then it - * must call {@link #getSubCell(com.spatial4j.core.shape.Point)}; - * Precondition: Never called when getLevel() == maxLevel. - * - * @param shapeFilter an optional filter for the returned cells. - * @return A set of cells (no dups), sorted. Not Modifiable. - */ - public IList GetSubCells(Shape shapeFilter) - { - //Note: Higher-performing subclasses might override to consider the shape filter to generate fewer cells. - var point = shapeFilter as Point; - if (point != null) - { -#if !NET35 - return new ReadOnlyCollectionBuilder(new[] { GetSubCell(point) }).ToReadOnlyCollection(); -#else - return new List(new[]{GetSubCell(point)}).AsReadOnly(); -#endif - - } - - var cells = GetSubCells(); - if (shapeFilter == null) - { - return cells; - } - var copy = new List(cells.Count);//copy since cells contractually isn't modifiable - foreach (var cell in cells) - { - SpatialRelation rel = cell.GetShape().Relate(shapeFilter); - if (rel == SpatialRelation.DISJOINT) - continue; - cell.shapeRel = rel; - copy.Add(cell); - } - cells = copy; - return cells; - } - - /* - * Performant implementations are expected to implement this efficiently by considering the current - * cell's boundary. - * Precondition: Never called when getLevel() == maxLevel. - * Precondition: this.getShape().relate(p) != DISJOINT. - */ - public abstract Node GetSubCell(Point p); - - //TODO Cell getSubCell(byte b) - - /* - * Gets the cells at the next grid cell level that cover this cell. - * Precondition: Never called when getLevel() == maxLevel. - * - * @return A set of cells (no dups), sorted. Not Modifiable. - */ - public abstract IList GetSubCells(); - - /* - * {@link #getSubCells()}.size() -- usually a constant. Should be >=2 - */ - public abstract int GetSubCellsSize(); - - public abstract Shape GetShape(); - - public virtual Point GetCenter() - { - return GetShape().GetCenter(); - } - - - public int CompareTo(Node o) - { - return System.String.CompareOrdinal(GetTokenString(), o.GetTokenString()); - } - - public override bool Equals(object obj) - { - return !(obj == null || !(obj is Node)) && GetTokenString().Equals(((Node)obj).GetTokenString()); - } - - public override int GetHashCode() - { - return GetTokenString().GetHashCode(); - } - - public override string ToString() - { - return GetTokenString() + (IsLeaf() ? new string(new[] { (char)LEAF_BYTE }) : string.Empty); - } - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/19c150ae/src/Lucene.Net.Spatial/Util/TermsEnumCompatibility.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Spatial/Util/TermsEnumCompatibility.cs b/src/Lucene.Net.Spatial/Util/TermsEnumCompatibility.cs deleted file mode 100644 index 7b6809e..0000000 --- a/src/Lucene.Net.Spatial/Util/TermsEnumCompatibility.cs +++ /dev/null @@ -1,140 +0,0 @@ -/* - * - * 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.Index; -using Lucene.Net.Util; - -namespace Lucene.Net.Spatial.Util -{ - /// - /// Wraps Lucene 3 TermEnum to make it look like a Lucene 4 TermsEnum - /// SOLR-2155 - /// @author dsmiley - /// - 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; - } - - /// - /// 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. - /// - /// - /// - public SeekStatus SeekCeil(String value) - { - return Seek(value); - } - - /// - /// 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. - /// - /// - 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); - } - } - - public void Docs(FixedBitSet bits) - { - var termDocs = reader.TermDocs(new Term(fieldName, Term().Text)); - while (termDocs.Next()) - { - bits.Set(termDocs.Doc); - } - } - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/19c150ae/src/Lucene.Net.Spatial/project.json ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Spatial/project.json b/src/Lucene.Net.Spatial/project.json index a0e9abb..538306c 100644 --- a/src/Lucene.Net.Spatial/project.json +++ b/src/Lucene.Net.Spatial/project.json @@ -25,14 +25,6 @@ "debugType": "portable", "define": [ "NETSTANDARD" ], "compile": { - "exclude": [ - "BBox/*" - ], - "excludeFiles": [ - "Prefix/Tree/Node.cs", - "Prefix/RecursivePrefixTreeFilter.cs", - "Util/TermsEnumCompatibility.cs" - ], "includeFiles": [ "../CommonAssemblyInfo.cs" ] @@ -50,14 +42,6 @@ "debugType": "portable", "define": [ "FEATURE_SERIALIZABLE" ], "compile": { - "exclude": [ - "BBox/*" - ], - "excludeFiles": [ - "Prefix/Tree/Node.cs", - "Prefix/RecursivePrefixTreeFilter.cs", - "Util/TermsEnumCompatibility.cs" - ], "includeFiles": [ "../CommonAssemblyInfo.cs" ]