public long count() {
return createQuery(true).getResultSize();
}
private FullTextQuery createQuery(boolean forCount) {
QueryMetadata metadata = queryMixin.getMetadata();
org.apache.lucene.search.Query query;
if (metadata.getWhere() != null) {
query = serializer.toQuery(metadata.getWhere(), metadata);
} else {
query = new MatchAllDocsQuery();
}
FullTextQuery fullTextQuery = session.createFullTextQuery(query, path.getType());
// order
if (!metadata.getOrderBy().isEmpty() && !forCount) {
fullTextQuery.setSort(serializer.toSort(metadata.getOrderBy()));
}
// paging
QueryModifiers modifiers = metadata.getModifiers();
if (modifiers != null && modifiers.isRestricting() && !forCount) {
Integer limit = modifiers.getLimitAsInteger();
Integer offset = modifiers.getOffsetAsInteger();
if (limit != null) {
fullTextQuery.setMaxResults(limit.intValue());