lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject lucene-solr:branch_6_0: SOLR-8886: fix TrieField.toObject(IndexableField) for docValues
Date Wed, 23 Mar 2016 16:41:10 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6_0 7667b67c8 -> a144f16f7


SOLR-8886: fix TrieField.toObject(IndexableField) for docValues


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/a144f16f
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/a144f16f
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/a144f16f

Branch: refs/heads/branch_6_0
Commit: a144f16f72bf12d97b060da26f3cfe60abaad80d
Parents: 7667b67
Author: yonik <yonik@apache.org>
Authored: Wed Mar 23 11:56:00 2016 -0400
Committer: yonik <yonik@apache.org>
Committed: Wed Mar 23 12:40:14 2016 -0400

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  3 ++
 .../java/org/apache/solr/schema/TrieField.java  | 40 +++++++++++++++++++-
 .../solr/collection1/conf/schema-docValues.xml  | 11 ++++++
 .../org/apache/solr/schema/DocValuesTest.java   | 22 +++++++++++
 4 files changed, 74 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a144f16f/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index e219483..4bc695d 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -282,6 +282,9 @@ Bug Fixes
   numeric field.  For more complex functions, FunctionValues.exists() must also return true
   for the document to match.  (yonik)
 
+* SOLR-8886: Fix TrieField.toObject(IndexableField) to work for field with docValues
+  enabled. (yonik)
+
 Optimizations
 ----------------------
 * SOLR-7876: Speed up queries and operations that use many terms when timeAllowed has not
been

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a144f16f/solr/core/src/java/org/apache/solr/schema/TrieField.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/schema/TrieField.java b/solr/core/src/java/org/apache/solr/schema/TrieField.java
index 1580b00..506d8ad 100644
--- a/solr/core/src/java/org/apache/solr/schema/TrieField.java
+++ b/solr/core/src/java/org/apache/solr/schema/TrieField.java
@@ -33,6 +33,7 @@ import org.apache.lucene.document.LegacyIntField;
 import org.apache.lucene.document.LegacyLongField;
 import org.apache.lucene.document.NumericDocValuesField;
 import org.apache.lucene.document.SortedSetDocValuesField;
+import org.apache.lucene.index.DocValuesType;
 import org.apache.lucene.index.IndexOptions;
 import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.queries.function.ValueSource;
@@ -121,11 +122,46 @@ public class TrieField extends PrimitiveFieldType {
   public Object toObject(IndexableField f) {
     final Number val = f.numericValue();
     if (val != null) {
+
+      if (f.fieldType().stored() == false && f.fieldType().docValuesType() == DocValuesType.NUMERIC
) {
+        long bits = val.longValue();
+        switch (type) {
+          case INTEGER:
+            return (int)bits;
+          case FLOAT:
+            return Float.intBitsToFloat((int)bits);
+          case LONG:
+            return bits;
+          case DOUBLE:
+            return Double.longBitsToDouble(bits);
+          case DATE:
+            return new Date(bits);
+          default:
+            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for
trie field: " + f.name());
+        }
+      }
+
+      // normal stored case
       return (type == TrieTypes.DATE) ? new Date(val.longValue()) : val;
     } else {
-      // the old BinaryField encoding is no longer supported
-      return badFieldString(f);
+      // multi-valued numeric docValues currently use SortedSet on the indexed terms.
+      BytesRef term = f.binaryValue();
+      switch (type) {
+        case INTEGER:
+          return LegacyNumericUtils.prefixCodedToInt(term);
+        case FLOAT:
+          return NumericUtils.sortableIntToFloat(LegacyNumericUtils.prefixCodedToInt(term));
+        case LONG:
+          return LegacyNumericUtils.prefixCodedToLong(term);
+        case DOUBLE:
+          return NumericUtils.sortableLongToDouble(LegacyNumericUtils.prefixCodedToLong(term));
+        case DATE:
+          return new Date(LegacyNumericUtils.prefixCodedToLong(term));
+        default:
+          throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for
trie field: " + f.name());
+      }
     }
+
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a144f16f/solr/core/src/test-files/solr/collection1/conf/schema-docValues.xml
----------------------------------------------------------------------
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-docValues.xml b/solr/core/src/test-files/solr/collection1/conf/schema-docValues.xml
index cbbdf6e..680ac04 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema-docValues.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-docValues.xml
@@ -67,6 +67,17 @@
     <field name="datedv" type="date" indexed="false" stored="false" docValues="true" default="1995-12-31T23:59:59.999Z"
/>
 
     <field name="stringdv" type="string" indexed="false" stored="false" docValues="true"
default="solr" />
+
+    <field name="floatdvs" type="float" indexed="false" stored="false" docValues="true"
default="1" />
+    <field name="intdvs" type="int" indexed="false" stored="false" docValues="true" default="2"
/>
+    <field name="doubledvs" type="double" indexed="false" stored="false" docValues="true"
default="3" />
+    <field name="longdvs" type="long" indexed="false" stored="false" docValues="true"
default="4" />
+    <field name="datedvs" type="date" indexed="false" stored="false" docValues="true"
default="1995-12-31T23:59:59.999Z" />
+    <field name="stringdvs" type="string" indexed="false" stored="false" docValues="true"
default="solr" />
+
+
+
+
   </fields>
 
   <uniqueKey>id</uniqueKey>

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a144f16f/solr/core/src/test/org/apache/solr/schema/DocValuesTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/schema/DocValuesTest.java b/solr/core/src/test/org/apache/solr/schema/DocValuesTest.java
index f1d0196..2537c8f 100644
--- a/solr/core/src/test/org/apache/solr/schema/DocValuesTest.java
+++ b/solr/core/src/test/org/apache/solr/schema/DocValuesTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.solr.schema;
 
+import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.index.LeafReader;
 import org.apache.lucene.index.DocValuesType;
 import org.apache.lucene.index.FieldInfos;
@@ -33,6 +34,7 @@ import java.io.IOException;
 import java.lang.invoke.MethodHandles;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 import java.util.function.Function;
 import java.util.function.Supplier;
@@ -102,12 +104,32 @@ public class DocValuesTest extends SolrTestCaseJ4 {
         values = longDv.getType().getValueSource(longDv, null).getValues(null, searcher.getLeafReader().leaves().get(0));
         assertEquals(4L, values.longVal(0));
         assertEquals(4L, values.objectVal(0));
+
+        // check reversability of created fields
+        tstToObj(schema.getField("floatdv"), -1.5f);
+        tstToObj(schema.getField("floatdvs"), -1.5f);
+        tstToObj(schema.getField("doubledv"), -1.5d);
+        tstToObj(schema.getField("doubledvs"), -1.5d);
+        tstToObj(schema.getField("intdv"), -7);
+        tstToObj(schema.getField("intdvs"), -7);
+        tstToObj(schema.getField("longdv"), -11L);
+        tstToObj(schema.getField("longdvs"), -11L);
+        tstToObj(schema.getField("datedv"), new Date(1000));
+        tstToObj(schema.getField("datedvs"), new Date(1000));
+        
       } finally {
         searcherRef.decref();
       }
     }
   }
 
+  private void tstToObj(SchemaField sf, Object o) {
+    List<IndexableField> fields = sf.createFields(o, 1.0f);
+    for (IndexableField field : fields) {
+      assertEquals( sf.getType().toObject(field), o);
+    }
+  }
+
   public void testDocValuesSorting() {
     assertU(adoc("id", "1", "floatdv", "2", "intdv", "3", "doubledv", "4", "longdv", "5",
"datedv", "1995-12-31T23:59:59.999Z", "stringdv", "b"));
     assertU(adoc("id", "2", "floatdv", "5", "intdv", "4", "doubledv", "3", "longdv", "2",
"datedv", "1997-12-31T23:59:59.999Z", "stringdv", "a"));


Mime
View raw message