Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query sort type problem #26

Open
jmrenouard opened this issue Dec 13, 2011 · 0 comments
Open

Query sort type problem #26

jmrenouard opened this issue Dec 13, 2011 · 0 comments

Comments

@jmrenouard
Copy link

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant