use of org.alfresco.repo.search.impl.lucene.LuceneSearcher in project alfresco-repository by Alfresco.
the class LuceneQueryEngine method executeQuery.
public QueryEngineResults executeQuery(Query query, QueryOptions options, FunctionEvaluationContext functionContext) {
Set<String> selectorGroup = null;
if (query.getSource() != null) {
List<Set<String>> selectorGroups = query.getSource().getSelectorGroups(functionContext);
if (selectorGroups.size() == 0) {
throw new UnsupportedOperationException("No selectors");
}
if (selectorGroups.size() > 1) {
throw new UnsupportedOperationException("Advanced join is not supported");
}
selectorGroup = selectorGroups.get(0);
}
SearchParameters searchParameters = new SearchParameters();
if (options.getLocales().size() > 0) {
for (Locale locale : options.getLocales()) {
searchParameters.addLocale(locale);
}
}
searchParameters.excludeDataInTheCurrentTransaction(!options.isIncludeInTransactionData());
searchParameters.setSkipCount(options.getSkipCount());
searchParameters.setMaxPermissionChecks(options.getMaxPermissionChecks());
searchParameters.setMaxPermissionCheckTimeMillis(options.getMaxPermissionCheckTimeMillis());
searchParameters.setDefaultFieldName(options.getDefaultFieldName());
searchParameters.setMlAnalaysisMode(options.getMlAnalaysisMode());
if (options.getMaxItems() >= 0) {
searchParameters.setLimitBy(LimitBy.FINAL_SIZE);
searchParameters.setLimit(options.getMaxItems());
searchParameters.setMaxItems(options.getMaxItems());
} else {
searchParameters.setLimitBy(LimitBy.UNLIMITED);
}
searchParameters.setUseInMemorySort(options.getUseInMemorySort());
searchParameters.setMaxRawResultSetSizeForInMemorySort(options.getMaxRawResultSetSizeForInMemorySort());
searchParameters.setBulkFetchEnabled(options.isBulkFetchEnabled());
searchParameters.setQueryConsistency(options.getQueryConsistency());
try {
StoreRef storeRef = options.getStores().get(0);
searchParameters.addStore(storeRef);
if (query instanceof LuceneQueryBuilder) {
SearchService searchService = indexAndSearcher.getSearcher(storeRef, options.isIncludeInTransactionData());
if (searchService instanceof LuceneSearcher) {
LuceneSearcher luceneSearcher = (LuceneSearcher) searchService;
ClosingIndexSearcher searcher = luceneSearcher.getClosingIndexSearcher();
LuceneQueryBuilderContext<org.apache.lucene.search.Query, Sort, ParseException> luceneContext = new LuceneQueryBuilderContextImpl(dictionaryService, namespaceService, tenantService, searchParameters, indexAndSearcher.getDefaultMLSearchAnalysisMode(), searcher.getIndexReader());
@SuppressWarnings("unchecked") LuceneQueryBuilder<org.apache.lucene.search.Query, Sort, ParseException> builder = (LuceneQueryBuilder<org.apache.lucene.search.Query, Sort, ParseException>) query;
org.apache.lucene.search.Query luceneQuery = builder.buildQuery(selectorGroup, luceneContext, functionContext);
if (logger.isDebugEnabled()) {
logger.debug("Executing lucene query: " + luceneQuery);
}
Sort sort = builder.buildSort(selectorGroup, luceneContext, functionContext);
Hits hits = searcher.search(luceneQuery);
boolean postSort = false;
;
if (sort != null) {
postSort = searchParameters.usePostSort(hits.length(), useInMemorySort, maxRawResultSetSizeForInMemorySort);
if (postSort == false) {
hits = searcher.search(luceneQuery, sort);
}
}
ResultSet answer;
ResultSet result = new LuceneResultSet(hits, searcher, nodeService, tenantService, searchParameters, indexAndSearcher);
if (postSort) {
if (sort != null) {
for (SortField sf : sort.getSort()) {
searchParameters.addSort(sf.getField(), !sf.getReverse());
}
}
ResultSet sorted = new SortedResultSet(result, nodeService, builder.buildSortDefinitions(selectorGroup, luceneContext, functionContext), namespaceService, dictionaryService, searchParameters.getSortLocale());
answer = sorted;
} else {
answer = result;
}
ResultSet rs = new PagingLuceneResultSet(answer, searchParameters, nodeService);
Map<Set<String>, ResultSet> map = new HashMap<Set<String>, ResultSet>(1);
map.put(selectorGroup, rs);
return new QueryEngineResults(map);
} else {
throw new UnsupportedOperationException();
}
} else {
throw new UnsupportedOperationException();
}
} catch (ParseException e) {
throw new SearcherException("Failed to parse query: " + e);
} catch (IOException e) {
throw new SearcherException("IO exception during search", e);
}
}
Aggregations