mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Refactor of the SiteService Lucene query to support users explicitly searching for "*" in the site-finder UI.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29015 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -750,13 +750,17 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
|
|||||||
StringBuilder query = new StringBuilder(128);
|
StringBuilder query = new StringBuilder(128);
|
||||||
query.append("+PARENT:\"").append(siteRoot.toString()).append('"');
|
query.append("+PARENT:\"").append(siteRoot.toString()).append('"');
|
||||||
|
|
||||||
final boolean nameFilterIsPresent = filter != null && filter.length() > 0;
|
final boolean filterIsPresent = filter != null && filter.length() > 0;
|
||||||
|
// The filter string is only used in the Lucene query if it restricts results.
|
||||||
|
// A search for name/title/description = "*" does not need to be put into the Lucene query.
|
||||||
|
// This allows users to search for "*" in the site-finder.
|
||||||
|
final boolean filterIsPresentAndNecessary = filterIsPresent && !filter.equals("*");
|
||||||
final boolean sitePresetFilterIsPresent = sitePresetFilter != null && sitePresetFilter.length() > 0;
|
final boolean sitePresetFilterIsPresent = sitePresetFilter != null && sitePresetFilter.length() > 0;
|
||||||
|
|
||||||
if (nameFilterIsPresent || sitePresetFilterIsPresent)
|
if (filterIsPresentAndNecessary || sitePresetFilterIsPresent)
|
||||||
{
|
{
|
||||||
query.append(" +(");
|
query.append(" +(");
|
||||||
if (nameFilterIsPresent)
|
if (filterIsPresentAndNecessary)
|
||||||
{
|
{
|
||||||
String escNameFilter = AbstractLuceneQueryParser.escape(filter.replace('"', ' '));
|
String escNameFilter = AbstractLuceneQueryParser.escape(filter.replace('"', ' '));
|
||||||
|
|
||||||
|
@@ -605,6 +605,37 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test method ensures that searches with wildcards work as they should
|
||||||
|
*/
|
||||||
|
public void testfindSitesWithWildcardTitles() throws Exception
|
||||||
|
{
|
||||||
|
// How many sites are there already in the repo?
|
||||||
|
List<SiteInfo> preexistingSites = this.siteService.findSites(null, null, 0);
|
||||||
|
final int preexistingSitesCount = preexistingSites.size();
|
||||||
|
|
||||||
|
// Create some test sites
|
||||||
|
//
|
||||||
|
// Note that the shortName can't contain an asterisk but the title can.
|
||||||
|
this.siteService.createSite(TEST_SITE_PRESET, "siteAlpha", "asterix", TEST_DESCRIPTION, SiteVisibility.PUBLIC);
|
||||||
|
this.siteService.createSite(TEST_SITE_PRESET, "siteBeta", "asterix*obelix", TEST_DESCRIPTION, SiteVisibility.PUBLIC);
|
||||||
|
|
||||||
|
// Get sites by matching title
|
||||||
|
List<SiteInfo> sites = this.siteService.findSites("asterix", null, 0);
|
||||||
|
assertNotNull(sites);
|
||||||
|
// As the name & description do not contain "asterix", this will become a search for sites whose titles match "asterix"
|
||||||
|
assertEquals("Matched wrong number of sites with title equal to 'asterix'", 2, sites.size());
|
||||||
|
|
||||||
|
// This means 'find all'
|
||||||
|
sites = this.siteService.findSites("*", null, 0);
|
||||||
|
assertNotNull(sites);
|
||||||
|
assertEquals("Matched wrong number of sites using '*'", preexistingSitesCount + 2, sites.size());
|
||||||
|
|
||||||
|
sites = this.siteService.findSites("as?erix", null, 0);
|
||||||
|
assertNotNull(sites);
|
||||||
|
assertEquals("Matched wrong number of sites using '?'", 2, sites.size());
|
||||||
|
}
|
||||||
|
|
||||||
public void testGetSite()
|
public void testGetSite()
|
||||||
{
|
{
|
||||||
// Get a site that isn't there
|
// Get a site that isn't there
|
||||||
|
Reference in New Issue
Block a user