You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2019/01/09 02:44:55 UTC
lucene-solr:master: SOLR-12983: Create DocValues fields directly from
byte[]
Repository: lucene-solr
Updated Branches:
refs/heads/master 951b4e4c8 -> d814d862b
SOLR-12983: Create DocValues fields directly from byte[]
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/d814d862
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/d814d862
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/d814d862
Branch: refs/heads/master
Commit: d814d862b035a17eced4ac40663471105dd56a4b
Parents: 951b4e4
Author: Noble Paul <no...@apache.org>
Authored: Wed Jan 9 13:44:41 2019 +1100
Committer: Noble Paul <no...@apache.org>
Committed: Wed Jan 9 13:44:41 2019 +1100
----------------------------------------------------------------------
.../org/apache/solr/schema/SortableTextField.java | 14 +++++++++++++-
.../src/java/org/apache/solr/schema/StrField.java | 10 +++++++++-
.../java/org/apache/solr/update/DocumentBuilder.java | 1 -
3 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d814d862/solr/core/src/java/org/apache/solr/schema/SortableTextField.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/schema/SortableTextField.java b/solr/core/src/java/org/apache/solr/schema/SortableTextField.java
index 1d2c21d..1d48c84 100644
--- a/solr/core/src/java/org/apache/solr/schema/SortableTextField.java
+++ b/solr/core/src/java/org/apache/solr/schema/SortableTextField.java
@@ -29,6 +29,7 @@ import org.apache.lucene.queries.function.valuesource.SortedSetFieldSource;
import org.apache.lucene.search.*;
import org.apache.lucene.util.BytesRef;
import org.apache.solr.common.SolrException;
+import org.apache.solr.common.util.ByteArrayUtf8CharSequence;
import org.apache.solr.search.QParser;
import org.apache.solr.uninverting.UninvertingReader.Type;
@@ -103,6 +104,13 @@ public class SortableTextField extends TextField {
if (! field.hasDocValues()) {
return Collections.singletonList(f);
}
+ if (value instanceof ByteArrayUtf8CharSequence) {
+ ByteArrayUtf8CharSequence utf8 = (ByteArrayUtf8CharSequence) value;
+ if (utf8.size() < maxCharsForDocValues) {
+ BytesRef bytes = new BytesRef(utf8.getBuf(), utf8.offset(), utf8.size());
+ return getIndexableFields(field, f, bytes);
+ }
+ }
final String origString = value.toString();
final int origLegth = origString.length();
final boolean truncate = maxCharsForDocValues < origLegth;
@@ -116,7 +124,11 @@ public class SortableTextField extends TextField {
maxCharsForDocValues + " when useDocValuesAsStored=true (length=" + origLegth + ")");
}
final BytesRef bytes = new BytesRef(truncate ? origString.subSequence(0, maxCharsForDocValues) : origString);
-
+
+ return getIndexableFields(field, f, bytes);
+ }
+
+ private static List<IndexableField> getIndexableFields(SchemaField field, IndexableField f, BytesRef bytes) {
final IndexableField docval = field.multiValued()
? new SortedSetDocValuesField(field.getName(), bytes)
: new SortedDocValuesField(field.getName(), bytes);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d814d862/solr/core/src/java/org/apache/solr/schema/StrField.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/schema/StrField.java b/solr/core/src/java/org/apache/solr/schema/StrField.java
index a8ec62c..3413ce1 100644
--- a/solr/core/src/java/org/apache/solr/schema/StrField.java
+++ b/solr/core/src/java/org/apache/solr/schema/StrField.java
@@ -31,6 +31,7 @@ import org.apache.lucene.search.SortField;
import org.apache.lucene.search.SortedSetSelector;
import org.apache.lucene.util.BytesRef;
import org.apache.solr.common.SolrException;
+import org.apache.solr.common.util.ByteArrayUtf8CharSequence;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.search.QParser;
import org.apache.solr.uninverting.UninvertingReader.Type;
@@ -48,7 +49,7 @@ public class StrField extends PrimitiveFieldType {
if (field.hasDocValues()) {
IndexableField docval;
- final BytesRef bytes = new BytesRef(value.toString());
+ final BytesRef bytes = getBytesRef(value);
if (field.multiValued()) {
docval = new SortedSetDocValuesField(field.getName(), bytes);
} else {
@@ -68,6 +69,13 @@ public class StrField extends PrimitiveFieldType {
return Collections.singletonList(fval);
}
+ public static BytesRef getBytesRef(Object value) {
+ if (value instanceof ByteArrayUtf8CharSequence) {
+ ByteArrayUtf8CharSequence utf8 = (ByteArrayUtf8CharSequence) value;
+ return new BytesRef(utf8.getBuf(), utf8.offset(), utf8.size());
+ } else return new BytesRef(value.toString());
+ }
+
@Override
public boolean isUtf8Field() {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d814d862/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java b/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
index 6aef1b4..38b10b9 100644
--- a/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
+++ b/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
@@ -166,7 +166,6 @@ public class DocumentBuilder {
if( v == null ) {
continue;
}
- v = ByteArrayUtf8CharSequence.convertCharSeq(v);
hasField = true;
if (sfield != null) {
used = true;