@Override public DocumentModel getSearchDocumentModel() { if (searchDocumentModel == null) { if (searchDocumentModelBinding != null) { // initialize from binding FacesContext context = FacesContext.getCurrentInstance(); Object value = ComponentTagUtils.resolveElExpression(context, searchDocumentModelBinding); if (value != null && !(value instanceof DocumentModel)) { log.error( "Error processing expression '" + searchDocumentModelBinding + "', result is not a DocumentModel: " + value); } else { setSearchDocumentModel((DocumentModel) value); } } if (searchDocumentModel == null) { // generate a bare document model of given type String docType = getSearchDocumentModelType(); if (docType != null) { DocumentModel bareDoc = DocumentModelFactory.createDocumentModel(docType); setSearchDocumentModel(bareDoc); } } } return searchDocumentModel; }
@Override public DocumentModelList query( String query, String queryType, QueryFilter queryFilter, long countUpTo) throws QueryException { try { // do ORDER BY ecm:path by hand in SQLQueryResult as we can't // do it in SQL (and has to do limit/offset as well) Boolean orderByPath; Matcher matcher = ORDER_BY_PATH_ASC.matcher(query); if (matcher.matches()) { orderByPath = Boolean.TRUE; // ASC } else { matcher = ORDER_BY_PATH_DESC.matcher(query); if (matcher.matches()) { orderByPath = Boolean.FALSE; // DESC } else { orderByPath = null; } } long limit = 0; long offset = 0; if (orderByPath != null) { query = matcher.group(1); limit = queryFilter.getLimit(); offset = queryFilter.getOffset(); queryFilter = QueryFilter.withoutLimitOffset(queryFilter); } PartialList<Serializable> pl = session.query(query, queryType, queryFilter, countUpTo); List<Serializable> ids = pl.list; // get Documents in bulk List<Document> docs = getDocumentsById(ids); // build DocumentModels from Documents String[] schemas = {"common"}; List<DocumentModel> list = new ArrayList<DocumentModel>(ids.size()); for (Document doc : docs) { list.add(DocumentModelFactory.createDocumentModel(doc, schemas)); } // order / limit if (orderByPath != null) { Collections.sort(list, new PathComparator(orderByPath.booleanValue())); } if (limit != 0) { // do limit/offset by hand int size = list.size(); list.subList(0, (int) (offset > size ? size : offset)).clear(); size = list.size(); if (limit < size) { list.subList((int) limit, size).clear(); } } return new DocumentModelListImpl(list, pl.totalSize); } catch (QueryParseException e) { throw new QueryException(e.getMessage() + ": " + query, e); } }