lucene 4: sort values on hit are Text, not BytesRef
This commit is contained in:
parent
c46228254d
commit
9a79fb40bf
|
@ -298,10 +298,11 @@ public class InternalSearchHit implements SearchHit {
|
||||||
|
|
||||||
public void sortValues(Object[] sortValues) {
|
public void sortValues(Object[] sortValues) {
|
||||||
// LUCENE 4 UPGRADE: There must be a better way
|
// LUCENE 4 UPGRADE: There must be a better way
|
||||||
|
// we want to convert to a Text object here, and not BytesRef
|
||||||
if (sortValues != null) {
|
if (sortValues != null) {
|
||||||
for (int i=0; i<sortValues.length; i++) {
|
for (int i = 0; i < sortValues.length; i++) {
|
||||||
if (sortValues[i] instanceof BytesRef) {
|
if (sortValues[i] instanceof BytesRef) {
|
||||||
sortValues[i] = new StringAndBytesText(new BytesArray((BytesRef)sortValues[i]));
|
sortValues[i] = new StringAndBytesText(new BytesArray((BytesRef) sortValues[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -481,8 +482,8 @@ public class InternalSearchHit implements SearchHit {
|
||||||
|
|
||||||
public void readFrom(StreamInput in, InternalSearchHits.StreamContext context) throws IOException {
|
public void readFrom(StreamInput in, InternalSearchHits.StreamContext context) throws IOException {
|
||||||
score = in.readFloat();
|
score = in.readFloat();
|
||||||
id = in.readUTF();
|
id = in.readString();
|
||||||
type = in.readUTF();
|
type = in.readString();
|
||||||
version = in.readLong();
|
version = in.readLong();
|
||||||
source = in.readBytesReference();
|
source = in.readBytesReference();
|
||||||
if (source.length() == 0) {
|
if (source.length() == 0) {
|
||||||
|
@ -566,7 +567,7 @@ public class InternalSearchHit implements SearchHit {
|
||||||
if (type == 0) {
|
if (type == 0) {
|
||||||
sortValues[i] = null;
|
sortValues[i] = null;
|
||||||
} else if (type == 1) {
|
} else if (type == 1) {
|
||||||
sortValues[i] = in.readUTF();
|
sortValues[i] = in.readString();
|
||||||
} else if (type == 2) {
|
} else if (type == 2) {
|
||||||
sortValues[i] = in.readInt();
|
sortValues[i] = in.readInt();
|
||||||
} else if (type == 3) {
|
} else if (type == 3) {
|
||||||
|
@ -582,8 +583,7 @@ public class InternalSearchHit implements SearchHit {
|
||||||
} else if (type == 8) {
|
} else if (type == 8) {
|
||||||
sortValues[i] = in.readBoolean();
|
sortValues[i] = in.readBoolean();
|
||||||
} else if (type == 9) {
|
} else if (type == 9) {
|
||||||
// LUCENE 4 UPGRADE: There must be a better way
|
sortValues[i] = in.readText();
|
||||||
sortValues[i] = new StringAndBytesText(new BytesArray(in.readBytesRef()));
|
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Can't match type [" + type + "]");
|
throw new IOException("Can't match type [" + type + "]");
|
||||||
}
|
}
|
||||||
|
@ -594,7 +594,7 @@ public class InternalSearchHit implements SearchHit {
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
matchedFilters = new String[size];
|
matchedFilters = new String[size];
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
matchedFilters[i] = in.readUTF();
|
matchedFilters[i] = in.readString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -617,8 +617,8 @@ public class InternalSearchHit implements SearchHit {
|
||||||
|
|
||||||
public void writeTo(StreamOutput out, InternalSearchHits.StreamContext context) throws IOException {
|
public void writeTo(StreamOutput out, InternalSearchHits.StreamContext context) throws IOException {
|
||||||
out.writeFloat(score);
|
out.writeFloat(score);
|
||||||
out.writeUTF(id);
|
out.writeString(id);
|
||||||
out.writeUTF(type);
|
out.writeString(type);
|
||||||
out.writeLong(version);
|
out.writeLong(version);
|
||||||
out.writeBytesReference(source);
|
out.writeBytesReference(source);
|
||||||
if (explanation == null) {
|
if (explanation == null) {
|
||||||
|
@ -655,7 +655,7 @@ public class InternalSearchHit implements SearchHit {
|
||||||
Class type = sortValue.getClass();
|
Class type = sortValue.getClass();
|
||||||
if (type == String.class) {
|
if (type == String.class) {
|
||||||
out.writeByte((byte) 1);
|
out.writeByte((byte) 1);
|
||||||
out.writeUTF((String) sortValue);
|
out.writeString((String) sortValue);
|
||||||
} else if (type == Integer.class) {
|
} else if (type == Integer.class) {
|
||||||
out.writeByte((byte) 2);
|
out.writeByte((byte) 2);
|
||||||
out.writeInt((Integer) sortValue);
|
out.writeInt((Integer) sortValue);
|
||||||
|
@ -677,9 +677,9 @@ public class InternalSearchHit implements SearchHit {
|
||||||
} else if (type == Boolean.class) {
|
} else if (type == Boolean.class) {
|
||||||
out.writeByte((byte) 8);
|
out.writeByte((byte) 8);
|
||||||
out.writeBoolean((Boolean) sortValue);
|
out.writeBoolean((Boolean) sortValue);
|
||||||
} else if (type == BytesRef.class) {
|
} else if (sortValue instanceof Text) {
|
||||||
out.writeByte((byte) 9);
|
out.writeByte((byte) 9);
|
||||||
out.writeBytesRef((BytesRef) sortValue);
|
out.writeText((Text) sortValue);
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Can't handle sort field value of type [" + type + "]");
|
throw new IOException("Can't handle sort field value of type [" + type + "]");
|
||||||
}
|
}
|
||||||
|
@ -692,7 +692,7 @@ public class InternalSearchHit implements SearchHit {
|
||||||
} else {
|
} else {
|
||||||
out.writeVInt(matchedFilters.length);
|
out.writeVInt(matchedFilters.length);
|
||||||
for (String matchedFilter : matchedFilters) {
|
for (String matchedFilter : matchedFilters) {
|
||||||
out.writeUTF(matchedFilter);
|
out.writeString(matchedFilter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue