API Change: search sort
This commit is contained in:
parent
3a59397306
commit
7c93c1915f
|
@ -85,25 +85,43 @@ public class SortParseElement implements SearchParseElement {
|
||||||
boolean reverse = false;
|
boolean reverse = false;
|
||||||
String innerJsonName = null;
|
String innerJsonName = null;
|
||||||
int type = -1;
|
int type = -1;
|
||||||
while ((token = jp.nextToken()) != JsonToken.END_OBJECT) {
|
token = jp.nextToken();
|
||||||
if (token == JsonToken.FIELD_NAME) {
|
if (token == JsonToken.VALUE_STRING) {
|
||||||
innerJsonName = jp.getCurrentName();
|
String direction = jp.getText();
|
||||||
} else if (token == JsonToken.VALUE_STRING) {
|
if (direction.equals("asc")) {
|
||||||
if ("type".equals(innerJsonName)) {
|
if ("score".equals(fieldName)) {
|
||||||
type = sortFieldTypesMapper.get(jp.getText());
|
|
||||||
if (type == -1) {
|
|
||||||
throw new SearchParseException(context, "No sort type for [" + jp.getText() + "] with field [" + fieldName + "]");
|
|
||||||
}
|
|
||||||
} else if ("reverse".equals(innerJsonName)) {
|
|
||||||
reverse = Booleans.parseBoolean(jp.getText(), reverse);
|
|
||||||
}
|
|
||||||
} 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;
|
reverse = true;
|
||||||
|
} else {
|
||||||
|
reverse = false;
|
||||||
|
}
|
||||||
|
} else if (direction.equals("desc")) {
|
||||||
|
if ("score".equals(fieldName)) {
|
||||||
|
reverse = false;
|
||||||
|
} else {
|
||||||
|
reverse = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while ((token = jp.nextToken()) != JsonToken.END_OBJECT) {
|
||||||
|
if (token == JsonToken.FIELD_NAME) {
|
||||||
|
innerJsonName = jp.getCurrentName();
|
||||||
|
} else if (token == JsonToken.VALUE_STRING) {
|
||||||
|
if ("type".equals(innerJsonName)) {
|
||||||
|
type = sortFieldTypesMapper.get(jp.getText());
|
||||||
|
if (type == -1) {
|
||||||
|
throw new SearchParseException(context, "No sort type for [" + jp.getText() + "] with field [" + fieldName + "]");
|
||||||
|
}
|
||||||
|
} else if ("reverse".equals(innerJsonName)) {
|
||||||
|
reverse = Booleans.parseBoolean(jp.getText(), reverse);
|
||||||
|
}
|
||||||
|
} 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue