use of org.alfresco.service.cmr.search.ResultSet 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.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class HiddenAspect method checkHidden.
/**
* Searches for nodes in the given store that should be hidden (i.e. match the hidden pattern)
* and hides them if they are not already hidden.
*
* @param storeRef StoreRef
*/
public void checkHidden(StoreRef storeRef) {
for (HiddenFileInfo filter : filters) {
String pattern = filter.getFilter();
ResultSet rs = searchForName(storeRef, pattern);
for (NodeRef nodeRef : rs.getNodeRefs()) {
if (!hasHiddenAspect(nodeRef)) {
hideNode(nodeRef, filter.getVisibilityMask(), true, true, false);
}
}
}
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class SolrSQLHttpClient method postSolrQuery.
protected ResultSet postSolrQuery(HttpClient httpClient, String url, JSONObject body, SolrJsonProcessor<?> jsonProcessor) throws IOException, JSONException {
JSONObject json = postQuery(httpClient, url, body);
JSONResult results = jsonProcessor.getResult(json);
LOGGER.debug("Sent : {}", url);
LOGGER.debug("with: {}", body);
LOGGER.debug("Got: {} in {} ms", results.getNumberFound(), results.getQueryTime());
return (ResultSet) results;
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class SolrSearchService method like.
@Override
public boolean like(NodeRef nodeRef, QName propertyQName, String sqlLikePattern, boolean includeFTS) throws InvalidNodeRefException {
if (propertyQName == null) {
throw new IllegalArgumentException("Property QName is mandatory for the like expression");
}
StringBuilder sb = new StringBuilder(sqlLikePattern.length() * 3);
if (includeFTS) {
// convert the SQL-like pattern into a Lucene-compatible string
String pattern = SearchLanguageConversion.convertXPathLikeToLucene(sqlLikePattern.toLowerCase());
// build Lucene search string specific to the node
sb = new StringBuilder();
sb.append("+ID:\"").append(nodeRef.toString()).append("\" +(");
// FTS or attribute matches
if (includeFTS) {
sb.append("TEXT:(").append(pattern).append(") ");
}
if (propertyQName != null) {
sb.append(" @").append(SearchLanguageConversion.escapeLuceneQuery(QName.createQName(propertyQName.getNamespaceURI(), ISO9075.encode(propertyQName.getLocalName())).toString())).append(":(").append(pattern).append(")");
}
sb.append(")");
ResultSet resultSet = null;
try {
resultSet = this.query(nodeRef.getStoreRef(), "lucene", sb.toString());
boolean answer = resultSet.length() > 0;
return answer;
} finally {
if (resultSet != null) {
resultSet.close();
}
}
} else {
// convert the SQL-like pattern into a Lucene-compatible string
String pattern = SearchLanguageConversion.convertXPathLikeToRegex(sqlLikePattern.toLowerCase());
Serializable property = nodeService.getProperty(nodeRef, propertyQName);
if (property == null) {
return false;
} else {
String propertyString = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(nodeRef, propertyQName));
return propertyString.toLowerCase().matches(pattern);
}
}
}
use of org.alfresco.service.cmr.search.ResultSet 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();
}
}
}
Aggregations