incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject git commit: Adding the ability to search for geohashes and quad tree prefixes directly.
Date Tue, 23 Sep 2014 19:47:32 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/master 697156e57 -> 2b0125ab2


Adding the ability to search for geohashes and quad tree prefixes directly.


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

Branch: refs/heads/master
Commit: 2b0125ab20c7f9972508989859a868463e0d5813
Parents: 697156e
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Tue Sep 23 15:47:23 2014 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Tue Sep 23 15:47:23 2014 -0400

----------------------------------------------------------------------
 .../spatial/BaseSpatialFieldTypeDefinition.java |  1 +
 ...vePrefixTreeStrategyFieldTypeDefinition.java |  5 ++-
 ...ryPrefixTreeStrategyFieldTypeDefinition.java | 31 ++++++++++++++++--
 .../BaseSpatialFieldTypeDefinitionTest.java     |  1 +
 ...eStrategyFieldTypeDefinitionGeohashTest.java | 33 +++++++++++++++++++-
 5 files changed, 64 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2b0125ab/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/BaseSpatialFieldTypeDefinition.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/BaseSpatialFieldTypeDefinition.java
b/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/BaseSpatialFieldTypeDefinition.java
index f1455ea..bf29132 100644
--- a/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/BaseSpatialFieldTypeDefinition.java
+++ b/blur-query/src/main/java/org/apache/blur/analysis/type/spatial/BaseSpatialFieldTypeDefinition.java
@@ -44,6 +44,7 @@ public abstract class BaseSpatialFieldTypeDefinition extends CustomFieldTypeDefi
 
   protected SpatialStrategy _strategy;
   protected SpatialContext _ctx;
+  protected SpatialPrefixTree _grid;
   protected ShapeReadWriter<SpatialContext> _shapeReadWriter;
   protected List<SpatialOperation> _supportedOperations;
   protected List<Class<? extends Shape>> _supportedIndexedShapes;

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2b0125ab/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 a90067c..d1c02ce 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
@@ -22,7 +22,6 @@ import org.apache.blur.analysis.type.spatial.lucene.RecursivePrefixTreeStrategy;
 import org.apache.hadoop.conf.Configuration;
 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;
 
 import com.spatial4j.core.context.SpatialContext;
@@ -47,12 +46,12 @@ public class SpatialRecursivePrefixTreeStrategyFieldTypeDefinition extends
BaseS
   @Override
   public void configure(String fieldNameForThisInstance, Map<String, String> properties,
Configuration configuration) {
     _ctx = SpatialContext.GEO;
-    SpatialPrefixTree grid = getSpatialPrefixTree(properties);
+    _grid = getSpatialPrefixTree(properties);
     boolean docValue = false;
     if (properties.get(DOC_VALUE) != null) {
       docValue = true;
     }
-    _strategy = new RecursivePrefixTreeStrategy(grid, fieldNameForThisInstance, docValue);
+    _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/2b0125ab/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 283388b..8d6d189 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
@@ -22,7 +22,11 @@ import org.apache.blur.analysis.type.spatial.lucene.TermQueryPrefixTreeStrategy;
 import org.apache.hadoop.conf.Configuration;
 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.index.Term;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree;
+import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;
 import org.apache.lucene.spatial.query.SpatialOperation;
 
 import com.spatial4j.core.context.SpatialContext;
@@ -30,6 +34,9 @@ import com.spatial4j.core.shape.Point;
 
 public class SpatialTermQueryPrefixTreeStrategyFieldTypeDefinition extends BaseSpatialFieldTypeDefinition
{
 
+  private static final String QUAD = "Quad(";
+  private static final String END = ")";
+  private static final String GEO_HASH = "GeoHash(";
   private static final String DOC_VALUE = "docValue";
   public static final String NAME = "geo-termprefix";
   private static final Analyzer _keyword = new KeywordAnalyzer();
@@ -51,10 +58,28 @@ public class SpatialTermQueryPrefixTreeStrategyFieldTypeDefinition extends
BaseS
     if (properties.get(DOC_VALUE) != null) {
       docValue = true;
     }
-    SpatialPrefixTree grid = getSpatialPrefixTree(properties);
-    _strategy = new TermQueryPrefixTreeStrategy(grid, fieldNameForThisInstance, docValue);
+    _grid = getSpatialPrefixTree(properties);
+    _strategy = new TermQueryPrefixTreeStrategy(_grid, fieldNameForThisInstance, docValue);
     _shapeReadWriter = new ShapeReadWriter<SpatialContext>(_ctx);
     addSupportedIndexedShapes(Point.class);
     addSupportedOperations(SpatialOperation.Intersects);
   }
+
+  @Override
+  public Query getCustomQuery(String text) {
+    if (_grid instanceof GeohashPrefixTree) {
+      if (text.startsWith(GEO_HASH)) {
+        int start = text.indexOf(GEO_HASH) + GEO_HASH.length();
+        int end = text.indexOf(END, start);
+        return new TermQuery(new Term(getFieldName(), text.substring(start, end)));
+      }
+    } else if (_grid instanceof QuadPrefixTree) {
+      if (text.startsWith(QUAD)) {
+        int start = text.indexOf(QUAD) + QUAD.length();
+        int end = text.indexOf(END, start);
+        return new TermQuery(new Term(getFieldName(), text.substring(start, end)));
+      }
+    }
+    return super.getCustomQuery(text);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2b0125ab/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
index 5cdae19..4bc06f8 100644
--- 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
@@ -92,6 +92,7 @@ public abstract class BaseSpatialFieldTypeDefinitionTest {
     BytesRef result = new BytesRef();
     sortedDocValues.get(0, result);
     assertEquals(s, result.utf8ToString());
+    System.out.println(result.utf8ToString());
     reader.close();
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2b0125ab/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
index 8ed9ba2..45c7b1e 100644
--- 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
@@ -16,19 +16,50 @@
  */
 package org.apache.blur.analysis.type.spatial;
 
+import static org.junit.Assert.*;
+
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.blur.analysis.BaseFieldManager;
+import org.apache.blur.analysis.NoStopWordStandardAnalyzer;
+import org.apache.blur.lucene.search.SuperParser;
+import org.apache.blur.thrift.generated.ScoreType;
+import org.apache.blur.utils.BlurConstants;
+import org.apache.lucene.index.DirectoryReader;
+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.util.Version;
 import org.junit.Test;
 
-public class SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionGeohashTest extends BaseSpatialFieldTypeDefinitionTest
{
+public class SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionGeohashTest extends
+    BaseSpatialFieldTypeDefinitionTest {
 
   @Test
   public void testTermQueryPrefixTree() throws IOException, ParseException {
     runGisTypeTest();
+    testGeoHash();
+  }
+
+  public void testGeoHash() throws IOException, ParseException {
+    BaseFieldManager fieldManager = getFieldManager(new NoStopWordStandardAnalyzer());
+    setupGisField(fieldManager);
+    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:\"GeoHash(uvgb26kqsm0)\"");
+
+    TopDocs topDocs = searcher.search(query, 10);
+    assertEquals(1, topDocs.totalHits);
+
+    reader.close();
   }
 
   protected void setupGisField(BaseFieldManager fieldManager) throws IOException {


Mime
View raw message