use of org.alfresco.repo.search.impl.lucene.LuceneQueryParserException in project alfresco-repository by Alfresco.
the class SiteServiceImpl method findSites.
/*
* (non-Javadoc)
* @see org.alfresco.service.cmr.site.SiteService#findSites(java.lang.String, int)
*/
@Override
public List<SiteInfo> findSites(String filter, int size) {
List<SiteInfo> result;
NodeRef siteRoot = getSiteRoot();
if (siteRoot == null) {
result = Collections.emptyList();
} else {
// get the sites that match the specified names
StringBuilder query = new StringBuilder(128);
query.append("+TYPE:\"").append(SiteModel.TYPE_SITE).append('"');
final boolean filterIsPresent = filter != null && filter.length() > 0;
if (filterIsPresent) {
query.append(" AND (");
String escNameFilter = SearchLanguageConversion.escapeLuceneQuery(filter.replace('"', ' '));
String[] tokenizedFilter = SearchLanguageConversion.tokenizeString(escNameFilter);
// cm:name
query.append(" cm:name:\" ");
for (int i = 0; i < tokenizedFilter.length; i++) {
if (// Not first element
i != 0) {
query.append("?");
}
query.append(tokenizedFilter[i].toLowerCase());
}
query.append("*\"");
// cm:title
query.append(" OR ").append(" cm:title: (");
for (int i = 0; i < tokenizedFilter.length; i++) {
if (// Not first element
i != 0) {
query.append(" AND ");
}
query.append("\"" + tokenizedFilter[i] + "*\" ");
}
query.append(")");
query.append(" OR cm:description:\"" + escNameFilter + "\"");
query.append(")");
}
SearchParameters sp = new SearchParameters();
sp.addStore(siteRoot.getStoreRef());
sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
sp.setQuery(query.toString());
if (size > 0) {
sp.setLimit(size);
sp.setLimitBy(LimitBy.FINAL_SIZE);
}
if (logger.isDebugEnabled()) {
logger.debug("Search parameters are: " + sp);
}
ResultSet results = null;
try {
results = this.searchService.query(sp);
result = new ArrayList<SiteInfo>(results.length());
for (NodeRef site : results.getNodeRefs()) {
result.add(createSiteInfo(site));
}
} catch (LuceneQueryParserException lqpe) {
// Log the error but suppress is from the user
logger.error("LuceneQueryParserException with findSites()", lqpe);
result = Collections.emptyList();
} finally {
if (results != null)
results.close();
}
}
return result;
}
use of org.alfresco.repo.search.impl.lucene.LuceneQueryParserException in project alfresco-repository by Alfresco.
the class SOLRAdminClient method executeCommand.
/* (non-Javadoc)
* @see org.alfresco.repo.search.impl.solr.SolrAdminClient#executeCommand(java.lang.String, org.alfresco.repo.search.impl.solr.SolrAdminClient.HANDLER, org.alfresco.repo.search.impl.solr.SolrAdminClient.COMMAND, java.util.Map)
*/
@Override
public JSONAPIResult executeCommand(String core, JSONAPIResultFactory.HANDLER handler, JSONAPIResultFactory.COMMAND command, Map<String, String> parameters) {
StoreRef store = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
SolrStoreMappingWrapper mapping = SolrClientUtil.extractMapping(store, mappingLookup, shardRegistry, useDynamicShardRegistration, beanFactory);
HttpClient httpClient = mapping.getHttpClientAndBaseUrl().getFirst();
StringBuilder url = new StringBuilder();
url.append(baseUrl);
if (!url.toString().endsWith("/")) {
url.append("/");
}
url.append(core + "/" + handler.toString().toLowerCase());
URLCodec encoder = new URLCodec();
url.append("?command=" + command.toString().toLowerCase());
parameters.forEach((key, value) -> {
try {
url.append("&" + key + "=" + encoder.encode(value));
} catch (EncoderException e) {
throw new RuntimeException(e);
}
});
url.append("&alfresco.shards=");
if (mapping.isSharded()) {
url.append(mapping.getShards());
} else {
String solrurl = httpClient.getHostConfiguration().getHostURL() + mapping.getHttpClientAndBaseUrl().getSecond();
url.append(solrurl);
}
try {
JSONAPIResult response = new SolrCommandBackupResult(getOperation(httpClient, url.toString()));
if (response.getStatus() != 0) {
solrTracker.setSolrActive(false);
}
return response;
} catch (IOException e) {
throw new LuceneQueryParserException("action", e);
}
}
use of org.alfresco.repo.search.impl.lucene.LuceneQueryParserException in project alfresco-repository by Alfresco.
the class ExplicitSolrStoreMappingWrapper method getShards2.
private String getShards2() {
try {
URLCodec encoder = new URLCodec();
StringBuilder builder = new StringBuilder();
for (int shard = 0; shard < wrapped.getNumShards(); shard++) {
int position = random.nextInt(wrapped.getReplicationFactor());
List<Integer> nodeInstances = policy.getNodeInstancesForShardId(shard);
Integer nodeId = nodeInstances.get(position);
if (builder.length() > 0) {
builder.append(',');
}
HttpClientAndBaseUrl httpClientAndBaseUrl = httpClientsAndBaseURLs.toArray(new HttpClientAndBaseUrl[0])[nodeId - 1];
builder.append(encoder.encode(httpClientAndBaseUrl.getProtocol() + "://", "UTF-8"));
builder.append(encoder.encode(httpClientAndBaseUrl.getHost(), "UTF-8"));
builder.append(':');
builder.append(encoder.encode("" + httpClientAndBaseUrl.getPort(), "UTF-8"));
if (httpClientAndBaseUrl.getBaseUrl().startsWith("/")) {
builder.append(encoder.encode(httpClientAndBaseUrl.getBaseUrl(), "UTF-8"));
} else {
builder.append(encoder.encode("/" + httpClientAndBaseUrl.getBaseUrl(), "UTF-8"));
}
if (isSharded())
builder.append('-').append(shard);
}
return builder.toString();
} catch (UnsupportedEncodingException e) {
throw new LuceneQueryParserException("", e);
}
}
use of org.alfresco.repo.search.impl.lucene.LuceneQueryParserException 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.repo.search.impl.lucene.LuceneQueryParserException in project alfresco-repository by Alfresco.
the class AbstractSolrAdminHTTPClient method getOperation.
/**
* Executes an action or a command in SOLR using REST API
*
* @param httpClient HTTP Client to be used for the invocation
* @param url Complete URL of SOLR REST API Endpoint
* @return A JSON Object including SOLR response
* @throws UnsupportedEncodingException
*/
protected JSONObject getOperation(HttpClient httpClient, String url) throws UnsupportedEncodingException {
GetMethod get = new GetMethod(url);
try {
httpClient.executeMethod(get);
if (get.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY || get.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) {
Header locationHeader = get.getResponseHeader("location");
if (locationHeader != null) {
String redirectLocation = locationHeader.getValue();
get.setURI(new URI(redirectLocation, true));
httpClient.executeMethod(get);
}
}
if (get.getStatusCode() != HttpServletResponse.SC_OK) {
throw new LuceneQueryParserException("Request failed " + get.getStatusCode() + " " + url.toString());
}
Reader reader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), get.getResponseCharSet()));
JSONObject json = new JSONObject(new JSONTokener(reader));
return json;
} catch (IOException | JSONException e) {
throw new AlfrescoRuntimeException(e.getMessage(), e);
} finally {
get.releaseConnection();
}
}
Aggregations