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


The following commit(s) were added to refs/heads/feature/GEODE-QueryProvider by 
this push:
     new 1440ac0  Support numeric fields in PdxLuceneSerializer
1440ac0 is described below

commit 1440ac066061ada4d1a23dc69e3bffeb36ba9807
Author: zhouxh <gz...@pivotal.io>
AuthorDate: Wed Jun 20 17:37:23 2018 -0700

    Support numeric fields in PdxLuceneSerializer
---
 .../serializer/HeterogeneousLuceneSerializer.java  | 23 ++++------------------
 .../repository/serializer/PdxLuceneSerializer.java | 21 ++++++++++++++++++++
 .../serializer/ReflectionLuceneSerializer.java     | 16 +++++++++++++--
 3 files changed, 39 insertions(+), 21 deletions(-)

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 160077a..6fbb675 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,8 +14,6 @@
  */
 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;
@@ -97,26 +95,13 @@ public class HeterogeneousLuceneSerializer implements 
LuceneSerializer {
 
   // TODO need a compute method to recalculate pointsConfigMap
   public Map<String, PointsConfig> getPointsConfigMap() {
+    PdxLuceneSerializer pdxSerializer = (PdxLuceneSerializer) pdxMapper;
+    pointsConfigMap.putAll(pdxSerializer.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));
-          }
-        }
+        pointsConfigMap.putAll(reflectionSerializer.getPointsConfigMap());
       }
     }
     return pointsConfigMap;
diff --git 
a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/PdxLuceneSerializer.java
 
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/PdxLuceneSerializer.java
index b644548..11308b1 100644
--- 
a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/PdxLuceneSerializer.java
+++ 
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/PdxLuceneSerializer.java
@@ -15,11 +15,15 @@
 
 package org.apache.geode.cache.lucene.internal.repository.serializer;
 
+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;
@@ -32,9 +36,25 @@ import org.apache.geode.pdx.PdxInstance;
 class PdxLuceneSerializer implements LuceneSerializer {
 
   private static final Logger logger = LogService.getLogger();
+  private Map<String, PointsConfig> pointsConfigMap = new HashMap();
 
   public PdxLuceneSerializer() {}
 
+  private void saveNumericFields(String fieldName, Object fieldValue) {
+    Class<?> clazz = fieldValue.getClass();
+    if (pointsConfigMap.get(fieldName) == null) {
+      if (clazz == Long.class || clazz == Integer.class || clazz == Float.class
+          || clazz == Double.class) {
+        pointsConfigMap.put(fieldName,
+            new PointsConfig(NumberFormat.getInstance(), (Class<? extends 
Number>) clazz));
+      }
+    }
+  }
+
+  public Map<String, PointsConfig> getPointsConfigMap() {
+    return pointsConfigMap;
+  }
+
   @Override
   public Collection<Document> toDocuments(LuceneIndex index, Object value) {
     Document doc = new Document();
@@ -46,6 +66,7 @@ class PdxLuceneSerializer implements LuceneSerializer {
           continue;
         }
         SerializerUtil.addField(doc, field, fieldValue);
+        saveNumericFields(field, fieldValue);
       }
     }
     if (logger.isDebugEnabled()) {
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 e89ed90..ea14f12 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
@@ -16,15 +16,19 @@
 package org.apache.geode.cache.lucene.internal.repository.serializer;
 
 import java.lang.reflect.Field;
+import java.text.NumberFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 
 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;
@@ -37,6 +41,7 @@ import org.apache.geode.internal.logging.LogService;
 class ReflectionLuceneSerializer implements LuceneSerializer {
 
   private Field[] fields;
+  private Map<String, PointsConfig> pointsConfigMap = new HashMap();
 
   private static final Logger logger = LogService.getLogger();
 
@@ -54,6 +59,12 @@ class ReflectionLuceneSerializer implements LuceneSerializer 
{
         if (fieldSet.contains(field.getName()) && 
SerializerUtil.isSupported(type)) {
           field.setAccessible(true);
           foundFields.add(field);
+
+          if (type == Long.class || type == Integer.class || type == 
Float.class
+              || type == Double.class) {
+            pointsConfigMap.put(field.getName(),
+                new PointsConfig(NumberFormat.getInstance(), (Class<? extends 
Number>) type));
+          }
         }
       }
 
@@ -83,7 +94,8 @@ class ReflectionLuceneSerializer implements LuceneSerializer {
     return Collections.singleton(doc);
   }
 
-  public Field[] getFields() {
-    return fields;
+  public Map<String, PointsConfig> getPointsConfigMap() {
+    return pointsConfigMap;
   }
+
 }

Reply via email to