};
SearchManager searchManager = Search.getSearchManager(cache);
IspnLuceneProcessingChain processingChain = new IspnLuceneProcessingChain((SearchFactoryIntegrator) searchManager.getSearchFactory(), entityNamesResolver, null);
QueryParser queryParser = new QueryParser();
IspnLuceneQueryParsingResult parsingResult = queryParser.parseQuery(request.getJpqlString(), processingChain);
Sort sort = null;
if (request.getSortCriteria() != null && !request.getSortCriteria().isEmpty()) {
SortField[] sortField = new SortField[request.getSortCriteria().size()];
int i = 0;
for (QueryRequest.SortCriteria sc : request.getSortCriteria()) {
//TODO [anistor] sort type is not properly handled right now
int sortType = SortField.STRING;
Descriptors.FieldDescriptor field = parsingResult.getTargetType().findFieldByName(sc.getAttributePath());
if (field != null) {
switch (field.getJavaType()) {
case INT:
case BOOLEAN:
case ENUM:
sortType = SortField.INT;
break;
case LONG:
sortType = SortField.LONG;
break;
case FLOAT:
sortType = SortField.FLOAT;
break;
case DOUBLE:
sortType = SortField.DOUBLE;
break;
}
}
sortField[i++] = new SortField(sc.getAttributePath(), sortType, !sc.isAscending());
}
sort = new Sort(sortField);
}
QueryBuilder qb = searchManager.getSearchFactory().buildQueryBuilder().forEntity(parsingResult.getTargetEntity()).get();
Query q = qb.bool()
.must(qb.keyword().onField(TYPE_FIELD_NAME).ignoreFieldBridge().matching(parsingResult.getTargetType().getFullName()).createQuery())
.must(parsingResult.getQuery())
.createQuery();
CacheQuery cacheQuery = searchManager.getQuery(q, parsingResult.getTargetEntity());
if (sort != null) {
cacheQuery = cacheQuery.sort(sort);
}
int projSize = 0;
if (parsingResult.getProjections() != null && !parsingResult.getProjections().isEmpty()) {
projSize = parsingResult.getProjections().size();
cacheQuery.projection(parsingResult.getProjections().toArray(new String[projSize]));
}
if (request.getStartOffset() > 0) {
cacheQuery.firstResult((int) request.getStartOffset());
}
if (request.getMaxResults() > 0) {