use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class SolrOpenCMISQueryServiceImpl method query.
@Override
public CMISResultSet query(CMISQueryOptions options) {
SearchParameters searchParameters = options.getAsSearchParmeters();
searchParameters.addExtraParameter("cmisVersion", options.getCmisVersion().toString());
ResultSet rs = solrQueryLanguage.executeQuery(searchParameters);
CapabilityJoin joinSupport = getJoinSupport();
if (options.getQueryMode() == CMISQueryOptions.CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS) {
joinSupport = CapabilityJoin.INNERANDOUTER;
}
// TODO: Refactor to avoid duplication of valid scopes here and in CMISQueryParser
BaseTypeId[] validScopes = (options.getQueryMode() == CMISQueryMode.CMS_STRICT) ? CmisFunctionEvaluationContext.STRICT_SCOPES : CmisFunctionEvaluationContext.ALFRESCO_SCOPES;
CmisFunctionEvaluationContext functionContext = new CmisFunctionEvaluationContext();
functionContext.setCmisDictionaryService(cmisDictionaryService);
functionContext.setNodeService(nodeService);
functionContext.setValidScopes(validScopes);
CMISQueryParser parser = new CMISQueryParser(options, cmisDictionaryService, joinSupport);
Query query = parser.parse(new LuceneQueryModelFactory(), functionContext);
Map<String, ResultSet> wrapped = new HashMap<String, ResultSet>();
for (Set<String> group : query.getSource().getSelectorGroups(functionContext)) {
for (String selector : group) {
wrapped.put(selector, rs);
}
}
LimitBy limitBy = null;
limitBy = rs.getResultSetMetaData().getLimitedBy();
CMISResultSet cmis = new CMISResultSet(wrapped, options, limitBy, nodeService, query, cmisDictionaryService, alfrescoDictionaryService);
return cmis;
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class DbCmisQueryLanguage method executeQueryImpl.
private ResultSet executeQueryImpl(SearchParameters searchParameters) {
CMISQueryOptions options = CMISQueryOptions.create(searchParameters);
options.setQueryMode(CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS);
CapabilityJoin joinSupport = CapabilityJoin.INNERANDOUTER;
BaseTypeId[] validScopes = CmisFunctionEvaluationContext.ALFRESCO_SCOPES;
CmisFunctionEvaluationContext functionContext = new CmisFunctionEvaluationContext();
functionContext.setCmisDictionaryService(cmisDictionaryService);
functionContext.setValidScopes(validScopes);
CMISQueryParser parser = new CMISQueryParser(options, cmisDictionaryService, joinSupport);
org.alfresco.repo.search.impl.querymodel.Query queryModelQuery = parser.parse(new DBQueryModelFactory(), functionContext);
// TODO: Remove as this appears to be dead code
// // build lucene query
// Set<String> selectorGroup = null;
// if (queryModelQuery.getSource() != null)
// {
// List<Set<String>> selectorGroups = queryModelQuery.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);
// }
//
QueryEngineResults results = queryEngine.executeQuery(queryModelQuery, options, functionContext);
ResultSet resultSet = results.getResults().values().iterator().next();
return resultSet;
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class DbOrIndexSwitchingQueryLanguage method executeQuery.
public ResultSet executeQuery(SearchParameters searchParameters) {
QueryConsistency consistency = searchParameters.getQueryConsistency();
if (consistency == QueryConsistency.DEFAULT) {
consistency = queryConsistency;
}
switch(consistency) {
case EVENTUAL:
if (indexQueryLanguage != null) {
if (logger.isDebugEnabled()) {
logger.debug("Using SOLR query: " + dbQueryLanguage.getName() + " for " + searchParameters);
}
StopWatch stopWatch = new StopWatch("index only");
stopWatch.start();
ResultSet results = indexQueryLanguage.executeQuery(searchParameters);
stopWatch.stop();
if (logger.isDebugEnabled()) {
logger.debug("SOLR returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms");
}
return results;
} else {
throw new QueryModelException("No query language available");
}
case TRANSACTIONAL:
if (dbQueryLanguage != null) {
if (logger.isDebugEnabled()) {
logger.debug("Trying db query for " + dbQueryLanguage.getName() + " for " + searchParameters);
}
StopWatch stopWatch = new StopWatch("database only");
stopWatch.start();
ResultSet results = dbQueryLanguage.executeQuery(flattenDBQuery(searchParameters));
stopWatch.stop();
if (logger.isDebugEnabled()) {
logger.debug("DB returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms");
}
return results;
} else {
throw new QueryModelException("No query language available");
}
case HYBRID:
if (!hybridEnabled) {
throw new DisabledFeatureException("Hybrid query is disabled.");
}
return executeHybridQuery(searchParameters);
case DEFAULT:
case TRANSACTIONAL_IF_POSSIBLE:
default:
StopWatch stopWatch = new StopWatch("DB if possible");
// SEARCH-347, exclude TMDQ calls if faceting present.
if (dbQueryLanguage != null && !searchParameters.hasFaceting()) {
try {
if (logger.isDebugEnabled()) {
logger.debug("Trying db query for " + dbQueryLanguage.getName() + " for " + searchParameters);
}
stopWatch.start();
ResultSet results = dbQueryLanguage.executeQuery(flattenDBQuery(searchParameters));
stopWatch.stop();
if (logger.isDebugEnabled()) {
logger.debug("DB returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms");
}
return results;
} catch (QueryModelException qme) {
if (stopWatch.isRunning()) {
stopWatch.stop();
}
// MNT-10323: Logging configuration on JBoss leads to clogging of the log with a lot of these errors because of INFO level when WQS module is installed
if (logger.isDebugEnabled()) {
logger.debug("DB query failed for " + dbQueryLanguage.getName() + " for " + searchParameters, qme);
}
if (indexQueryLanguage != null) {
if (logger.isDebugEnabled()) {
logger.debug("Using SOLR query: " + dbQueryLanguage.getName() + " for " + searchParameters);
}
stopWatch.start();
ResultSet results = indexQueryLanguage.executeQuery(searchParameters);
stopWatch.stop();
if (logger.isDebugEnabled()) {
logger.debug("SOLR returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms");
}
return results;
}
}
} else {
if (indexQueryLanguage != null) {
if (logger.isDebugEnabled()) {
logger.debug("(No DB QL) Using SOLR query: " + "dbQueryLanguage==null" + " for " + searchParameters);
}
stopWatch.start();
ResultSet results = indexQueryLanguage.executeQuery(searchParameters);
stopWatch.stop();
if (logger.isDebugEnabled()) {
logger.debug("SOLR returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms");
}
return results;
}
}
throw new QueryModelException("No query language available");
}
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class AuditMethodInterceptorTest method testAuditSearchServiceQuery.
/**
* Test for <a href="https://issues.alfresco.com/jira/browse/MNT-16748">MNT-16748</a> <br>
* Use {@link SearchService#query(StoreRef, String, String)} to perform a query.
*/
public void testAuditSearchServiceQuery() throws Exception {
// Run as admin
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
// Perform a search
@SuppressWarnings("unused") ResultSet rs = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<ResultSet>() {
@Override
public ResultSet execute() throws Throwable {
return searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, "/app:company_home");
}
}, true, false);
// Check the audit entries
checkAuditEntries(APPLICATION_NAME_MNT_16748, SearchService.LANGUAGE_XPATH, "/app:company_home", 1);
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class PersonServiceImpl method getPeopleFtsList.
private List<NodeRef> getPeopleFtsList(String pattern, PagingRequest pagingRequest) throws Throwable {
// Think this code is based on org.alfresco.repo.jscript.People.getPeopleImplSearch(String, StringTokenizer, int, int)
List<NodeRef> people = null;
SearchParameters params = new SearchParameters();
params.addQueryTemplate("_PERSON", "|%firstName OR |%lastName OR |%userName");
params.setDefaultFieldName("_PERSON");
StringBuilder query = new StringBuilder(256);
query.append("TYPE:\"").append(ContentModel.TYPE_PERSON).append("\" AND (");
StringTokenizer t = new StringTokenizer(pattern, " ");
if (t.countTokens() == 1) {
// fts-alfresco property search i.e. location:"maidenhead"
query.append('"').append(pattern).append("*\"");
} else {
// multiple terms supplied - look for first and second name etc.
// assume first term is first name, any more are second i.e.
// "Fraun van de Wiels"
// also allow fts-alfresco property search to reduce results
params.setDefaultOperator(SearchParameters.Operator.AND);
StringBuilder multiPartNames = new StringBuilder(pattern.length());
int numOfTokens = t.countTokens();
int counter = 1;
String term = null;
// MNT-8539, in order to support firstname and lastname search
while (t.hasMoreTokens()) {
term = t.nextToken();
// firstName and lastName
if (term.endsWith("*")) {
term = term.substring(0, term.lastIndexOf("*"));
}
multiPartNames.append("\"");
multiPartNames.append(term);
multiPartNames.append("*\"");
if (numOfTokens > counter) {
multiPartNames.append(' ');
}
counter++;
}
// name and "lewis martinez" is the last name.
if (multiPartNames.length() > 0) {
query.append("firstName:");
query.append(multiPartNames);
query.append(" OR lastName:");
query.append(multiPartNames);
}
}
query.append(")");
// define the search parameters
params.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
params.addStore(this.storeRef);
params.setQuery(query.toString());
if (pagingRequest.getMaxItems() > 0) {
params.setLimitBy(LimitBy.FINAL_SIZE);
params.setLimit(pagingRequest.getMaxItems());
}
ResultSet results = null;
try {
results = searchService.query(params);
people = results.getNodeRefs();
} catch (Throwable err) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to execute people search: " + query.toString(), err);
}
throw err;
} finally {
if (results != null) {
results.close();
}
}
return people;
}
Aggregations