incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twilli...@apache.org
Subject [5/7] git commit: ADding more tests, fixing a couple of bugs when using the spatial types, and adding docvalue support for Geohash and QuadPrefix types.
Date Thu, 18 Sep 2014 01:58:16 GMT
ADding more tests, fixing a couple of bugs when using the spatial types, and adding docvalue support for Geohash and QuadPrefix types.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/532e3c88
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/532e3c88
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/532e3c88

Branch: refs/heads/blur-374
Commit: 532e3c8843797ba263565b8eb3a593f3a4504ead
Parents: 435519a
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Wed Sep 17 09:04:51 2014 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Wed Sep 17 09:04:51 2014 -0400

----------------------------------------------------------------------
 ...vePrefixTreeStrategyFieldTypeDefinition.java |  17 +-
 ...ryPrefixTreeStrategyFieldTypeDefinition.java |  17 +-
 .../type/spatial/lucene/PrefixTreeStrategy.java | 221 +++++++++++++++++++
 .../lucene/RecursivePrefixTreeStrategy.java     |  99 +++++++++
 .../lucene/TermQueryPrefixTreeStrategy.java     |  68 ++++++
 .../BaseSpatialFieldTypeDefinitionTest.java     | 120 ++++++++++
 ...ntVectorStrategyFieldTypeDefinitionTest.java |  75 +------
 ...yFieldTypeDefinitionGeohashDocValueTest.java |  44 ++++
 ...eStrategyFieldTypeDefinitionGeohashTest.java |  41 ++++
 ...eldTypeDefinitionQuadPrefixDocValueTest.java |  44 ++++
 ...rategyFieldTypeDefinitionQuadPrefixTest.java |  42 ++++
 ...yFieldTypeDefinitionGeohashDocValueTest.java |  43 ++++
 ...eStrategyFieldTypeDefinitionGeohashTest.java |  41 ++++
 ...eldTypeDefinitionQuadPrefixDocValueTest.java |  44 ++++
 ...rategyFieldTypeDefinitionQuadPrefixTest.java |  41 ++++
 .../blur/lucene/search/SuperParserTest.java     |  12 +-
 16 files changed, 888 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/532e3c88/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinition.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinition.java b/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinition.java
index 060ee46..a90067c 100644
--- a/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinition.java
+++ b/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinition.java
@@ -18,8 +18,10 @@ package org.apache.blur.analysis.type.spatial;
  */
 import java.util.Map;
 
+import org.apache.blur.analysis.type.spatial.lucene.RecursivePrefixTreeStrategy;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy;
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.core.KeywordAnalyzer;
 import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;
 import org.apache.lucene.spatial.query.SpatialOperation;
 
@@ -29,6 +31,8 @@ import com.spatial4j.core.shape.Shape;
 public class SpatialRecursivePrefixTreeStrategyFieldTypeDefinition extends BaseSpatialFieldTypeDefinition {
 
   public static final String NAME = "geo-recursiveprefix";
+  public static final String DOC_VALUE = "docValue";
+  private static final Analyzer _keyword = new KeywordAnalyzer();
 
   @Override
   public String getName() {
@@ -36,10 +40,19 @@ public class SpatialRecursivePrefixTreeStrategyFieldTypeDefinition extends BaseS
   }
 
   @Override
+  public Analyzer getAnalyzerForIndex(String fieldName) {
+    return _keyword;
+  }
+
+  @Override
   public void configure(String fieldNameForThisInstance, Map<String, String> properties, Configuration configuration) {
     _ctx = SpatialContext.GEO;
     SpatialPrefixTree grid = getSpatialPrefixTree(properties);
-    _strategy = new RecursivePrefixTreeStrategy(grid, fieldNameForThisInstance);
+    boolean docValue = false;
+    if (properties.get(DOC_VALUE) != null) {
+      docValue = true;
+    }
+    _strategy = new RecursivePrefixTreeStrategy(grid, fieldNameForThisInstance, docValue);
     _shapeReadWriter = new ShapeReadWriter<SpatialContext>(_ctx);
     addSupportedIndexedShapes(Shape.class);
     addSupportedOperations(SpatialOperation.IsDisjointTo);

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/532e3c88/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinition.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinition.java b/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinition.java
index ed83e1e..283388b 100644
--- a/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinition.java
+++ b/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinition.java
@@ -18,8 +18,10 @@ package org.apache.blur.analysis.type.spatial;
  */
 import java.util.Map;
 
+import org.apache.blur.analysis.type.spatial.lucene.TermQueryPrefixTreeStrategy;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy;
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.core.KeywordAnalyzer;
 import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;
 import org.apache.lucene.spatial.query.SpatialOperation;
 
@@ -28,7 +30,9 @@ import com.spatial4j.core.shape.Point;
 
 public class SpatialTermQueryPrefixTreeStrategyFieldTypeDefinition extends BaseSpatialFieldTypeDefinition {
 
+  private static final String DOC_VALUE = "docValue";
   public static final String NAME = "geo-termprefix";
+  private static final Analyzer _keyword = new KeywordAnalyzer();
 
   @Override
   public String getName() {
@@ -36,10 +40,19 @@ public class SpatialTermQueryPrefixTreeStrategyFieldTypeDefinition extends BaseS
   }
 
   @Override
+  public Analyzer getAnalyzerForIndex(String fieldName) {
+    return _keyword;
+  }
+
+  @Override
   public void configure(String fieldNameForThisInstance, Map<String, String> properties, Configuration configuration) {
     _ctx = SpatialContext.GEO;
+    boolean docValue = false;
+    if (properties.get(DOC_VALUE) != null) {
+      docValue = true;
+    }
     SpatialPrefixTree grid = getSpatialPrefixTree(properties);
-    _strategy = new TermQueryPrefixTreeStrategy(grid, fieldNameForThisInstance);
+    _strategy = new TermQueryPrefixTreeStrategy(grid, fieldNameForThisInstance, docValue);
     _shapeReadWriter = new ShapeReadWriter<SpatialContext>(_ctx);
     addSupportedIndexedShapes(Point.class);
     addSupportedOperations(SpatialOperation.Intersects);

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/532e3c88/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/lucene/PrefixTreeStrategy.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/lucene/PrefixTreeStrategy.java b/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/lucene/PrefixTreeStrategy.java
new file mode 100644
index 0000000..6c5d7c8
--- /dev/null
+++ b/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/lucene/PrefixTreeStrategy.java
@@ -0,0 +1,221 @@
+package org.apache.blur.analysis.type.spatial.lucene;
+
+/*
+ * 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.
+ */
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.SortedDocValuesField;
+import org.apache.lucene.index.FieldInfo;
+import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.spatial.SpatialStrategy;
+import org.apache.lucene.spatial.prefix.PointPrefixTreeFieldCacheProvider;
+import org.apache.lucene.spatial.prefix.tree.Cell;
+import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;
+import org.apache.lucene.spatial.query.SpatialArgs;
+import org.apache.lucene.spatial.util.ShapeFieldCacheDistanceValueSource;
+import org.apache.lucene.util.BytesRef;
+
+import com.spatial4j.core.shape.Point;
+import com.spatial4j.core.shape.Shape;
+
+/**
+ * An abstract SpatialStrategy based on {@link SpatialPrefixTree}. The two
+ * subclasses are {@link RecursivePrefixTreeStrategy} and
+ * {@link TermQueryPrefixTreeStrategy}. This strategy is most effective as a
+ * fast approximate spatial search filter.
+ * 
+ * <h4>Characteristics:</h4>
+ * <ul>
+ * <li>Can index any shape; however only {@link RecursivePrefixTreeStrategy} can
+ * effectively search non-point shapes.</li>
+ * <li>Can index a variable number of shapes per field value. This strategy can
+ * do it via multiple calls to
+ * {@link #createIndexableFields(com.spatial4j.core.shape.Shape)} for a document
+ * or by giving it some sort of Shape aggregate (e.g. JTS WKT MultiPoint). The
+ * shape's boundary is approximated to a grid precision.</li>
+ * <li>Can query with any shape. The shape's boundary is approximated to a grid
+ * precision.</li>
+ * <li>Only {@link org.apache.lucene.spatial.query.SpatialOperation#Intersects}
+ * is supported. If only points are indexed then this is effectively equivalent
+ * to IsWithin.</li>
+ * <li>The strategy supports
+ * {@link #makeDistanceValueSource(com.spatial4j.core.shape.Point)} even for
+ * multi-valued data, so long as the indexed data is all points; the behavior is
+ * undefined otherwise. However, <em>it will likely be removed in
+ * the future</em> in lieu of using another strategy with a more scalable
+ * implementation. Use of this call is the only circumstance in which a cache is
+ * used. The cache is simple but as such it doesn't scale to large numbers of
+ * points nor is it real-time-search friendly.</li>
+ * </ul>
+ * 
+ * <h4>Implementation:</h4> The {@link SpatialPrefixTree} does most of the work,
+ * for example returning a list of terms representing grids of various sizes for
+ * a supplied shape. An important configuration item is
+ * {@link #setDistErrPct(double)} which balances shape precision against
+ * scalability. See those javadocs.
+ * 
+ * @lucene.internal
+ */
+public abstract class PrefixTreeStrategy extends SpatialStrategy {
+  protected final SpatialPrefixTree grid;
+  private final Map<String, PointPrefixTreeFieldCacheProvider> provider = new ConcurrentHashMap<String, PointPrefixTreeFieldCacheProvider>();
+  protected final boolean simplifyIndexedCells;
+  protected int defaultFieldValuesArrayLen = 2;
+  protected double distErrPct = SpatialArgs.DEFAULT_DISTERRPCT;// [ 0 TO 0.5 ]
+  protected boolean docValue;
+
+  public PrefixTreeStrategy(SpatialPrefixTree grid, String fieldName, boolean simplifyIndexedCells, boolean docValue) {
+    super(grid.getSpatialContext(), fieldName);
+    this.grid = grid;
+    this.simplifyIndexedCells = simplifyIndexedCells;
+    this.docValue = docValue;
+  }
+
+  /**
+   * A memory hint used by
+   * {@link #makeDistanceValueSource(com.spatial4j.core.shape.Point)} for how
+   * big the initial size of each Document's array should be. The default is 2.
+   * Set this to slightly more than the default expected number of points per
+   * document.
+   */
+  public void setDefaultFieldValuesArrayLen(int defaultFieldValuesArrayLen) {
+    this.defaultFieldValuesArrayLen = defaultFieldValuesArrayLen;
+  }
+
+  public double getDistErrPct() {
+    return distErrPct;
+  }
+
+  /**
+   * The default measure of shape precision affecting shapes at index and query
+   * times. Points don't use this as they are always indexed at the configured
+   * maximum precision (
+   * {@link org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree#getMaxLevels()}
+   * ); this applies to all other shapes. Specific shapes at index and query
+   * time can use something different than this default value. If you don't set
+   * a default then the default is {@link SpatialArgs#DEFAULT_DISTERRPCT} --
+   * 2.5%.
+   * 
+   * @see org.apache.lucene.spatial.query.SpatialArgs#getDistErrPct()
+   */
+  public void setDistErrPct(double distErrPct) {
+    this.distErrPct = distErrPct;
+  }
+
+  @Override
+  public Field[] createIndexableFields(Shape shape) {
+    double distErr = SpatialArgs.calcDistanceFromErrPct(shape, distErrPct, ctx);
+    return createIndexableFields(shape, distErr);
+  }
+
+  public Field[] createIndexableFields(Shape shape, double distErr) {
+    int detailLevel = grid.getLevelForDistance(distErr);
+    List<Cell> cells = grid.getCells(shape, detailLevel, true, simplifyIndexedCells);// intermediates
+                                                                                     // cells
+    Field docValueField = null;
+
+    if (docValue) {
+      Cell cell = cells.get(cells.size() - 1);
+      docValueField = new SortedDocValuesField(getFieldName(), new BytesRef(cell.getTokenString()));
+    }
+
+    // TODO is CellTokenStream supposed to be re-used somehow? see Uwe's
+    // comments:
+    // http://code.google.com/p/lucene-spatial-playground/issues/detail?id=4
+
+    Field field = new Field(getFieldName(), new CellTokenStream(cells.iterator()), FIELD_TYPE);
+    return docValue ? new Field[] { docValueField, field } : new Field[] { field };
+  }
+
+  /* Indexed, tokenized, not stored. */
+  public static final FieldType FIELD_TYPE = new FieldType();
+
+  static {
+    FIELD_TYPE.setIndexed(true);
+    FIELD_TYPE.setTokenized(true);
+    FIELD_TYPE.setOmitNorms(true);
+    FIELD_TYPE.setIndexOptions(FieldInfo.IndexOptions.DOCS_ONLY);
+    FIELD_TYPE.freeze();
+  }
+
+  /**
+   * Outputs the tokenString of a cell, and if its a leaf, outputs it again with
+   * the leaf byte.
+   */
+  final static class CellTokenStream extends TokenStream {
+
+    private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
+
+    private Iterator<Cell> iter = null;
+
+    public CellTokenStream(Iterator<Cell> tokens) {
+      this.iter = tokens;
+    }
+
+    CharSequence nextTokenStringNeedingLeaf = null;
+
+    @Override
+    public boolean incrementToken() {
+      clearAttributes();
+      if (nextTokenStringNeedingLeaf != null) {
+        termAtt.append(nextTokenStringNeedingLeaf);
+        termAtt.append((char) Cell.LEAF_BYTE);
+        nextTokenStringNeedingLeaf = null;
+        return true;
+      }
+      if (iter.hasNext()) {
+        Cell cell = iter.next();
+        CharSequence token = cell.getTokenString();
+        termAtt.append(token);
+        if (cell.isLeaf())
+          nextTokenStringNeedingLeaf = token;
+        return true;
+      }
+      return false;
+    }
+
+  }
+
+  @Override
+  public ValueSource makeDistanceValueSource(Point queryPoint) {
+    PointPrefixTreeFieldCacheProvider p = provider.get(getFieldName());
+    if (p == null) {
+      synchronized (this) {// double checked locking idiom is okay since
+                           // provider is threadsafe
+        p = provider.get(getFieldName());
+        if (p == null) {
+          p = new PointPrefixTreeFieldCacheProvider(grid, getFieldName(), defaultFieldValuesArrayLen);
+          provider.put(getFieldName(), p);
+        }
+      }
+    }
+
+    return new ShapeFieldCacheDistanceValueSource(ctx, p, queryPoint);
+  }
+
+  public SpatialPrefixTree getGrid() {
+    return grid;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/532e3c88/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/lucene/RecursivePrefixTreeStrategy.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/lucene/RecursivePrefixTreeStrategy.java b/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/lucene/RecursivePrefixTreeStrategy.java
new file mode 100644
index 0000000..9adf80a
--- /dev/null
+++ b/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/lucene/RecursivePrefixTreeStrategy.java
@@ -0,0 +1,99 @@
+package org.apache.blur.analysis.type.spatial.lucene;
+
+/*
+ * 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.
+ */
+
+import com.spatial4j.core.shape.Shape;
+
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.spatial.DisjointSpatialFilter;
+import org.apache.lucene.spatial.prefix.AbstractVisitingPrefixTreeFilter;
+import org.apache.lucene.spatial.prefix.ContainsPrefixTreeFilter;
+import org.apache.lucene.spatial.prefix.IntersectsPrefixTreeFilter;
+import org.apache.lucene.spatial.prefix.WithinPrefixTreeFilter;
+import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;
+import org.apache.lucene.spatial.query.SpatialArgs;
+import org.apache.lucene.spatial.query.SpatialOperation;
+import org.apache.lucene.spatial.query.UnsupportedSpatialOperation;
+
+/**
+ * A {@link PrefixTreeStrategy} which uses
+ * {@link AbstractVisitingPrefixTreeFilter}. This strategy has support for
+ * searching non-point shapes (note: not tested). Even a query shape with
+ * distErrPct=0 (fully precise to the grid) should have good performance for
+ * typical data, unless there is a lot of indexed data coincident with the
+ * shape's edge.
+ * 
+ * @lucene.experimental
+ */
+public class RecursivePrefixTreeStrategy extends PrefixTreeStrategy {
+
+  private int prefixGridScanLevel;
+
+  public RecursivePrefixTreeStrategy(SpatialPrefixTree grid, String fieldName, boolean docValue) {
+    super(grid, fieldName, true, docValue);// simplify indexed cells
+    prefixGridScanLevel = grid.getMaxLevels() - 4;// TODO this default constant
+                                                  // is dependent on the prefix
+                                                  // grid size
+  }
+
+  /**
+   * Sets the grid level [1-maxLevels] at which indexed terms are scanned
+   * brute-force instead of by grid decomposition. By default this is maxLevels
+   * - 4. The final level, maxLevels, is always scanned.
+   * 
+   * @param prefixGridScanLevel
+   *          1 to maxLevels
+   */
+  public void setPrefixGridScanLevel(int prefixGridScanLevel) {
+    // TODO if negative then subtract from maxlevels
+    this.prefixGridScanLevel = prefixGridScanLevel;
+  }
+
+  @Override
+  public String toString() {
+    return getClass().getSimpleName() + "(prefixGridScanLevel:" + prefixGridScanLevel + ",SPG:(" + grid + "))";
+  }
+
+  @Override
+  public Filter makeFilter(SpatialArgs args) {
+    final SpatialOperation op = args.getOperation();
+    if (op == SpatialOperation.IsDisjointTo)
+      return new DisjointSpatialFilter(this, args, getFieldName());
+
+    Shape shape = args.getShape();
+    int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct));
+    final boolean hasIndexedLeaves = true;
+
+    if (op == SpatialOperation.Intersects) {
+      return new IntersectsPrefixTreeFilter(shape, getFieldName(), grid, detailLevel, prefixGridScanLevel,
+          hasIndexedLeaves);
+    } else if (op == SpatialOperation.IsWithin) {
+      return new WithinPrefixTreeFilter(shape, getFieldName(), grid, detailLevel, prefixGridScanLevel, -1);// -1
+                                                                                                           // flag
+                                                                                                           // is
+                                                                                                           // slower
+                                                                                                           // but
+                                                                                                           // ensures
+                                                                                                           // correct
+                                                                                                           // results
+    } else if (op == SpatialOperation.Contains) {
+      return new ContainsPrefixTreeFilter(shape, getFieldName(), grid, detailLevel);
+    }
+    throw new UnsupportedSpatialOperation(op);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/532e3c88/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/lucene/TermQueryPrefixTreeStrategy.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/lucene/TermQueryPrefixTreeStrategy.java b/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/lucene/TermQueryPrefixTreeStrategy.java
new file mode 100644
index 0000000..24059bf
--- /dev/null
+++ b/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/lucene/TermQueryPrefixTreeStrategy.java
@@ -0,0 +1,68 @@
+package org.apache.blur.analysis.type.spatial.lucene;
+
+/*
+ * 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.
+ */
+
+import com.spatial4j.core.shape.Shape;
+import org.apache.lucene.queries.TermsFilter;
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.spatial.prefix.tree.Cell;
+import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;
+import org.apache.lucene.spatial.query.SpatialArgs;
+import org.apache.lucene.spatial.query.SpatialOperation;
+import org.apache.lucene.spatial.query.UnsupportedSpatialOperation;
+import org.apache.lucene.util.BytesRef;
+
+import java.util.List;
+
+/**
+ * A basic implementation of {@link PrefixTreeStrategy} using a large
+ * {@link TermsFilter} of all the cells from
+ * {@link SpatialPrefixTree#getCells(com.spatial4j.core.shape.Shape, int, boolean, boolean)}
+ * . It only supports the search of indexed Point shapes.
+ * <p/>
+ * The precision of query shapes (distErrPct) is an important factor in using
+ * this Strategy. If the precision is too precise then it will result in many
+ * terms which will amount to a slower query.
+ * 
+ * @lucene.experimental
+ */
+public class TermQueryPrefixTreeStrategy extends PrefixTreeStrategy {
+
+  public TermQueryPrefixTreeStrategy(SpatialPrefixTree grid, String fieldName, boolean docValue) {
+    super(grid, fieldName, false, docValue);// do not simplify indexed cells
+  }
+
+  @Override
+  public Filter makeFilter(SpatialArgs args) {
+    final SpatialOperation op = args.getOperation();
+    if (op != SpatialOperation.Intersects)
+      throw new UnsupportedSpatialOperation(op);
+
+    Shape shape = args.getShape();
+    int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct));
+    List<Cell> cells = grid.getCells(shape, detailLevel, false,// no parents
+        true);// simplify
+    BytesRef[] terms = new BytesRef[cells.size()];
+    int i = 0;
+    for (Cell cell : cells) {
+      terms[i++] = new BytesRef(cell.getTokenString());
+    }
+    return new TermsFilter(getFieldName(), terms);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/532e3c88/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/BaseSpatialFieldTypeDefinitionTest.java
----------------------------------------------------------------------
diff --git a/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/BaseSpatialFieldTypeDefinitionTest.java b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/BaseSpatialFieldTypeDefinitionTest.java
new file mode 100644
index 0000000..5cdae19
--- /dev/null
+++ b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/BaseSpatialFieldTypeDefinitionTest.java
@@ -0,0 +1,120 @@
+/**
+ * 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.
+ */
+package org.apache.blur.analysis.type.spatial;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.blur.analysis.BaseFieldManager;
+import org.apache.blur.analysis.FieldTypeDefinition;
+import org.apache.blur.analysis.NoStopWordStandardAnalyzer;
+import org.apache.blur.lucene.search.SuperParser;
+import org.apache.blur.thrift.generated.Column;
+import org.apache.blur.thrift.generated.Record;
+import org.apache.blur.thrift.generated.ScoreType;
+import org.apache.blur.utils.BlurConstants;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.index.AtomicReader;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.SortedDocValues;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.queryparser.classic.ParseException;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.Version;
+
+public abstract class BaseSpatialFieldTypeDefinitionTest {
+
+  protected Directory _dir = new RAMDirectory();
+
+  public void runGisTypeTest() throws IOException, ParseException {
+    BaseFieldManager fieldManager = getFieldManager(new NoStopWordStandardAnalyzer());
+    setupGisField(fieldManager);
+
+    Record record = new Record();
+    record.setFamily("fam");
+    record.setRecordId("1234");
+    record.addToColumns(new Column("geo", "77.4011984,39.040444"));
+
+    List<Field> fields = fieldManager.getFields("1234", record);
+
+    IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, fieldManager.getAnalyzerForIndex());
+
+    IndexWriter writer = new IndexWriter(_dir, conf);
+    writer.addDocument(fields);
+    writer.close();
+
+    DirectoryReader reader = DirectoryReader.open(_dir);
+    IndexSearcher searcher = new IndexSearcher(reader);
+
+    SuperParser parser = new SuperParser(Version.LUCENE_43, fieldManager, true, null, ScoreType.SUPER, new Term(
+        BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE));
+
+    Query query = parser.parse("fam.geo:\"Intersects(Circle(77.4011984,39.040444 d=10.0m))\"");
+
+    TopDocs topDocs = searcher.search(query, 10);
+
+    assertEquals(1, topDocs.totalHits);
+
+    reader.close();
+
+  }
+
+  protected void runGisDocValueTest(String s) throws IOException {
+    DirectoryReader reader = DirectoryReader.open(_dir);
+    AtomicReader atomicReader = reader.leaves().get(0).reader();
+    SortedDocValues sortedDocValues = atomicReader.getSortedDocValues("fam.geo");
+    BytesRef result = new BytesRef();
+    sortedDocValues.get(0, result);
+    assertEquals(s, result.utf8ToString());
+    reader.close();
+  }
+
+  protected abstract void setupGisField(BaseFieldManager fieldManager) throws IOException;
+
+  protected BaseFieldManager getFieldManager(Analyzer a) throws IOException {
+    BaseFieldManager fieldManager = new BaseFieldManager(BlurConstants.SUPER, a, new Configuration()) {
+      @Override
+      protected boolean tryToStore(FieldTypeDefinition fieldTypeDefinition, String fieldName) {
+        return true;
+      }
+
+      @Override
+      protected void tryToLoad(String fieldName) {
+
+      }
+
+      @Override
+      protected List<String> getFieldNamesToLoad() throws IOException {
+        return new ArrayList<String>();
+      }
+    };
+    return fieldManager;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/532e3c88/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialPointVectorStrategyFieldTypeDefinitionTest.java
----------------------------------------------------------------------
diff --git a/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialPointVectorStrategyFieldTypeDefinitionTest.java b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialPointVectorStrategyFieldTypeDefinitionTest.java
index 336d026..ff8c8ba 100644
--- a/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialPointVectorStrategyFieldTypeDefinitionTest.java
+++ b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialPointVectorStrategyFieldTypeDefinitionTest.java
@@ -16,88 +16,21 @@
  */
 package org.apache.blur.analysis.type.spatial;
 
-import static org.junit.Assert.*;
-
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
 
 import org.apache.blur.analysis.BaseFieldManager;
-import org.apache.blur.analysis.FieldTypeDefinition;
-import org.apache.blur.analysis.NoStopWordStandardAnalyzer;
-import org.apache.blur.lucene.search.SuperParser;
-import org.apache.blur.thrift.generated.Column;
-import org.apache.blur.thrift.generated.Record;
-import org.apache.blur.thrift.generated.ScoreType;
-import org.apache.blur.utils.BlurConstants;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.index.DirectoryReader;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
-import org.apache.lucene.index.Term;
 import org.apache.lucene.queryparser.classic.ParseException;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TopDocs;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.RAMDirectory;
-import org.apache.lucene.util.Version;
 import org.junit.Test;
 
-public class SpatialPointVectorStrategyFieldTypeDefinitionTest {
+public class SpatialPointVectorStrategyFieldTypeDefinitionTest extends BaseSpatialFieldTypeDefinitionTest {
 
   @Test
   public void testPointVector() throws IOException, ParseException {
-    BaseFieldManager fieldManager = getFieldManager(new NoStopWordStandardAnalyzer());
-    fieldManager.addColumnDefinitionGisPointVector("fam", "geo");
-
-    Record record = new Record();
-    record.setFamily("fam");
-    record.setRecordId("1234");
-    record.addToColumns(new Column("geo", "77.4011984,39.040444"));
-
-    List<Field> fields = fieldManager.getFields("1234", record);
-
-    IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, fieldManager.getAnalyzerForIndex());
-    Directory dir = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(dir, conf);
-    writer.addDocument(fields);
-    writer.close();
-
-    DirectoryReader reader = DirectoryReader.open(dir);
-    IndexSearcher searcher = new IndexSearcher(reader);
-
-    SuperParser parser = new SuperParser(Version.LUCENE_43, fieldManager, true, null, ScoreType.SUPER, new Term(
-        BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE));
-
-    Query query = parser.parse("fam.geo:\"Intersects(Circle(77.4011984,39.040444 d=10.0m))\"");
-
-    TopDocs topDocs = searcher.search(query, 10);
-
-    assertEquals(1, topDocs.totalHits);
-
+    runGisTypeTest();
   }
 
-  private BaseFieldManager getFieldManager(Analyzer a) throws IOException {
-    BaseFieldManager fieldManager = new BaseFieldManager(BlurConstants.SUPER, a, new Configuration()) {
-      @Override
-      protected boolean tryToStore(FieldTypeDefinition fieldTypeDefinition, String fieldName) {
-        return true;
-      }
-
-      @Override
-      protected void tryToLoad(String fieldName) {
-
-      }
-
-      @Override
-      protected List<String> getFieldNamesToLoad() throws IOException {
-        return new ArrayList<String>();
-      }
-    };
-    return fieldManager;
+  protected void setupGisField(BaseFieldManager fieldManager) throws IOException {
+    fieldManager.addColumnDefinitionGisPointVector("fam", "geo");
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/532e3c88/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionGeohashDocValueTest.java
----------------------------------------------------------------------
diff --git a/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionGeohashDocValueTest.java b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionGeohashDocValueTest.java
new file mode 100644
index 0000000..ba93e56
--- /dev/null
+++ b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionGeohashDocValueTest.java
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+package org.apache.blur.analysis.type.spatial;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.blur.analysis.BaseFieldManager;
+import org.apache.lucene.queryparser.classic.ParseException;
+import org.junit.Test;
+
+public class SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionGeohashDocValueTest extends
+    BaseSpatialFieldTypeDefinitionTest {
+
+  @Test
+  public void testRecursivePrefixTreeWithGeohashAndDocValue() throws IOException, ParseException {
+    runGisTypeTest();
+    runGisDocValueTest("uvgb26kqsm0");
+  }
+
+  protected void setupGisField(BaseFieldManager fieldManager) throws IOException {
+    Map<String, String> props = new HashMap<String, String>();
+    props.put(BaseSpatialFieldTypeDefinition.SPATIAL_PREFIX_TREE, BaseSpatialFieldTypeDefinition.GEOHASH_PREFIX_TREE);
+    props.put(SpatialRecursivePrefixTreeStrategyFieldTypeDefinition.DOC_VALUE, "true");
+    fieldManager.addColumnDefinition("fam", "geo", null, false,
+        SpatialRecursivePrefixTreeStrategyFieldTypeDefinition.NAME, false, props);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/532e3c88/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionGeohashTest.java
----------------------------------------------------------------------
diff --git a/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionGeohashTest.java b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionGeohashTest.java
new file mode 100644
index 0000000..ca52057
--- /dev/null
+++ b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionGeohashTest.java
@@ -0,0 +1,41 @@
+/**
+ * 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.
+ */
+package org.apache.blur.analysis.type.spatial;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.blur.analysis.BaseFieldManager;
+import org.apache.lucene.queryparser.classic.ParseException;
+import org.junit.Test;
+
+public class SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionGeohashTest extends BaseSpatialFieldTypeDefinitionTest {
+
+  @Test
+  public void testRecursivePrefixTreeWithGeohash() throws IOException, ParseException {
+    runGisTypeTest();
+  }
+
+  protected void setupGisField(BaseFieldManager fieldManager) throws IOException {
+    Map<String, String> props = new HashMap<String, String>();
+    props.put(BaseSpatialFieldTypeDefinition.SPATIAL_PREFIX_TREE, BaseSpatialFieldTypeDefinition.GEOHASH_PREFIX_TREE);
+    fieldManager.addColumnDefinition("fam", "geo", null, false,
+        SpatialRecursivePrefixTreeStrategyFieldTypeDefinition.NAME, false, props);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/532e3c88/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionQuadPrefixDocValueTest.java
----------------------------------------------------------------------
diff --git a/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionQuadPrefixDocValueTest.java b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionQuadPrefixDocValueTest.java
new file mode 100644
index 0000000..ffaab4a
--- /dev/null
+++ b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionQuadPrefixDocValueTest.java
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+package org.apache.blur.analysis.type.spatial;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.blur.analysis.BaseFieldManager;
+import org.apache.lucene.queryparser.classic.ParseException;
+import org.junit.Test;
+
+public class SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionQuadPrefixDocValueTest extends
+    BaseSpatialFieldTypeDefinitionTest {
+
+  @Test
+  public void testRecursivePrefixTreeWithQuadPrefixAndDocValue() throws IOException, ParseException {
+    runGisTypeTest();
+    runGisDocValueTest("BAADBABDDDC");
+  }
+
+  protected void setupGisField(BaseFieldManager fieldManager) throws IOException {
+    Map<String, String> props = new HashMap<String, String>();
+    props.put(BaseSpatialFieldTypeDefinition.SPATIAL_PREFIX_TREE, BaseSpatialFieldTypeDefinition.QUAD_PREFIX_TREE);
+    props.put(SpatialRecursivePrefixTreeStrategyFieldTypeDefinition.DOC_VALUE, "true");
+    fieldManager.addColumnDefinition("fam", "geo", null, false,
+        SpatialRecursivePrefixTreeStrategyFieldTypeDefinition.NAME, false, props);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/532e3c88/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionQuadPrefixTest.java
----------------------------------------------------------------------
diff --git a/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionQuadPrefixTest.java b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionQuadPrefixTest.java
new file mode 100644
index 0000000..657a163
--- /dev/null
+++ b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionQuadPrefixTest.java
@@ -0,0 +1,42 @@
+/**
+ * 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.
+ */
+package org.apache.blur.analysis.type.spatial;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.blur.analysis.BaseFieldManager;
+import org.apache.lucene.queryparser.classic.ParseException;
+import org.junit.Test;
+
+public class SpatialRecursivePrefixTreeStrategyFieldTypeDefinitionQuadPrefixTest extends
+    BaseSpatialFieldTypeDefinitionTest {
+
+  @Test
+  public void testRecursivePrefixTreeWithQuadPrefix() throws IOException, ParseException {
+    runGisTypeTest();
+  }
+
+  protected void setupGisField(BaseFieldManager fieldManager) throws IOException {
+    Map<String, String> props = new HashMap<String, String>();
+    props.put(BaseSpatialFieldTypeDefinition.SPATIAL_PREFIX_TREE, BaseSpatialFieldTypeDefinition.QUAD_PREFIX_TREE);
+    fieldManager.addColumnDefinition("fam", "geo", null, false,
+        SpatialRecursivePrefixTreeStrategyFieldTypeDefinition.NAME, false, props);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/532e3c88/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionGeohashDocValueTest.java
----------------------------------------------------------------------
diff --git a/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionGeohashDocValueTest.java b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionGeohashDocValueTest.java
new file mode 100644
index 0000000..20602ea
--- /dev/null
+++ b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionGeohashDocValueTest.java
@@ -0,0 +1,43 @@
+/**
+ * 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.
+ */
+package org.apache.blur.analysis.type.spatial;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.blur.analysis.BaseFieldManager;
+import org.apache.lucene.queryparser.classic.ParseException;
+import org.junit.Test;
+
+public class SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionGeohashDocValueTest extends BaseSpatialFieldTypeDefinitionTest {
+
+  @Test
+  public void testTermQueryPrefixTreeWithGeohashAndDocValue() throws IOException, ParseException {
+    runGisTypeTest();
+    runGisDocValueTest("uvgb26kqsm0");
+  }
+
+  protected void setupGisField(BaseFieldManager fieldManager) throws IOException {
+    Map<String, String> props = new HashMap<String, String>();
+    props.put(BaseSpatialFieldTypeDefinition.SPATIAL_PREFIX_TREE, BaseSpatialFieldTypeDefinition.GEOHASH_PREFIX_TREE);
+    props.put(SpatialRecursivePrefixTreeStrategyFieldTypeDefinition.DOC_VALUE, "true");
+    fieldManager.addColumnDefinition("fam", "geo", null, false,
+        SpatialTermQueryPrefixTreeStrategyFieldTypeDefinition.NAME, false, props);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/532e3c88/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionGeohashTest.java
----------------------------------------------------------------------
diff --git a/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionGeohashTest.java b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionGeohashTest.java
new file mode 100644
index 0000000..8ed9ba2
--- /dev/null
+++ b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionGeohashTest.java
@@ -0,0 +1,41 @@
+/**
+ * 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.
+ */
+package org.apache.blur.analysis.type.spatial;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.blur.analysis.BaseFieldManager;
+import org.apache.lucene.queryparser.classic.ParseException;
+import org.junit.Test;
+
+public class SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionGeohashTest extends BaseSpatialFieldTypeDefinitionTest {
+
+  @Test
+  public void testTermQueryPrefixTree() throws IOException, ParseException {
+    runGisTypeTest();
+  }
+
+  protected void setupGisField(BaseFieldManager fieldManager) throws IOException {
+    Map<String, String> props = new HashMap<String, String>();
+    props.put(BaseSpatialFieldTypeDefinition.SPATIAL_PREFIX_TREE, BaseSpatialFieldTypeDefinition.GEOHASH_PREFIX_TREE);
+    fieldManager.addColumnDefinition("fam", "geo", null, false,
+        SpatialTermQueryPrefixTreeStrategyFieldTypeDefinition.NAME, false, props);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/532e3c88/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionQuadPrefixDocValueTest.java
----------------------------------------------------------------------
diff --git a/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionQuadPrefixDocValueTest.java b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionQuadPrefixDocValueTest.java
new file mode 100644
index 0000000..c6f6cb1
--- /dev/null
+++ b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionQuadPrefixDocValueTest.java
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+package org.apache.blur.analysis.type.spatial;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.blur.analysis.BaseFieldManager;
+import org.apache.lucene.queryparser.classic.ParseException;
+import org.junit.Test;
+
+public class SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionQuadPrefixDocValueTest extends
+    BaseSpatialFieldTypeDefinitionTest {
+
+  @Test
+  public void testTermQueryPrefixTreeWithQuadPrefixAndDocValue() throws IOException, ParseException {
+    runGisTypeTest();
+    runGisDocValueTest("BAADBABDDDC");
+  }
+
+  protected void setupGisField(BaseFieldManager fieldManager) throws IOException {
+    Map<String, String> props = new HashMap<String, String>();
+    props.put(BaseSpatialFieldTypeDefinition.SPATIAL_PREFIX_TREE, BaseSpatialFieldTypeDefinition.QUAD_PREFIX_TREE);
+    props.put(SpatialRecursivePrefixTreeStrategyFieldTypeDefinition.DOC_VALUE, "true");
+    fieldManager.addColumnDefinition("fam", "geo", null, false,
+        SpatialTermQueryPrefixTreeStrategyFieldTypeDefinition.NAME, false, props);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/532e3c88/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionQuadPrefixTest.java
----------------------------------------------------------------------
diff --git a/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionQuadPrefixTest.java b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionQuadPrefixTest.java
new file mode 100644
index 0000000..78eb470
--- /dev/null
+++ b/blur-query/src/test/java/org/apache/blur/analysis/type/spatial/SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionQuadPrefixTest.java
@@ -0,0 +1,41 @@
+/**
+ * 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.
+ */
+package org.apache.blur.analysis.type.spatial;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.blur.analysis.BaseFieldManager;
+import org.apache.lucene.queryparser.classic.ParseException;
+import org.junit.Test;
+
+public class SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionQuadPrefixTest extends BaseSpatialFieldTypeDefinitionTest {
+
+  @Test
+  public void testTermQueryPrefixTree() throws IOException, ParseException {
+    runGisTypeTest();
+  }
+
+  protected void setupGisField(BaseFieldManager fieldManager) throws IOException {
+    Map<String, String> props = new HashMap<String, String>();
+    props.put(BaseSpatialFieldTypeDefinition.SPATIAL_PREFIX_TREE, BaseSpatialFieldTypeDefinition.QUAD_PREFIX_TREE);
+    fieldManager.addColumnDefinition("fam", "geo", null, false,
+        SpatialTermQueryPrefixTreeStrategyFieldTypeDefinition.NAME, false, props);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/532e3c88/blur-query/src/test/java/org/apache/blur/lucene/search/SuperParserTest.java
----------------------------------------------------------------------
diff --git a/blur-query/src/test/java/org/apache/blur/lucene/search/SuperParserTest.java b/blur-query/src/test/java/org/apache/blur/lucene/search/SuperParserTest.java
index 9b9ded0..09c44bd 100644
--- a/blur-query/src/test/java/org/apache/blur/lucene/search/SuperParserTest.java
+++ b/blur-query/src/test/java/org/apache/blur/lucene/search/SuperParserTest.java
@@ -33,6 +33,7 @@ import org.apache.blur.analysis.FieldTypeDefinition;
 import org.apache.blur.analysis.NoStopWordStandardAnalyzer;
 import org.apache.blur.analysis.type.spatial.ShapeReadWriter;
 import org.apache.blur.analysis.type.spatial.SpatialArgsParser;
+import org.apache.blur.analysis.type.spatial.lucene.RecursivePrefixTreeStrategy;
 import org.apache.blur.thrift.generated.ScoreType;
 import org.apache.blur.utils.BlurConstants;
 import org.apache.hadoop.conf.Configuration;
@@ -48,7 +49,6 @@ import org.apache.lucene.search.NumericRangeQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.TermRangeQuery;
-import org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy;
 import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree;
 import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;
 import org.apache.lucene.spatial.query.SpatialArgs;
@@ -356,7 +356,7 @@ public class SuperParserTest {
     ShapeReadWriter<SpatialContext> shapeReadWriter = new ShapeReadWriter<SpatialContext>(ctx);
     int maxLevels = 11;
     SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels);
-    RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis");
+    RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false);
     Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_KM));
     SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle);
 
@@ -375,7 +375,7 @@ public class SuperParserTest {
     SpatialContext ctx = SpatialContext.GEO;
     int maxLevels = 11;
     SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels);
-    RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis");
+    RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false);
     Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_KM));
     SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle);
 
@@ -390,7 +390,7 @@ public class SuperParserTest {
     SpatialContext ctx = SpatialContext.GEO;
     int maxLevels = 11;
     SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels);
-    RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis");
+    RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false);
     Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_MI));
     SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle);
 
@@ -471,7 +471,7 @@ public class SuperParserTest {
     BooleanQuery bq = bq(bc_n(q1), bc_n(q2), bc(q3));
     assertQuery(bq, q);
   }
-  
+
   @Test
   public void test39() throws ParseException {
     Query q = parseSq("<-f.c:a> <-f.c:b>");
@@ -480,7 +480,7 @@ public class SuperParserTest {
     BooleanQuery bq = bq(bc(q1), bc(q2));
     assertQuery(bq, q);
   }
-  
+
   @Test
   public void test40() throws ParseException {
     Query q = parseSq("-<-f.c:a> -<-f.c:b>");


Mime
View raw message