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() : "";
}
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() : "";
}
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();
}
Aggregations