Accept also 0 int number to indicate false, and any other number to indicate true (on top of accepting json boolean type), closes #26.

This commit is contained in:
kimchy 2010-02-20 02:13:06 +02:00
parent 4806df426a
commit 3f045dee1f
7 changed files with 47 additions and 7 deletions

View File

@ -89,6 +89,10 @@ public class BoolJsonQueryParser extends AbstractIndexComponent implements JsonQ
if ("disableCoord".equals(currentFieldName)) {
disableCoord = token == JsonToken.VALUE_TRUE;
}
} else if (token == JsonToken.VALUE_NUMBER_INT) {
if ("disableCoord".equals(currentFieldName)) {
disableCoord = jp.getIntValue() != 0;
}
} else {
if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();

View File

@ -117,6 +117,12 @@ public class QueryStringJsonQueryParser extends AbstractIndexComponent implement
fuzzyMinSim = jp.getFloatValue();
} else if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
} else if ("allowLeadingWildcard".equals(currentFieldName)) {
allowLeadingWildcard = jp.getIntValue() != 0;
} else if ("lowercaseExpandedTerms".equals(currentFieldName)) {
lowercaseExpandedTerms = jp.getIntValue() != 0;
} else if ("enablePositionIncrements".equals(currentFieldName)) {
enablePositionIncrements = jp.getIntValue() != 0;
}
}
}

View File

@ -84,12 +84,20 @@ public class RangeJsonFilterParser extends AbstractIndexComponent implements Jso
to = jp.getText();
}
} else if ("includeLower".equals(currentFieldName)) {
if (token == JsonToken.VALUE_NUMBER_INT) {
includeLower = jp.getIntValue() != 0;
} else {
includeLower = token == JsonToken.VALUE_TRUE;
}
} else if ("includeUpper".equals(currentFieldName)) {
if (token == JsonToken.VALUE_NUMBER_INT) {
includeUpper = jp.getIntValue() != 0;
} else {
includeUpper = token == JsonToken.VALUE_TRUE;
}
}
}
}
// move to the next end object, to close the field name
token = jp.nextToken();

View File

@ -81,9 +81,17 @@ public class RangeJsonQueryParser extends AbstractIndexComponent implements Json
to = jp.getText();
}
} else if ("includeLower".equals(currentFieldName)) {
if (token == JsonToken.VALUE_NUMBER_INT) {
includeLower = jp.getIntValue() != 0;
} else {
includeLower = token == JsonToken.VALUE_TRUE;
}
} else if ("includeUpper".equals(currentFieldName)) {
if (token == JsonToken.VALUE_NUMBER_INT) {
includeUpper = jp.getIntValue() != 0;
} else {
includeUpper = token == JsonToken.VALUE_TRUE;
}
} else if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
}

View File

@ -82,11 +82,17 @@ public class SpanNearJsonQueryParser extends AbstractIndexComponent implements J
} else if ("collectPayloads".equals(currentFieldName)) {
collectPayloads = token == JsonToken.VALUE_TRUE;
}
} else if (token == JsonToken.VALUE_NUMBER_INT) {
if ("inOrder".equals(currentFieldName)) {
inOrder = jp.getIntValue() != 0;
} else if ("collectPayloads".equals(currentFieldName)) {
collectPayloads = jp.getIntValue() != 0;
} else if ("slop".equals(currentFieldName)) {
slop = jp.getIntValue();
}
} else {
if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
} else if ("slop".equals(currentFieldName)) {
slop = jp.getIntValue();
}
}
}

View File

@ -30,6 +30,10 @@ import org.elasticsearch.search.internal.SearchContext;
public class ExplainParseElement implements SearchParseElement {
@Override public void parse(JsonParser jp, SearchContext context) throws Exception {
if (jp.getCurrentToken() == JsonToken.VALUE_NUMBER_INT) {
context.explain(jp.getIntValue() != 0);
} else {
context.explain(jp.getCurrentToken() == JsonToken.VALUE_TRUE);
}
}
}

View File

@ -68,6 +68,10 @@ public class SortParseElement implements SearchParseElement {
while ((token = jp.nextToken()) != JsonToken.END_OBJECT) {
if (token == JsonToken.FIELD_NAME) {
innerJsonName = jp.getCurrentName();
} else if (token == JsonToken.VALUE_NUMBER_INT) {
if ("reverse".equals(innerJsonName)) {
reverse = jp.getIntValue() != 0;
}
} else if (token == JsonToken.VALUE_TRUE) {
if ("reverse".equals(innerJsonName)) {
reverse = true;