Search in sources :

Example 1 with SortableField

use of org.hibernate.search.annotations.SortableField in project pyramus by otavanopisto.

the class Person method getLastNameSortable.

@Transient
@Field(analyze = Analyze.NO, store = Store.NO)
@SortableField
public String getLastNameSortable() {
    Student student = getLatestStudent();
    StaffMember staffMember = getStaffMember();
    return student != null ? student.getLastName() : staffMember != null ? staffMember.getLastName() : "";
}
Also used : Student(fi.otavanopisto.pyramus.domainmodel.students.Student) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) SortableField(org.hibernate.search.annotations.SortableField) Field(org.hibernate.search.annotations.Field) SortableField(org.hibernate.search.annotations.SortableField) Transient(javax.persistence.Transient)

Example 2 with SortableField

use of org.hibernate.search.annotations.SortableField in project pyramus by otavanopisto.

the class Person method getFirstNameSortable.

@Transient
@Field(analyze = Analyze.NO, store = Store.NO)
@SortableField
public String getFirstNameSortable() {
    Student student = getLatestStudent();
    StaffMember staffMember = getStaffMember();
    return student != null ? student.getFirstName() : staffMember != null ? staffMember.getFirstName() : "";
}
Also used : Student(fi.otavanopisto.pyramus.domainmodel.students.Student) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) SortableField(org.hibernate.search.annotations.SortableField) Field(org.hibernate.search.annotations.Field) SortableField(org.hibernate.search.annotations.SortableField) Transient(javax.persistence.Transient)

Example 3 with SortableField

use of org.hibernate.search.annotations.SortableField in project elide by yahoo.

the class SearchDataTransaction method buildSort.

/**
 * Builds a lucene Sort object from and Elide Sorting object.
 * @param sorting Elide sorting object
 * @param entityType The entity being sorted.
 * @return A lucene Sort object
 */
private Sort buildSort(Sorting sorting, Type<?> entityType) {
    Class<?> entityClass = null;
    if (entityType != null) {
        Preconditions.checkState(entityType instanceof ClassType);
        entityClass = ((ClassType) entityType).getCls();
    }
    QueryBuilder builder = em.getSearchFactory().buildQueryBuilder().forEntity(entityClass).get();
    SortFieldContext context = null;
    for (Map.Entry<Path, Sorting.SortOrder> entry : sorting.getSortingPaths().entrySet()) {
        String fieldName = entry.getKey().lastElement().get().getFieldName();
        SortableField sortableField = dictionary.getAttributeOrRelationAnnotation(entityType, SortableField.class, fieldName);
        fieldName = sortableField.forField().isEmpty() ? fieldName : sortableField.forField();
        if (context == null) {
            context = builder.sort().byField(fieldName);
        } else {
            context.andByField(fieldName);
        }
        Sorting.SortOrder order = entry.getValue();
        if (order == Sorting.SortOrder.asc) {
            context = context.asc();
        } else {
            context = context.desc();
        }
    }
    if (context == null) {
        throw new IllegalStateException("Invalid Sort rules");
    }
    return context.createSort();
}
Also used : Path(com.yahoo.elide.core.Path) SortableField(org.hibernate.search.annotations.SortableField) QueryBuilder(org.hibernate.search.query.dsl.QueryBuilder) ClassType(com.yahoo.elide.core.type.ClassType) Sorting(com.yahoo.elide.core.request.Sorting) SortFieldContext(org.hibernate.search.query.dsl.sort.SortFieldContext) Map(java.util.Map)

Aggregations

SortableField (org.hibernate.search.annotations.SortableField)3 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)2 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)2 Transient (javax.persistence.Transient)2 Field (org.hibernate.search.annotations.Field)2 Path (com.yahoo.elide.core.Path)1 Sorting (com.yahoo.elide.core.request.Sorting)1 ClassType (com.yahoo.elide.core.type.ClassType)1 Map (java.util.Map)1 QueryBuilder (org.hibernate.search.query.dsl.QueryBuilder)1 SortFieldContext (org.hibernate.search.query.dsl.sort.SortFieldContext)1