Added a new findSites() method for use by live-search and Site Finder (sites.get.js) for ACE-1513

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@68092 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gethin James
2014-04-26 16:20:13 +00:00
parent 28060c9cdf
commit e6e3814951
4 changed files with 241 additions and 3 deletions

View File

@@ -58,7 +58,6 @@ import org.alfresco.repo.node.getchildren.GetChildrenCannedQueryFactory;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.search.impl.lucene.AbstractLuceneQueryParser;
import org.alfresco.repo.security.authentication.AuthenticationContext;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
@@ -112,6 +111,7 @@ import org.json.JSONObject;
import org.springframework.context.ApplicationEvent;
import org.springframework.extensions.surf.util.AbstractLifecycleBean;
import org.springframework.extensions.surf.util.ParameterCheck;
import org.springframework.util.StringUtils;
/**
* Site Service Implementation. Also bootstraps the site AVM and DM stores.
@@ -810,6 +810,81 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
return siteHomeRef;
}
/*
* (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);
query.append(" cm:name:\"" + StringUtils.trimAllWhitespace(escNameFilter) + "*\"")
.append(" OR ")
.append(" cm:title: (");
for (String token: tokenizedFilter)
{
query.append("\""+token+"*\" ");
}
// for( int i = 0; i < tokenizedFilter.length; i++)
// {
// if (i!=0) //Not first element
// {
// 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);
}
ResultSet results = this.searchService.query(sp);
try
{
result = new ArrayList<SiteInfo>(results.length());
for (NodeRef site : results.getNodeRefs())
{
result.add(createSiteInfo(site));
}
}
finally
{
results.close();
}
}
return result;
}
/*
* (non-Javadoc)
* @see org.alfresco.service.cmr.site.SiteService#findSites(java.lang.String, java.lang.String, int)

View File

@@ -261,7 +261,25 @@ public class ScriptSiteService extends BaseScopableProcessorExtension
List<SiteInfo> siteInfos = this.siteService.findSites(filter, sitePresetFilter, size);
return makeSitesArray(siteInfos);
}
/**
* Find (search) the sites available in the repository. The returned list can optionally be filtered by name
* <p/>
*
* @param filter inclusion filter for returned sites. Only sites whose cm:name OR cm:title
* OR cm:description CONTAIN the filter string will be returned.
* @param size max results size crop if >0
*
* @return Site[] a list of the site filtered as appropriate
*
* @see SiteService#findSites(String, int) for a description of the limitations of this method.
* @since 5.0
*/
public Site[] findSites(String filter, int size)
{
List<SiteInfo> siteInfos = this.siteService.findSites(filter, size);
return makeSitesArray(siteInfos);
}
/**
* Converts the given List of SiteInfo objects to a JavaScript friendly array
* of Site objects.

View File

@@ -145,6 +145,23 @@ public interface SiteService
@NotAuditable
List<SiteInfo> findSites(String filter, String sitePresetFilter, int size);
/**
* This method will find all {@link SiteInfo sites} available to the currently authenticated user based on
* the specified site filter and result set size.
* The filter parameter will match any sites whose {@link ContentModel#PROP_NAME cm:name}, {@link ContentModel#PROP_TITLE cm:title}
* or {@link ContentModel#PROP_DESCRIPTION cm:description} <i>contain</i> the specified string (ignoring case).
* <p/>
* Note that this method uses <a href="http://wiki.alfresco.com/wiki/Search">Alfresco Full Text Search</a> to retrieve results
* and depending on server Lucene, SOLR configuration may only offer eventually consistent results.
*
* @param filter Any supplied filter will be wrapped in asterisks (e.g. 'foo*') and used to match the sites' cm:name, cm:title or cm:description.
* @param size this parameter specifies a maximum result set size.
* @return Site objects for all matching sites up to the maximum result size.
*
* @since 5.0
*/
@NotAuditable
List<SiteInfo> findSites(String filter, int size);
/**
* List the available sites. This list can optionally be filtered by site name/title/description and/or site preset.
* <p/>