You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2016/03/23 17:40:25 UTC
lucene-solr:branch_6x: SOLR-8886: fix
TrieField.toObject(IndexableField) for docValues
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x 855763b06 -> 82a537795
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/82a53779
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/82a53779
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/82a53779
Branch: refs/heads/branch_6x
Commit: 82a537795ff9e85cd6834d6f46c41851b435bf7c
Parents: 855763b
Author: yonik <yo...@apache.org>
Authored: Wed Mar 23 11:56:00 2016 -0400
Committer: yonik <yo...@apache.org>
Committed: Wed Mar 23 12:40:05 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/82a53779/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 634f218..7e0fbe4 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -345,6 +345,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/82a53779/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/82a53779/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/82a53779/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"));