lucene 4: Changed from BytesReference to Text as internal term representation for facet keys. Text now also implements comparable.
This commit is contained in:
parent
b128b7a750
commit
d820bfe11b
|
@ -137,55 +137,4 @@ public interface BytesReference {
|
||||||
String toUtf8();
|
String toUtf8();
|
||||||
|
|
||||||
|
|
||||||
// LUCENE 4 UPGRADE: Used by facets to order. Perhaps make this call implement Comparable.
|
|
||||||
public final static Comparator<BytesReference> utf8SortedAsUnicodeSortOrder = new UTF8SortedAsUnicodeComparator();
|
|
||||||
|
|
||||||
public static class UTF8SortedAsUnicodeComparator implements Comparator<BytesReference> {
|
|
||||||
|
|
||||||
// Only singleton
|
|
||||||
private UTF8SortedAsUnicodeComparator() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compare(BytesReference a, BytesReference b) {
|
|
||||||
if (a.hasArray() && b.hasArray()) {
|
|
||||||
final byte[] aBytes = a.array();
|
|
||||||
int aUpto = a.arrayOffset();
|
|
||||||
final byte[] bBytes = b.array();
|
|
||||||
int bUpto = b.arrayOffset();
|
|
||||||
|
|
||||||
final int aStop = aUpto + Math.min(a.length(), b.length());
|
|
||||||
while (aUpto < aStop) {
|
|
||||||
int aByte = aBytes[aUpto++] & 0xff;
|
|
||||||
int bByte = bBytes[bUpto++] & 0xff;
|
|
||||||
|
|
||||||
int diff = aByte - bByte;
|
|
||||||
if (diff != 0) {
|
|
||||||
return diff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// One is a prefix of the other, or, they are equal:
|
|
||||||
return a.length() - b.length();
|
|
||||||
} else {
|
|
||||||
final byte[] aBytes = a.toBytes();
|
|
||||||
int aUpto = 0;
|
|
||||||
final byte[] bBytes = b.toBytes();
|
|
||||||
int bUpto = 0;
|
|
||||||
|
|
||||||
final int aStop = aUpto + Math.min(a.length(), b.length());
|
|
||||||
while (aUpto < aStop) {
|
|
||||||
int aByte = aBytes[aUpto++] & 0xff;
|
|
||||||
int bByte = bBytes[bUpto++] & 0xff;
|
|
||||||
|
|
||||||
int diff = aByte - bByte;
|
|
||||||
if (diff != 0) {
|
|
||||||
return diff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// One is a prefix of the other, or, they are equal:
|
|
||||||
return a.length() - b.length();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ package org.elasticsearch.common.text;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link BytesReference} representation of the text, will always convert on the fly to a {@link String}.
|
* A {@link BytesReference} representation of the text, will always convert on the fly to a {@link String}.
|
||||||
*/
|
*/
|
||||||
|
@ -71,4 +73,10 @@ public class BytesText implements Text {
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return bytes().equals(((Text) obj).bytes());
|
return bytes().equals(((Text) obj).bytes());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Text text) {
|
||||||
|
return UTF8SortedAsUnicodeComparator.utf8SortedAsUnicodeSortOrder.compare(text.bytes(), text.bytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -97,4 +97,13 @@ public class StringAndBytesText implements Text {
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return bytes().equals(((Text) obj).bytes());
|
return bytes().equals(((Text) obj).bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Text other) {
|
||||||
|
if (text == null) {
|
||||||
|
return UTF8SortedAsUnicodeComparator.utf8SortedAsUnicodeSortOrder.compare(bytes, other.bytes());
|
||||||
|
} else {
|
||||||
|
return text.compareTo(other.string());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,4 +83,9 @@ public class StringText implements Text {
|
||||||
// we use bytes here so we can be consistent with other text implementations
|
// we use bytes here so we can be consistent with other text implementations
|
||||||
return bytes().equals(((Text) obj).bytes());
|
return bytes().equals(((Text) obj).bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Text text) {
|
||||||
|
return this.text.compareTo(text.string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.elasticsearch.common.bytes.BytesReference;
|
||||||
* so we can represent it in a more optimized manner in memory as well as serializing it over the
|
* so we can represent it in a more optimized manner in memory as well as serializing it over the
|
||||||
* network as well as converting it to json format.
|
* network as well as converting it to json format.
|
||||||
*/
|
*/
|
||||||
public interface Text {
|
public interface Text extends Comparable<Text> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Are bytes available without the need to be converted into bytes when calling {@link #bytes()}.
|
* Are bytes available without the need to be converted into bytes when calling {@link #bytes()}.
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package org.elasticsearch.common.text;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
// LUCENE 4 UPGRADE: Is this the right way of comparing bytesreferences inside Text instances?
|
||||||
|
// Copied from Lucene's BytesRef comparator
|
||||||
|
public class UTF8SortedAsUnicodeComparator implements Comparator<BytesReference> {
|
||||||
|
|
||||||
|
public final static Comparator<BytesReference> utf8SortedAsUnicodeSortOrder = new UTF8SortedAsUnicodeComparator();
|
||||||
|
|
||||||
|
// Only singleton
|
||||||
|
private UTF8SortedAsUnicodeComparator() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compare(BytesReference a, BytesReference b) {
|
||||||
|
if (a.hasArray() && b.hasArray()) {
|
||||||
|
final byte[] aBytes = a.array();
|
||||||
|
int aUpto = a.arrayOffset();
|
||||||
|
final byte[] bBytes = b.array();
|
||||||
|
int bUpto = b.arrayOffset();
|
||||||
|
|
||||||
|
final int aStop = aUpto + Math.min(a.length(), b.length());
|
||||||
|
while (aUpto < aStop) {
|
||||||
|
int aByte = aBytes[aUpto++] & 0xff;
|
||||||
|
int bByte = bBytes[bUpto++] & 0xff;
|
||||||
|
|
||||||
|
int diff = aByte - bByte;
|
||||||
|
if (diff != 0) {
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// One is a prefix of the other, or, they are equal:
|
||||||
|
return a.length() - b.length();
|
||||||
|
} else {
|
||||||
|
final byte[] aBytes = a.toBytes();
|
||||||
|
int aUpto = 0;
|
||||||
|
final byte[] bBytes = b.toBytes();
|
||||||
|
int bUpto = 0;
|
||||||
|
|
||||||
|
final int aStop = aUpto + Math.min(a.length(), b.length());
|
||||||
|
while (aUpto < aStop) {
|
||||||
|
int aByte = aBytes[aUpto++] & 0xff;
|
||||||
|
int bByte = bBytes[bUpto++] & 0xff;
|
||||||
|
|
||||||
|
int diff = aByte - bByte;
|
||||||
|
if (diff != 0) {
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// One is a prefix of the other, or, they are equal:
|
||||||
|
return a.length() - b.length();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.search.facet.terms;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
|
import org.elasticsearch.common.text.Text;
|
||||||
import org.elasticsearch.search.facet.Facet;
|
import org.elasticsearch.search.facet.Facet;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -41,9 +42,9 @@ public interface TermsFacet extends Facet, Iterable<TermsFacet.Entry> {
|
||||||
|
|
||||||
public interface Entry extends Comparable<Entry> {
|
public interface Entry extends Comparable<Entry> {
|
||||||
|
|
||||||
BytesReference term();
|
Text term();
|
||||||
|
|
||||||
BytesReference getTerm();
|
Text getTerm();
|
||||||
|
|
||||||
Number termAsNumber();
|
Number termAsNumber();
|
||||||
|
|
||||||
|
|
|
@ -22,13 +22,12 @@ package org.elasticsearch.search.facet.terms.bytes;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import gnu.trove.iterator.TByteIntIterator;
|
import gnu.trove.iterator.TByteIntIterator;
|
||||||
import gnu.trove.map.hash.TByteIntHashMap;
|
import gnu.trove.map.hash.TByteIntHashMap;
|
||||||
import org.apache.lucene.util.BytesRef;
|
|
||||||
import org.elasticsearch.common.CacheRecycler;
|
import org.elasticsearch.common.CacheRecycler;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
|
||||||
import org.elasticsearch.common.collect.BoundedTreeSet;
|
import org.elasticsearch.common.collect.BoundedTreeSet;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
|
import org.elasticsearch.common.text.StringText;
|
||||||
|
import org.elasticsearch.common.text.Text;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||||
import org.elasticsearch.search.facet.Facet;
|
import org.elasticsearch.search.facet.Facet;
|
||||||
|
@ -74,11 +73,11 @@ public class InternalByteTermsFacet extends InternalTermsFacet {
|
||||||
this.count = count;
|
this.count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference term() {
|
public Text term() {
|
||||||
return new BytesArray(Short.toString(term));
|
return new StringText(Short.toString(term));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference getTerm() {
|
public Text getTerm() {
|
||||||
return term();
|
return term();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ import com.google.common.collect.ImmutableSet;
|
||||||
import gnu.trove.iterator.TByteIntIterator;
|
import gnu.trove.iterator.TByteIntIterator;
|
||||||
import gnu.trove.map.hash.TByteIntHashMap;
|
import gnu.trove.map.hash.TByteIntHashMap;
|
||||||
import gnu.trove.set.hash.TByteHashSet;
|
import gnu.trove.set.hash.TByteHashSet;
|
||||||
import org.apache.lucene.index.AtomicReader;
|
|
||||||
import org.apache.lucene.index.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
import org.apache.lucene.search.Scorer;
|
import org.apache.lucene.search.Scorer;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
|
|
|
@ -22,13 +22,12 @@ package org.elasticsearch.search.facet.terms.doubles;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import gnu.trove.iterator.TDoubleIntIterator;
|
import gnu.trove.iterator.TDoubleIntIterator;
|
||||||
import gnu.trove.map.hash.TDoubleIntHashMap;
|
import gnu.trove.map.hash.TDoubleIntHashMap;
|
||||||
import org.apache.lucene.util.BytesRef;
|
|
||||||
import org.elasticsearch.common.CacheRecycler;
|
import org.elasticsearch.common.CacheRecycler;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
|
||||||
import org.elasticsearch.common.collect.BoundedTreeSet;
|
import org.elasticsearch.common.collect.BoundedTreeSet;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
|
import org.elasticsearch.common.text.StringText;
|
||||||
|
import org.elasticsearch.common.text.Text;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||||
import org.elasticsearch.search.facet.Facet;
|
import org.elasticsearch.search.facet.Facet;
|
||||||
|
@ -74,11 +73,11 @@ public class InternalDoubleTermsFacet extends InternalTermsFacet {
|
||||||
this.count = count;
|
this.count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference term() {
|
public Text term() {
|
||||||
return new BytesArray(Double.toString(term));
|
return new StringText(Double.toString(term));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference getTerm() {
|
public Text getTerm() {
|
||||||
return term();
|
return term();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ import com.google.common.collect.ImmutableSet;
|
||||||
import gnu.trove.iterator.TDoubleIntIterator;
|
import gnu.trove.iterator.TDoubleIntIterator;
|
||||||
import gnu.trove.map.hash.TDoubleIntHashMap;
|
import gnu.trove.map.hash.TDoubleIntHashMap;
|
||||||
import gnu.trove.set.hash.TDoubleHashSet;
|
import gnu.trove.set.hash.TDoubleHashSet;
|
||||||
import org.apache.lucene.index.AtomicReader;
|
|
||||||
import org.apache.lucene.index.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
import org.apache.lucene.search.Scorer;
|
import org.apache.lucene.search.Scorer;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
|
|
|
@ -22,13 +22,12 @@ package org.elasticsearch.search.facet.terms.floats;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import gnu.trove.iterator.TFloatIntIterator;
|
import gnu.trove.iterator.TFloatIntIterator;
|
||||||
import gnu.trove.map.hash.TFloatIntHashMap;
|
import gnu.trove.map.hash.TFloatIntHashMap;
|
||||||
import org.apache.lucene.util.BytesRef;
|
|
||||||
import org.elasticsearch.common.CacheRecycler;
|
import org.elasticsearch.common.CacheRecycler;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
|
||||||
import org.elasticsearch.common.collect.BoundedTreeSet;
|
import org.elasticsearch.common.collect.BoundedTreeSet;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
|
import org.elasticsearch.common.text.StringText;
|
||||||
|
import org.elasticsearch.common.text.Text;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||||
import org.elasticsearch.search.facet.Facet;
|
import org.elasticsearch.search.facet.Facet;
|
||||||
|
@ -74,11 +73,11 @@ public class InternalFloatTermsFacet extends InternalTermsFacet {
|
||||||
this.count = count;
|
this.count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference term() {
|
public Text term() {
|
||||||
return new BytesArray(Float.toString(term));
|
return new StringText(Float.toString(term));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference getTerm() {
|
public Text getTerm() {
|
||||||
return term();
|
return term();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +281,7 @@ public class InternalFloatTermsFacet extends InternalTermsFacet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
name = in.readUTF();
|
name = in.readString();
|
||||||
comparatorType = ComparatorType.fromId(in.readByte());
|
comparatorType = ComparatorType.fromId(in.readByte());
|
||||||
requiredSize = in.readVInt();
|
requiredSize = in.readVInt();
|
||||||
missing = in.readVLong();
|
missing = in.readVLong();
|
||||||
|
@ -297,7 +296,7 @@ public class InternalFloatTermsFacet extends InternalTermsFacet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeUTF(name);
|
out.writeString(name);
|
||||||
out.writeByte(comparatorType.id());
|
out.writeByte(comparatorType.id());
|
||||||
out.writeVInt(requiredSize);
|
out.writeVInt(requiredSize);
|
||||||
out.writeVLong(missing);
|
out.writeVLong(missing);
|
||||||
|
|
|
@ -24,9 +24,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
import gnu.trove.iterator.TFloatIntIterator;
|
import gnu.trove.iterator.TFloatIntIterator;
|
||||||
import gnu.trove.map.hash.TFloatIntHashMap;
|
import gnu.trove.map.hash.TFloatIntHashMap;
|
||||||
import gnu.trove.set.hash.TFloatHashSet;
|
import gnu.trove.set.hash.TFloatHashSet;
|
||||||
import org.apache.lucene.index.AtomicReader;
|
|
||||||
import org.apache.lucene.index.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
import org.apache.lucene.index.IndexReader;
|
|
||||||
import org.apache.lucene.search.Scorer;
|
import org.apache.lucene.search.Scorer;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||||
|
|
|
@ -22,13 +22,12 @@ package org.elasticsearch.search.facet.terms.ints;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import gnu.trove.iterator.TIntIntIterator;
|
import gnu.trove.iterator.TIntIntIterator;
|
||||||
import gnu.trove.map.hash.TIntIntHashMap;
|
import gnu.trove.map.hash.TIntIntHashMap;
|
||||||
import org.apache.lucene.util.BytesRef;
|
|
||||||
import org.elasticsearch.common.CacheRecycler;
|
import org.elasticsearch.common.CacheRecycler;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
|
||||||
import org.elasticsearch.common.collect.BoundedTreeSet;
|
import org.elasticsearch.common.collect.BoundedTreeSet;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
|
import org.elasticsearch.common.text.StringText;
|
||||||
|
import org.elasticsearch.common.text.Text;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||||
import org.elasticsearch.search.facet.Facet;
|
import org.elasticsearch.search.facet.Facet;
|
||||||
|
@ -74,11 +73,11 @@ public class InternalIntTermsFacet extends InternalTermsFacet {
|
||||||
this.count = count;
|
this.count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference term() {
|
public Text term() {
|
||||||
return new BytesArray(Integer.toString(term));
|
return new StringText(Integer.toString(term));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference getTerm() {
|
public Text getTerm() {
|
||||||
return term();
|
return term();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +278,7 @@ public class InternalIntTermsFacet extends InternalTermsFacet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
name = in.readUTF();
|
name = in.readString();
|
||||||
comparatorType = ComparatorType.fromId(in.readByte());
|
comparatorType = ComparatorType.fromId(in.readByte());
|
||||||
requiredSize = in.readVInt();
|
requiredSize = in.readVInt();
|
||||||
missing = in.readVLong();
|
missing = in.readVLong();
|
||||||
|
@ -294,7 +293,7 @@ public class InternalIntTermsFacet extends InternalTermsFacet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeUTF(name);
|
out.writeString(name);
|
||||||
out.writeByte(comparatorType.id());
|
out.writeByte(comparatorType.id());
|
||||||
out.writeVInt(requiredSize);
|
out.writeVInt(requiredSize);
|
||||||
out.writeVLong(missing);
|
out.writeVLong(missing);
|
||||||
|
|
|
@ -24,9 +24,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
import gnu.trove.iterator.TIntIntIterator;
|
import gnu.trove.iterator.TIntIntIterator;
|
||||||
import gnu.trove.map.hash.TIntIntHashMap;
|
import gnu.trove.map.hash.TIntIntHashMap;
|
||||||
import gnu.trove.set.hash.TIntHashSet;
|
import gnu.trove.set.hash.TIntHashSet;
|
||||||
import org.apache.lucene.index.AtomicReader;
|
|
||||||
import org.apache.lucene.index.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
import org.apache.lucene.index.IndexReader;
|
|
||||||
import org.apache.lucene.search.Scorer;
|
import org.apache.lucene.search.Scorer;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||||
|
|
|
@ -22,13 +22,12 @@ package org.elasticsearch.search.facet.terms.ip;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import gnu.trove.iterator.TLongIntIterator;
|
import gnu.trove.iterator.TLongIntIterator;
|
||||||
import gnu.trove.map.hash.TLongIntHashMap;
|
import gnu.trove.map.hash.TLongIntHashMap;
|
||||||
import org.apache.lucene.util.BytesRef;
|
|
||||||
import org.elasticsearch.common.CacheRecycler;
|
import org.elasticsearch.common.CacheRecycler;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
|
||||||
import org.elasticsearch.common.collect.BoundedTreeSet;
|
import org.elasticsearch.common.collect.BoundedTreeSet;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
|
import org.elasticsearch.common.text.StringText;
|
||||||
|
import org.elasticsearch.common.text.Text;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||||
import org.elasticsearch.index.mapper.ip.IpFieldMapper;
|
import org.elasticsearch.index.mapper.ip.IpFieldMapper;
|
||||||
|
@ -75,11 +74,11 @@ public class InternalIpTermsFacet extends InternalTermsFacet {
|
||||||
this.count = count;
|
this.count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference term() {
|
public Text term() {
|
||||||
return new BytesArray(IpFieldMapper.longToIp(term));
|
return new StringText(IpFieldMapper.longToIp(term));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference getTerm() {
|
public Text getTerm() {
|
||||||
return term();
|
return term();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,7 +283,7 @@ public class InternalIpTermsFacet extends InternalTermsFacet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
name = in.readUTF();
|
name = in.readString();
|
||||||
comparatorType = ComparatorType.fromId(in.readByte());
|
comparatorType = ComparatorType.fromId(in.readByte());
|
||||||
requiredSize = in.readVInt();
|
requiredSize = in.readVInt();
|
||||||
missing = in.readVLong();
|
missing = in.readVLong();
|
||||||
|
@ -299,7 +298,7 @@ public class InternalIpTermsFacet extends InternalTermsFacet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeUTF(name);
|
out.writeString(name);
|
||||||
out.writeByte(comparatorType.id());
|
out.writeByte(comparatorType.id());
|
||||||
out.writeVInt(requiredSize);
|
out.writeVInt(requiredSize);
|
||||||
out.writeVLong(missing);
|
out.writeVLong(missing);
|
||||||
|
|
|
@ -22,9 +22,7 @@ package org.elasticsearch.search.facet.terms.ip;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import gnu.trove.iterator.TLongIntIterator;
|
import gnu.trove.iterator.TLongIntIterator;
|
||||||
import gnu.trove.map.hash.TLongIntHashMap;
|
import gnu.trove.map.hash.TLongIntHashMap;
|
||||||
import org.apache.lucene.index.AtomicReader;
|
|
||||||
import org.apache.lucene.index.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
import org.apache.lucene.index.IndexReader;
|
|
||||||
import org.apache.lucene.search.Scorer;
|
import org.apache.lucene.search.Scorer;
|
||||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||||
import org.elasticsearch.common.CacheRecycler;
|
import org.elasticsearch.common.CacheRecycler;
|
||||||
|
|
|
@ -23,11 +23,11 @@ import com.google.common.collect.ImmutableList;
|
||||||
import gnu.trove.iterator.TLongIntIterator;
|
import gnu.trove.iterator.TLongIntIterator;
|
||||||
import gnu.trove.map.hash.TLongIntHashMap;
|
import gnu.trove.map.hash.TLongIntHashMap;
|
||||||
import org.elasticsearch.common.CacheRecycler;
|
import org.elasticsearch.common.CacheRecycler;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
|
||||||
import org.elasticsearch.common.collect.BoundedTreeSet;
|
import org.elasticsearch.common.collect.BoundedTreeSet;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
|
import org.elasticsearch.common.text.StringText;
|
||||||
|
import org.elasticsearch.common.text.Text;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||||
import org.elasticsearch.search.facet.Facet;
|
import org.elasticsearch.search.facet.Facet;
|
||||||
|
@ -73,11 +73,11 @@ public class InternalLongTermsFacet extends InternalTermsFacet {
|
||||||
this.count = count;
|
this.count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference term() {
|
public Text term() {
|
||||||
return new BytesArray(Long.toString(term));
|
return new StringText(Long.toString(term));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference getTerm() {
|
public Text getTerm() {
|
||||||
return term();
|
return term();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ public class InternalLongTermsFacet extends InternalTermsFacet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
name = in.readUTF();
|
name = in.readString();
|
||||||
comparatorType = ComparatorType.fromId(in.readByte());
|
comparatorType = ComparatorType.fromId(in.readByte());
|
||||||
requiredSize = in.readVInt();
|
requiredSize = in.readVInt();
|
||||||
missing = in.readVLong();
|
missing = in.readVLong();
|
||||||
|
@ -296,7 +296,7 @@ public class InternalLongTermsFacet extends InternalTermsFacet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeUTF(name);
|
out.writeString(name);
|
||||||
out.writeByte(comparatorType.id());
|
out.writeByte(comparatorType.id());
|
||||||
out.writeVInt(requiredSize);
|
out.writeVInt(requiredSize);
|
||||||
out.writeVLong(missing);
|
out.writeVLong(missing);
|
||||||
|
|
|
@ -22,13 +22,12 @@ package org.elasticsearch.search.facet.terms.shorts;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import gnu.trove.iterator.TShortIntIterator;
|
import gnu.trove.iterator.TShortIntIterator;
|
||||||
import gnu.trove.map.hash.TShortIntHashMap;
|
import gnu.trove.map.hash.TShortIntHashMap;
|
||||||
import org.apache.lucene.util.BytesRef;
|
|
||||||
import org.elasticsearch.common.CacheRecycler;
|
import org.elasticsearch.common.CacheRecycler;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
|
||||||
import org.elasticsearch.common.collect.BoundedTreeSet;
|
import org.elasticsearch.common.collect.BoundedTreeSet;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
|
import org.elasticsearch.common.text.StringText;
|
||||||
|
import org.elasticsearch.common.text.Text;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||||
import org.elasticsearch.search.facet.Facet;
|
import org.elasticsearch.search.facet.Facet;
|
||||||
|
@ -74,11 +73,11 @@ public class InternalShortTermsFacet extends InternalTermsFacet {
|
||||||
this.count = count;
|
this.count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference term() {
|
public Text term() {
|
||||||
return new BytesArray(Short.toString(term));
|
return new StringText(Short.toString(term));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference getTerm() {
|
public Text getTerm() {
|
||||||
return term();
|
return term();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +278,7 @@ public class InternalShortTermsFacet extends InternalTermsFacet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
name = in.readUTF();
|
name = in.readString();
|
||||||
comparatorType = ComparatorType.fromId(in.readByte());
|
comparatorType = ComparatorType.fromId(in.readByte());
|
||||||
requiredSize = in.readVInt();
|
requiredSize = in.readVInt();
|
||||||
missing = in.readVLong();
|
missing = in.readVLong();
|
||||||
|
@ -294,7 +293,7 @@ public class InternalShortTermsFacet extends InternalTermsFacet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeUTF(name);
|
out.writeString(name);
|
||||||
out.writeByte(comparatorType.id());
|
out.writeByte(comparatorType.id());
|
||||||
out.writeVInt(requiredSize);
|
out.writeVInt(requiredSize);
|
||||||
out.writeVLong(missing);
|
out.writeVLong(missing);
|
||||||
|
|
|
@ -24,9 +24,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
import gnu.trove.iterator.TShortIntIterator;
|
import gnu.trove.iterator.TShortIntIterator;
|
||||||
import gnu.trove.map.hash.TShortIntHashMap;
|
import gnu.trove.map.hash.TShortIntHashMap;
|
||||||
import gnu.trove.set.hash.TShortHashSet;
|
import gnu.trove.set.hash.TShortHashSet;
|
||||||
import org.apache.lucene.index.AtomicReader;
|
|
||||||
import org.apache.lucene.index.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
import org.apache.lucene.index.IndexReader;
|
|
||||||
import org.apache.lucene.search.Scorer;
|
import org.apache.lucene.search.Scorer;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||||
|
|
|
@ -25,10 +25,12 @@ import gnu.trove.map.hash.TObjectIntHashMap;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.common.CacheRecycler;
|
import org.elasticsearch.common.CacheRecycler;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
import org.elasticsearch.common.bytes.BytesArray;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
|
||||||
import org.elasticsearch.common.collect.BoundedTreeSet;
|
import org.elasticsearch.common.collect.BoundedTreeSet;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
|
import org.elasticsearch.common.text.BytesText;
|
||||||
|
import org.elasticsearch.common.text.StringText;
|
||||||
|
import org.elasticsearch.common.text.Text;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||||
import org.elasticsearch.search.facet.Facet;
|
import org.elasticsearch.search.facet.Facet;
|
||||||
|
@ -66,36 +68,36 @@ public class InternalStringTermsFacet extends InternalTermsFacet {
|
||||||
|
|
||||||
public static class TermEntry implements Entry {
|
public static class TermEntry implements Entry {
|
||||||
|
|
||||||
private BytesReference term;
|
private Text term;
|
||||||
private int count;
|
private int count;
|
||||||
|
|
||||||
public TermEntry(String term, int count) {
|
public TermEntry(String term, int count) {
|
||||||
this.term = new BytesArray(term);
|
this.term = new StringText(term);
|
||||||
this.count = count;
|
this.count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TermEntry(BytesRef term, int count) {
|
public TermEntry(BytesRef term, int count) {
|
||||||
this.term = new BytesArray(term);
|
this.term = new BytesText(new BytesArray(term));
|
||||||
this.count = count;
|
this.count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TermEntry(BytesReference term, int count) {
|
public TermEntry(Text term, int count) {
|
||||||
this.term = term;
|
this.term = term;
|
||||||
this.count = count;
|
this.count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference term() {
|
public Text term() {
|
||||||
return term;
|
return term;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference getTerm() {
|
public Text getTerm() {
|
||||||
return term;
|
return term;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Number termAsNumber() {
|
public Number termAsNumber() {
|
||||||
// LUCENE 4 UPGRADE: better way?
|
// LUCENE 4 UPGRADE: better way?
|
||||||
return Double.parseDouble(term.toUtf8());
|
return Double.parseDouble(term.string());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -113,7 +115,7 @@ public class InternalStringTermsFacet extends InternalTermsFacet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Entry o) {
|
public int compareTo(Entry o) {
|
||||||
int i = BytesReference.utf8SortedAsUnicodeSortOrder.compare(this.term, o.term());
|
int i = this.term.compareTo(o.term());
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
i = count - o.count();
|
i = count - o.count();
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
@ -227,7 +229,7 @@ public class InternalStringTermsFacet extends InternalTermsFacet {
|
||||||
return facets.get(0);
|
return facets.get(0);
|
||||||
}
|
}
|
||||||
InternalStringTermsFacet first = (InternalStringTermsFacet) facets.get(0);
|
InternalStringTermsFacet first = (InternalStringTermsFacet) facets.get(0);
|
||||||
TObjectIntHashMap<BytesReference> aggregated = CacheRecycler.popObjectIntMap();
|
TObjectIntHashMap<Text> aggregated = CacheRecycler.popObjectIntMap();
|
||||||
long missing = 0;
|
long missing = 0;
|
||||||
long total = 0;
|
long total = 0;
|
||||||
for (Facet facet : facets) {
|
for (Facet facet : facets) {
|
||||||
|
@ -240,7 +242,7 @@ public class InternalStringTermsFacet extends InternalTermsFacet {
|
||||||
}
|
}
|
||||||
|
|
||||||
BoundedTreeSet<TermEntry> ordered = new BoundedTreeSet<TermEntry>(first.comparatorType.comparator(), first.requiredSize);
|
BoundedTreeSet<TermEntry> ordered = new BoundedTreeSet<TermEntry>(first.comparatorType.comparator(), first.requiredSize);
|
||||||
for (TObjectIntIterator<BytesReference> it = aggregated.iterator(); it.hasNext(); ) {
|
for (TObjectIntIterator<Text> it = aggregated.iterator(); it.hasNext(); ) {
|
||||||
it.advance();
|
it.advance();
|
||||||
ordered.add(new TermEntry(it.key(), it.value()));
|
ordered.add(new TermEntry(it.key(), it.value()));
|
||||||
}
|
}
|
||||||
|
@ -290,7 +292,7 @@ public class InternalStringTermsFacet extends InternalTermsFacet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
name = in.readUTF();
|
name = in.readString();
|
||||||
comparatorType = ComparatorType.fromId(in.readByte());
|
comparatorType = ComparatorType.fromId(in.readByte());
|
||||||
requiredSize = in.readVInt();
|
requiredSize = in.readVInt();
|
||||||
missing = in.readVLong();
|
missing = in.readVLong();
|
||||||
|
@ -299,7 +301,7 @@ public class InternalStringTermsFacet extends InternalTermsFacet {
|
||||||
int size = in.readVInt();
|
int size = in.readVInt();
|
||||||
entries = new ArrayList<TermEntry>(size);
|
entries = new ArrayList<TermEntry>(size);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
entries.add(new TermEntry(in.readBytesReference(), in.readVInt()));
|
entries.add(new TermEntry(in.readText(), in.readVInt()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,7 +315,7 @@ public class InternalStringTermsFacet extends InternalTermsFacet {
|
||||||
|
|
||||||
out.writeVInt(entries.size());
|
out.writeVInt(entries.size());
|
||||||
for (Entry entry : entries) {
|
for (Entry entry : entries) {
|
||||||
out.writeBytesReference(entry.term());
|
out.writeText(entry.term());
|
||||||
out.writeVInt(entry.count());
|
out.writeVInt(entry.count());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@ public class ScriptTermsStringFieldFacetCollector extends AbstractFacetCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean match(String value) {
|
private boolean match(String value) {
|
||||||
if (excluded != null && excluded.contains(value)) {
|
if (excluded != null && excluded.contains(new BytesRef(value))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (matcher != null && !matcher.reset(value).matches()) {
|
if (matcher != null && !matcher.reset(value).matches()) {
|
||||||
|
|
|
@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import gnu.trove.iterator.TObjectIntIterator;
|
import gnu.trove.iterator.TObjectIntIterator;
|
||||||
import gnu.trove.map.hash.TObjectIntHashMap;
|
import gnu.trove.map.hash.TObjectIntHashMap;
|
||||||
import org.apache.lucene.index.AtomicReader;
|
|
||||||
import org.apache.lucene.index.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
import org.apache.lucene.search.Scorer;
|
import org.apache.lucene.search.Scorer;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.search.facet.termsstats;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
|
import org.elasticsearch.common.text.Text;
|
||||||
import org.elasticsearch.search.facet.Facet;
|
import org.elasticsearch.search.facet.Facet;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -394,9 +395,9 @@ public interface TermsStatsFacet extends Facet, Iterable<TermsStatsFacet.Entry>
|
||||||
|
|
||||||
public interface Entry extends Comparable<Entry> {
|
public interface Entry extends Comparable<Entry> {
|
||||||
|
|
||||||
BytesReference term();
|
Text term();
|
||||||
|
|
||||||
BytesReference getTerm();
|
Text getTerm();
|
||||||
|
|
||||||
Number termAsNumber();
|
Number termAsNumber();
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,10 @@ package org.elasticsearch.search.facet.termsstats.doubles;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import org.elasticsearch.common.CacheRecycler;
|
import org.elasticsearch.common.CacheRecycler;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
|
import org.elasticsearch.common.text.StringText;
|
||||||
|
import org.elasticsearch.common.text.Text;
|
||||||
import org.elasticsearch.common.trove.ExtTDoubleObjectHashMap;
|
import org.elasticsearch.common.trove.ExtTDoubleObjectHashMap;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||||
|
@ -76,12 +76,12 @@ public class InternalTermsStatsDoubleFacet extends InternalTermsStatsFacet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BytesReference term() {
|
public Text term() {
|
||||||
return new BytesArray(Double.toString(term));
|
return new StringText(Double.toString(term));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BytesReference getTerm() {
|
public Text getTerm() {
|
||||||
return term();
|
return term();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,7 +341,7 @@ public class InternalTermsStatsDoubleFacet extends InternalTermsStatsFacet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
name = in.readUTF();
|
name = in.readString();
|
||||||
comparatorType = ComparatorType.fromId(in.readByte());
|
comparatorType = ComparatorType.fromId(in.readByte());
|
||||||
requiredSize = in.readVInt();
|
requiredSize = in.readVInt();
|
||||||
missing = in.readVLong();
|
missing = in.readVLong();
|
||||||
|
@ -355,7 +355,7 @@ public class InternalTermsStatsDoubleFacet extends InternalTermsStatsFacet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeUTF(name);
|
out.writeString(name);
|
||||||
out.writeByte(comparatorType.id());
|
out.writeByte(comparatorType.id());
|
||||||
out.writeVInt(requiredSize);
|
out.writeVInt(requiredSize);
|
||||||
out.writeVLong(missing);
|
out.writeVLong(missing);
|
||||||
|
|
|
@ -21,10 +21,10 @@ package org.elasticsearch.search.facet.termsstats.longs;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import org.elasticsearch.common.CacheRecycler;
|
import org.elasticsearch.common.CacheRecycler;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
|
import org.elasticsearch.common.text.StringText;
|
||||||
|
import org.elasticsearch.common.text.Text;
|
||||||
import org.elasticsearch.common.trove.ExtTLongObjectHashMap;
|
import org.elasticsearch.common.trove.ExtTLongObjectHashMap;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||||
|
@ -76,12 +76,12 @@ public class InternalTermsStatsLongFacet extends InternalTermsStatsFacet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BytesReference term() {
|
public Text term() {
|
||||||
return new BytesArray(Long.toString(term));
|
return new StringText(Long.toString(term));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BytesReference getTerm() {
|
public Text getTerm() {
|
||||||
return term();
|
return term();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ import org.elasticsearch.common.bytes.BytesArray;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
|
import org.elasticsearch.common.text.BytesText;
|
||||||
|
import org.elasticsearch.common.text.Text;
|
||||||
import org.elasticsearch.common.trove.ExtTHashMap;
|
import org.elasticsearch.common.trove.ExtTHashMap;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||||
|
@ -60,7 +62,7 @@ public class InternalTermsStatsStringFacet extends InternalTermsStatsFacet {
|
||||||
|
|
||||||
public static class StringEntry implements Entry {
|
public static class StringEntry implements Entry {
|
||||||
|
|
||||||
BytesReference term;
|
Text term;
|
||||||
long count;
|
long count;
|
||||||
long totalCount;
|
long totalCount;
|
||||||
double total;
|
double total;
|
||||||
|
@ -68,10 +70,10 @@ public class InternalTermsStatsStringFacet extends InternalTermsStatsFacet {
|
||||||
double max;
|
double max;
|
||||||
|
|
||||||
public StringEntry(BytesRef term, long count, long totalCount, double total, double min, double max) {
|
public StringEntry(BytesRef term, long count, long totalCount, double total, double min, double max) {
|
||||||
this(new BytesArray(term), count, totalCount, total, min, max);
|
this(new BytesText(new BytesArray(term)), count, totalCount, total, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringEntry(BytesReference term, long count, long totalCount, double total, double min, double max) {
|
public StringEntry(Text term, long count, long totalCount, double total, double min, double max) {
|
||||||
this.term = term;
|
this.term = term;
|
||||||
this.count = count;
|
this.count = count;
|
||||||
this.totalCount = totalCount;
|
this.totalCount = totalCount;
|
||||||
|
@ -81,18 +83,18 @@ public class InternalTermsStatsStringFacet extends InternalTermsStatsFacet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BytesReference term() {
|
public Text term() {
|
||||||
return term;
|
return term;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BytesReference getTerm() {
|
public Text getTerm() {
|
||||||
return term();
|
return term();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Number termAsNumber() {
|
public Number termAsNumber() {
|
||||||
return Double.parseDouble(term.toUtf8());
|
return Double.parseDouble(term.string());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -164,8 +166,8 @@ public class InternalTermsStatsStringFacet extends InternalTermsStatsFacet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Entry o) {
|
public int compareTo(Entry other) {
|
||||||
return BytesReference.utf8SortedAsUnicodeSortOrder.compare(this.term, o.term());
|
return term.compareTo(other.term());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,7 +259,7 @@ public class InternalTermsStatsStringFacet extends InternalTermsStatsFacet {
|
||||||
return facets.get(0);
|
return facets.get(0);
|
||||||
}
|
}
|
||||||
int missing = 0;
|
int missing = 0;
|
||||||
ExtTHashMap<BytesReference, StringEntry> map = CacheRecycler.popHashMap();
|
ExtTHashMap<Text, StringEntry> map = CacheRecycler.popHashMap();
|
||||||
for (Facet facet : facets) {
|
for (Facet facet : facets) {
|
||||||
InternalTermsStatsStringFacet tsFacet = (InternalTermsStatsStringFacet) facet;
|
InternalTermsStatsStringFacet tsFacet = (InternalTermsStatsStringFacet) facet;
|
||||||
missing += tsFacet.missing;
|
missing += tsFacet.missing;
|
||||||
|
@ -353,7 +355,7 @@ public class InternalTermsStatsStringFacet extends InternalTermsStatsFacet {
|
||||||
int size = in.readVInt();
|
int size = in.readVInt();
|
||||||
entries = new ArrayList<StringEntry>(size);
|
entries = new ArrayList<StringEntry>(size);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
entries.add(new StringEntry(in.readBytesReference(), in.readVLong(), in.readVLong(), in.readDouble(), in.readDouble(), in.readDouble()));
|
entries.add(new StringEntry(in.readText(), in.readVLong(), in.readVLong(), in.readDouble(), in.readDouble(), in.readDouble()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,7 +368,7 @@ public class InternalTermsStatsStringFacet extends InternalTermsStatsFacet {
|
||||||
|
|
||||||
out.writeVInt(entries.size());
|
out.writeVInt(entries.size());
|
||||||
for (Entry entry : entries) {
|
for (Entry entry : entries) {
|
||||||
out.writeBytesReference(entry.term());
|
out.writeText(entry.term());
|
||||||
out.writeVLong(entry.count());
|
out.writeVLong(entry.count());
|
||||||
out.writeVLong(entry.totalCount());
|
out.writeVLong(entry.totalCount());
|
||||||
out.writeDouble(entry.total());
|
out.writeDouble(entry.total());
|
||||||
|
|
Loading…
Reference in New Issue