lucene 4: optimize bytes on XContentParser
also, does not seem like we need to reuse bytes buffer, if we need to, we can always add it later
This commit is contained in:
parent
19ab1d0548
commit
e75301b781
|
@ -19,12 +19,12 @@
|
|||
|
||||
package org.elasticsearch.common.xcontent;
|
||||
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -130,10 +130,10 @@ public interface XContentParser extends Closeable {
|
|||
String text() throws IOException;
|
||||
|
||||
String textOrNull() throws IOException;
|
||||
|
||||
BytesRef bytesOrNull(BytesRef spare) throws IOException;
|
||||
|
||||
BytesRef bytes(BytesRef spare) throws IOException;
|
||||
|
||||
BytesRef bytesOrNull() throws IOException;
|
||||
|
||||
BytesRef bytes() throws IOException;
|
||||
|
||||
boolean hasTextCharacters();
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.common.xcontent.support;
|
||||
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.UnicodeUtil;
|
||||
import org.elasticsearch.common.Booleans;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
|
@ -106,26 +107,21 @@ public abstract class AbstractXContentParser implements XContentParser {
|
|||
}
|
||||
return text();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public BytesRef bytesOrNull(BytesRef spare) throws IOException {
|
||||
if (currentToken() == Token.VALUE_NULL) {
|
||||
return null;
|
||||
}
|
||||
return bytes(spare);
|
||||
public BytesRef bytesOrNull() throws IOException {
|
||||
if (currentToken() == Token.VALUE_NULL) {
|
||||
return null;
|
||||
}
|
||||
return bytes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BytesRef bytes(BytesRef spare) throws IOException {
|
||||
// LUCENE 4 UPGRADE: we can possibly make this more efficient for now I just forward to text
|
||||
if (spare == null) {
|
||||
return new BytesRef(text());
|
||||
} else {
|
||||
spare.copyChars(text());
|
||||
return spare;
|
||||
}
|
||||
public BytesRef bytes() throws IOException {
|
||||
BytesRef bytes = new BytesRef();
|
||||
UnicodeUtil.UTF16toUTF8(textCharacters(), textOffset(), textLength(), bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -72,24 +72,24 @@ public class RangeFilterParser implements FilterParser {
|
|||
currentFieldName = parser.currentName();
|
||||
} else {
|
||||
if ("from".equals(currentFieldName)) {
|
||||
from = parser.bytesOrNull(from);
|
||||
from = parser.bytesOrNull();
|
||||
} else if ("to".equals(currentFieldName)) {
|
||||
to = parser.bytesOrNull(to);
|
||||
to = parser.bytesOrNull();
|
||||
} else if ("include_lower".equals(currentFieldName) || "includeLower".equals(currentFieldName)) {
|
||||
includeLower = parser.booleanValue();
|
||||
} else if ("include_upper".equals(currentFieldName) || "includeUpper".equals(currentFieldName)) {
|
||||
includeUpper = parser.booleanValue();
|
||||
} else if ("gt".equals(currentFieldName)) {
|
||||
from = parser.bytesOrNull(from);
|
||||
from = parser.bytesOrNull();
|
||||
includeLower = false;
|
||||
} else if ("gte".equals(currentFieldName) || "ge".equals(currentFieldName)) {
|
||||
from = parser.bytesOrNull(from);
|
||||
from = parser.bytesOrNull();
|
||||
includeLower = true;
|
||||
} else if ("lt".equals(currentFieldName)) {
|
||||
to = parser.bytesOrNull(to);
|
||||
to = parser.bytesOrNull();
|
||||
includeUpper = false;
|
||||
} else if ("lte".equals(currentFieldName) || "le".equals(currentFieldName)) {
|
||||
to = parser.bytesOrNull(to);
|
||||
to = parser.bytesOrNull();
|
||||
includeUpper = true;
|
||||
} else {
|
||||
throw new QueryParsingException(parseContext.index(), "[range] filter does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -72,9 +72,9 @@ public class RangeQueryParser implements QueryParser {
|
|||
currentFieldName = parser.currentName();
|
||||
} else {
|
||||
if ("from".equals(currentFieldName)) {
|
||||
from = parser.bytesOrNull(from);
|
||||
from = parser.bytesOrNull();
|
||||
} else if ("to".equals(currentFieldName)) {
|
||||
to = parser.bytesOrNull(to);
|
||||
to = parser.bytesOrNull();
|
||||
} else if ("include_lower".equals(currentFieldName) || "includeLower".equals(currentFieldName)) {
|
||||
includeLower = parser.booleanValue();
|
||||
} else if ("include_upper".equals(currentFieldName) || "includeUpper".equals(currentFieldName)) {
|
||||
|
@ -82,16 +82,16 @@ public class RangeQueryParser implements QueryParser {
|
|||
} else if ("boost".equals(currentFieldName)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("gt".equals(currentFieldName)) {
|
||||
from = parser.bytesOrNull(from);
|
||||
from = parser.bytesOrNull();
|
||||
includeLower = false;
|
||||
} else if ("gte".equals(currentFieldName) || "ge".equals(currentFieldName)) {
|
||||
from = parser.bytesOrNull(from);
|
||||
from = parser.bytesOrNull();
|
||||
includeLower = true;
|
||||
} else if ("lt".equals(currentFieldName)) {
|
||||
to = parser.bytesOrNull(to);
|
||||
to = parser.bytesOrNull();
|
||||
includeUpper = false;
|
||||
} else if ("lte".equals(currentFieldName) || "le".equals(currentFieldName)) {
|
||||
to = parser.bytesOrNull(to);
|
||||
to = parser.bytesOrNull();
|
||||
includeUpper = true;
|
||||
} else {
|
||||
throw new QueryParsingException(parseContext.index(), "[range] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -59,7 +59,7 @@ public class TypeFilterParser implements FilterParser {
|
|||
if (token != XContentParser.Token.VALUE_STRING) {
|
||||
throw new QueryParsingException(parseContext.index(), "[type] filter should have a value field, and the type name");
|
||||
}
|
||||
BytesRef type = parser.bytes(null);
|
||||
BytesRef type = parser.bytes();
|
||||
// move to the next token
|
||||
parser.nextToken();
|
||||
|
||||
|
|
Loading…
Reference in New Issue