jfp/play-search — Issue #26: Query sort type problem
Author: jmrenouard
Created: 2011-12-13 16:49:46+00:00
State: open

Hello,
String class is not declared in the getSortType method from the class ConvertionUtils.java

So, when you want to sort string you sort by score ( the default sort stategy).

We have a problem with the String sort type and this code help us to fix the problem.

public static int getSortType(Class clazz, String field)
throws SearchException {
java.lang.reflect.Field fi;
try {
fi = clazz.getField(field);
} catch (Exception e) {
String tok=field.substring(0, field.indexOf('_'));

if (tok.equals(field))throw new SearchException("The field " + field
+ " is not found on class " + clazz);

return getSortType(clazz, tok);
}
Class type = fi.getType();
if (type.equals(String.class))
return SortField.STRING_VAL;
if (type.equals(long.class) || type.equals(Long.class))
return SortField.LONG;
if (type.equals(int.class) || type.equals(Integer.class))
return SortField.INT;
if (type.equals(double.class) || type.equals(Double.class))
return SortField.DOUBLE;
if (type.equals(float.class) || type.equals(Float.class))
return SortField.FLOAT;
if (type.equals(short.class) || type.equals(Short.class))
return SortField.SHORT;
if (type.equals(byte.class) || type.equals(Byte.class))
return SortField.BYTE;
return SortField.SCORE;
}