use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-repository by Alfresco.
the class SolrClientUtil method extractMapping.
public static SolrStoreMappingWrapper extractMapping(StoreRef store, HashMap<StoreRef, SolrStoreMappingWrapper> mappingLookup, ShardRegistry shardRegistry, boolean useDynamicShardRegistration, BeanFactory beanFactory) {
if ((shardRegistry != null) && useDynamicShardRegistration) {
SearchParameters sp = new SearchParameters();
sp.addStore(store);
List<ShardInstance> slice = shardRegistry.getIndexSlice(sp);
if ((slice == null) || (slice.size() == 0)) {
logger.error("No available shards for solr query of store " + store + " - trying non-dynamic configuration");
SolrStoreMappingWrapper mappings = mappingLookup.get(store);
if (mappings == null) {
throw new LuceneQueryParserException("No solr query support for store " + store);
}
return mappings;
}
return DynamicSolrStoreMappingWrapperFactory.wrap(slice, beanFactory);
} else {
SolrStoreMappingWrapper mappings = mappingLookup.get(store);
if (mappings == null) {
throw new LuceneQueryParserException("No solr query support for store " + store);
}
return mappings;
}
}
use of org.alfresco.service.cmr.search.SearchParameters 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.SearchParameters in project alfresco-repository by Alfresco.
the class SolrQueryHTTPClient method buildPivotParameters.
protected void buildPivotParameters(SearchParameters searchParameters, URLCodec encoder, StringBuilder url) throws UnsupportedEncodingException {
if (searchParameters.getPivots() != null && !searchParameters.getPivots().isEmpty()) {
url.append("&facet=").append(encoder.encode("true", "UTF-8"));
for (List<String> pivotKeys : searchParameters.getPivots()) {
List<String> pivotsList = new ArrayList<>();
pivotsList.addAll(pivotKeys);
url.append("&facet.pivot=");
StringBuilder prefix = new StringBuilder("{! ");
if (searchParameters.getStats() != null && !searchParameters.getStats().isEmpty()) {
for (StatsRequestParameters aStat : searchParameters.getStats()) {
if (pivotKeys.contains(aStat.getLabel())) {
prefix.append("stats=" + aStat.getLabel() + " ");
pivotsList.remove(aStat.getLabel());
// only do it once
break;
}
}
}
if (searchParameters.getRanges() != null && !searchParameters.getRanges().isEmpty()) {
for (RangeParameters aRange : searchParameters.getRanges()) {
Optional<String> found = pivotKeys.stream().filter(aKey -> aKey.equals(aRange.getLabel())).findFirst();
if (found.isPresent()) {
prefix.append("range=" + found.get() + " ");
pivotsList.remove(found.get());
// only do it once
break;
}
}
}
if (// We have add something
prefix.length() > 3) {
url.append(encoder.encode(prefix.toString().trim(), "UTF-8"));
url.append(encoder.encode("}", "UTF-8"));
}
url.append(encoder.encode(String.join(",", pivotsList), "UTF-8"));
}
}
}
use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-repository by Alfresco.
the class SolrSearchService method contains.
@Override
public boolean contains(NodeRef nodeRef, QName propertyQName, String googleLikePattern, Operator defaultOperator) throws InvalidNodeRefException {
ResultSet resultSet = null;
try {
// build Lucene search string specific to the node
StringBuilder sb = new StringBuilder();
sb.append("+ID:\"").append(nodeRef.toString()).append("\" +(TEXT:(").append(googleLikePattern.toLowerCase()).append(") ");
if (propertyQName != null) {
sb.append(" OR @").append(SearchLanguageConversion.escapeLuceneQuery(QName.createQName(propertyQName.getNamespaceURI(), ISO9075.encode(propertyQName.getLocalName())).toString()));
sb.append(":(").append(googleLikePattern.toLowerCase()).append(")");
} else {
for (QName key : nodeService.getProperties(nodeRef).keySet()) {
sb.append(" OR @").append(SearchLanguageConversion.escapeLuceneQuery(QName.createQName(key.getNamespaceURI(), ISO9075.encode(key.getLocalName())).toString()));
sb.append(":(").append(googleLikePattern.toLowerCase()).append(")");
}
}
sb.append(")");
SearchParameters sp = new SearchParameters();
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery(sb.toString());
sp.setDefaultOperator(defaultOperator);
sp.addStore(nodeRef.getStoreRef());
resultSet = this.query(sp);
boolean answer = resultSet.length() > 0;
return answer;
} finally {
if (resultSet != null) {
resultSet.close();
}
}
}
use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-repository by Alfresco.
the class DbOrIndexSwitchingQueryLanguage method flattenDBQuery.
private SearchParameters flattenDBQuery(SearchParameters sp) {
if (sp.getFilterQueries().size() == 0) {
return sp;
} else {
SearchParameters flatten = sp.copy();
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append("( ").append(sp.getQuery()).append(" )");
for (String filter : sp.getFilterQueries()) {
Matcher matcher = LuceneQueryLanguageSPI.AFTS_QUERY.matcher(filter);
if (matcher.find()) {
queryBuilder.append("AND ( ").append(matcher.group(2)).append(" )");
} else {
queryBuilder.append("AND ( ").append(filter).append(" )");
}
}
flatten.setQuery(queryBuilder.toString());
// the filter can be left and will be ignored by the DB query
return flatten;
}
}
Aggregations