allExactMatch &= attr.isExactMatch();
}
QueryContext queryContext = new QueryContext(query);
IndexHits hits = null;
if (sortKey != null) {
Integer sortType = sortKey.getSortType();
if (sortType != null) {
queryContext.sort(new Sort(new SortField(sortKey.dbName(), sortType, sortDescending)));
} else {
queryContext.sort(new Sort(new SortField(sortKey.dbName(), Locale.getDefault(), sortDescending)));
}
}
if (distanceSearch != null) {
if (coords != null) {
Map<String, Object> params = new HashMap<>();
params.put(LayerNodeIndex.POINT_PARAMETER, coords.toArray());
params.put(LayerNodeIndex.DISTANCE_IN_KM_PARAMETER, dist);
LayerNodeIndex spatialIndex = this.getSpatialIndex();
if (spatialIndex != null) {
synchronized (spatialIndex) {
hits = spatialIndex.query(LayerNodeIndex.WITHIN_DISTANCE_QUERY, params);
}
}
}
// instantiate spatial search results without paging,
// as the results must be filtered by type anyway
intermediateResult = new NodeFactory(securityContext).instantiate(hits);
} else if (allExactMatch) {
index = getKeywordIndex();
synchronized (index) {
try {
hits = index.query(queryContext);
} catch (NumberFormatException nfe) {
logger.log(Level.SEVERE, "Could not sort results", nfe);
// retry without sorting
queryContext.sort(null);
hits = index.query(queryContext);
}
}
// all luecene query, do not filter results
filterResults = hasEmptySearchFields;
intermediateResult = factory.instantiate(hits);
} else {
// Default: Mixed or fulltext-only search: Use fulltext index
index = getFulltextIndex();
synchronized (index) {
try {
hits = index.query(queryContext);
} catch (NumberFormatException nfe) {
logger.log(Level.SEVERE, "Could not sort results", nfe);
// retry without sorting
queryContext.sort(null);
hits = index.query(queryContext);
}
}
// all luecene query, do not filter results
filterResults = hasEmptySearchFields;
intermediateResult = factory.instantiate(hits);
}
if (hits != null) {
hits.close();
}
}
if (filterResults) {