geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zho...@apache.org
Subject [geode] 01/01: GEODE-QueryProvider: add pointsConfigMap to support numeric query
Date Wed, 13 Jun 2018 17:03:29 GMT
This is an automated email from the ASF dual-hosted git repository.

zhouxj pushed a commit to branch feature/GEODE-QueryProvider
in repository https://gitbox.apache.org/repos/asf/geode.git

commit d92adb76bb23bcdb0c3f960e30e1c1cde0454838
Author: zhouxh <gzhou@pivotal.io>
AuthorDate: Wed Jun 13 10:01:34 2018 -0700

    GEODE-QueryProvider: add pointsConfigMap to support numeric query
---
 .../lucene/internal/LuceneIndexFactoryImpl.java    |  3 +-
 .../cache/lucene/internal/StringQueryProvider.java | 20 +++++++++++++
 .../serializer/HeterogeneousLuceneSerializer.java  | 33 ++++++++++++++++++++++
 .../serializer/ReflectionLuceneSerializer.java     |  4 +++
 4 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexFactoryImpl.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexFactoryImpl.java
index 45d4fe1..0332954 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexFactoryImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexFactoryImpl.java
@@ -22,11 +22,12 @@ import org.apache.lucene.analysis.standard.StandardAnalyzer;
 
 import org.apache.geode.cache.lucene.LuceneIndexFactory;
 import org.apache.geode.cache.lucene.LuceneSerializer;
+import org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer;
 
 public class LuceneIndexFactoryImpl implements LuceneIndexFactory {
   private final LuceneServiceImpl service;
   private final Map<String, Analyzer> fields = new LinkedHashMap<String, Analyzer>();
-  private LuceneSerializer serializer;
+  private LuceneSerializer serializer = new HeterogeneousLuceneSerializer();
 
 
   public LuceneIndexFactoryImpl(final LuceneServiceImpl luceneService) {
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/StringQueryProvider.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/StringQueryProvider.java
index f0626b5..d0aeb24 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/StringQueryProvider.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/StringQueryProvider.java
@@ -18,16 +18,21 @@ package org.apache.geode.cache.lucene.internal;
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
+import java.util.Arrays;
+import java.util.Map;
 
 import org.apache.logging.log4j.Logger;
 import org.apache.lucene.queryparser.flexible.core.QueryNodeException;
 import org.apache.lucene.queryparser.flexible.standard.StandardQueryParser;
+import org.apache.lucene.queryparser.flexible.standard.config.PointsConfig;
 import org.apache.lucene.search.Query;
 
 import org.apache.geode.DataSerializer;
 import org.apache.geode.cache.lucene.LuceneIndex;
 import org.apache.geode.cache.lucene.LuceneQueryException;
 import org.apache.geode.cache.lucene.LuceneQueryProvider;
+import org.apache.geode.cache.lucene.LuceneSerializer;
+import org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer;
 import org.apache.geode.internal.DataSerializableFixedID;
 import org.apache.geode.internal.Version;
 import org.apache.geode.internal.i18n.LocalizedStrings;
@@ -66,6 +71,21 @@ public class StringQueryProvider implements LuceneQueryProvider, DataSerializabl
     if (luceneQuery == null) {
       LuceneIndexImpl indexImpl = (LuceneIndexImpl) index;
       StandardQueryParser parser = new StandardQueryParser(indexImpl.getAnalyzer());
+      // parser.getQueryConfigHandler().set(StandardQueryConfigHandler.ConfigurationKeys.DATE_RESOLUTION,
+      // DateTools.Resolution.MILLISECOND);
+      Map<String, PointsConfig> pointsConfigMap = null;
+      LuceneSerializer serializer = index.getLuceneSerializer();
+      if (serializer instanceof HeterogeneousLuceneSerializer) {
+        HeterogeneousLuceneSerializer heteroSerializer = (HeterogeneousLuceneSerializer)
serializer;
+        pointsConfigMap = heteroSerializer.getPointsConfigMap();
+      }
+      logger.info(serializer + ":" + Arrays.toString(indexImpl.getFieldNames()) + ":"
+              + parser.getDateResolution());
+      // pointsConfigMap.put("revenue", new PointsConfig(NumberFormat.getInstance(),
+      // Integer.class));
+      parser.setPointsConfigMap(pointsConfigMap);
+      // TODO: is DateTools.Resolution optional?
+      // parser.setDateResolution(DateTools.Resolution.MILLISECOND);
       parser.setAllowLeadingWildcard(true);
       try {
         luceneQuery = parser.parse(query, defaultField);
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializer.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializer.java
index 41281d5..160077a 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializer.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializer.java
@@ -14,12 +14,16 @@
  */
 package org.apache.geode.cache.lucene.internal.repository.serializer;
 
+import java.lang.reflect.Field;
+import java.text.NumberFormat;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.logging.log4j.Logger;
 import org.apache.lucene.document.Document;
+import org.apache.lucene.queryparser.flexible.standard.config.PointsConfig;
 
 import org.apache.geode.cache.lucene.LuceneIndex;
 import org.apache.geode.cache.lucene.LuceneSerializer;
@@ -45,6 +49,8 @@ public class HeterogeneousLuceneSerializer implements LuceneSerializer {
   private Map<Class<?>, LuceneSerializer> mappers =
       new CopyOnWriteWeakHashMap<Class<?>, LuceneSerializer>();
 
+  private Map<String, PointsConfig> pointsConfigMap = new HashMap();
+
   private static final Logger logger = LogService.getLogger();
 
   public HeterogeneousLuceneSerializer() {
@@ -89,4 +95,31 @@ public class HeterogeneousLuceneSerializer implements LuceneSerializer
{
     }
   }
 
+  // TODO need a compute method to recalculate pointsConfigMap
+  public Map<String, PointsConfig> getPointsConfigMap() {
+    for (LuceneSerializer serializer : mappers.values()) {
+      if (serializer instanceof ReflectionLuceneSerializer) {
+        ReflectionLuceneSerializer reflectionSerializer = (ReflectionLuceneSerializer) serializer;
+        Field[] fields = reflectionSerializer.getFields();
+        for (Field field : fields) {
+          Class<?> type = field.getType();
+          if (type == int.class || type == Integer.class) {
+            pointsConfigMap.put(field.getName(),
+                new PointsConfig(NumberFormat.getInstance(), Integer.class));
+          } else if (type == float.class || type == Float.class) {
+            pointsConfigMap.put(field.getName(),
+                new PointsConfig(NumberFormat.getInstance(), Float.class));
+          } else if (type == long.class || type == Long.class) {
+            pointsConfigMap.put(field.getName(),
+                new PointsConfig(NumberFormat.getInstance(), Long.class));
+          } else if (type == double.class || type == Double.class) {
+            pointsConfigMap.put(field.getName(),
+                new PointsConfig(NumberFormat.getInstance(), Double.class));
+          }
+        }
+      }
+    }
+    return pointsConfigMap;
+  }
+
 }
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/ReflectionLuceneSerializer.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/ReflectionLuceneSerializer.java
index 947b2ad..e89ed90 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/ReflectionLuceneSerializer.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/ReflectionLuceneSerializer.java
@@ -82,4 +82,8 @@ class ReflectionLuceneSerializer implements LuceneSerializer {
     }
     return Collections.singleton(doc);
   }
+
+  public Field[] getFields() {
+    return fields;
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
zhouxj@apache.org.

Mime
View raw message