diff --git a/source/java/org/alfresco/repo/jscript/People.java b/source/java/org/alfresco/repo/jscript/People.java index 6c5099f162..cc38bc67e1 100644 --- a/source/java/org/alfresco/repo/jscript/People.java +++ b/source/java/org/alfresco/repo/jscript/People.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2013 Alfresco Software Limited. + * Copyright (C) 2005-2015 Alfresco Software Limited. * * This file is part of Alfresco * @@ -27,7 +27,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.StringTokenizer; import org.alfresco.model.ContentModel; import org.alfresco.repo.security.authentication.AuthenticationException; @@ -718,8 +717,12 @@ public class People extends BaseScopableProcessorExtension implements Initializi // single word with no field will go against _PERSON and expand // fts-alfresco property search i.e. location:"maidenhead" - query.append(term.substring(0, propIndex + 1)).append('"') - .append(term.substring(propIndex + 1)); + query.append(term.substring(0, propIndex + 1)).append('"'); + if (propIndex < 0) + { + query.append('*'); + } + query.append(term.substring(propIndex + 1)); if (propIndex > 0) { query.append('"'); @@ -753,7 +756,7 @@ public class People extends BaseScopableProcessorExtension implements Initializi { // simple search: first name, last name and username // starting with term - query.append("_PERSON:\""); + query.append("_PERSON:\"*"); query.append(token); query.append("*\" "); } @@ -766,7 +769,7 @@ public class People extends BaseScopableProcessorExtension implements Initializi { token = token.substring(0, token.lastIndexOf("*")); } - multiPartNames.append("\""); + multiPartNames.append("\"*"); multiPartNames.append(token); multiPartNames.append("*\""); if (firstToken) diff --git a/source/test-java/org/alfresco/repo/jscript/PeopleTest.java b/source/test-java/org/alfresco/repo/jscript/PeopleTest.java index f5f2dc8601..c98a650ae4 100644 --- a/source/test-java/org/alfresco/repo/jscript/PeopleTest.java +++ b/source/test-java/org/alfresco/repo/jscript/PeopleTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2013 Alfresco Software Limited. + * Copyright (C) 2005-2015 Alfresco Software Limited. * * This file is part of Alfresco * @@ -18,7 +18,9 @@ */ package org.alfresco.repo.jscript; +import java.util.HashSet; import java.util.List; +import java.util.Set; import javax.transaction.UserTransaction; @@ -27,6 +29,7 @@ import junit.framework.TestCase; import org.alfresco.model.ContentModel; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService.PersonInfo; import org.alfresco.service.transaction.TransactionService; @@ -49,6 +52,12 @@ import org.springframework.context.ApplicationContext; @Category(OwnJVMTestsCategory.class) public class PeopleTest extends TestCase { + private static final String SIMPLE_FILTER = "a"; + + private static final String CQ_SIMPLE_FILTER = SIMPLE_FILTER + " [hint:useCQ]"; + + private static final String DEFAULT_SORT_BY_FIELD = "username"; + private static final UserInfo USER_1 = new UserInfo("user1", "john junior", "lewis second"); private static final UserInfo USER_2 = new UserInfo("user2", "john senior", "lewis second"); @@ -171,6 +180,33 @@ public class PeopleTest extends TestCase } + /** + * Test for MNT-14113.
+ *
+ * This test is also valid for SOLR1 and SOLR4! + */ + public void testGetPeopleByPatternIndexedAndCQ() throws Exception + { + ScriptPagingDetails paging = new ScriptPagingDetails(0, 0); + List unsortedPeople = people.getPeopleImpl(CQ_SIMPLE_FILTER, paging, null, null); + assertNotNull("No one person is found!", unsortedPeople); + + Set expectedUsers = new HashSet(); + for (PersonInfo person : unsortedPeople) + { + expectedUsers.add(person.getNodeRef()); + } + + List sortedPeople = people.getPeopleImpl(SIMPLE_FILTER, paging, DEFAULT_SORT_BY_FIELD, null); + assertNotNull("No one person is found and sorted!", sortedPeople); + assertEquals(expectedUsers.size(), sortedPeople.size()); + + for (PersonInfo person : sortedPeople) + { + assertTrue(("Unexpected person: '" + person.getUserName() + "[" + person.getNodeRef() + "]'"), expectedUsers.contains(person.getNodeRef())); + } + } + private void createUser(UserInfo... userInfo) { for (UserInfo user : userInfo)