mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)
59064: Merged V4.2-BUG-FIX (4.2.1) to HEAD-BUG-FIX (Cloud/4.3) 59042: Merged V4.1-BUG-FIX (4.1.8) to V4.2-BUG-FIX (4.2.1) 58919 : MNT-9205 : Search by IM property with spaces doesn't work - Using correct regexp to split search term. Added a test git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@62089 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -609,18 +609,18 @@ public class People extends BaseScopableProcessorExtension implements Initializi
|
|||||||
{
|
{
|
||||||
filter = filter.trim();
|
filter = filter.trim();
|
||||||
|
|
||||||
String term = filter.replace("\\", "").replace("\"", "");
|
String term = filter.replace("\"", "");
|
||||||
StringTokenizer t = new StringTokenizer(term, " ");
|
String[] tokens = term.split("(?<!\\\\) ");
|
||||||
int propIndex = term.lastIndexOf(':');
|
int propIndex = term.lastIndexOf(':');
|
||||||
int wildPosition = term.indexOf('*');
|
int wildPosition = term.indexOf('*');
|
||||||
|
|
||||||
// simple filter - can use CQ if search fails
|
// simple filter - can use CQ if search fails
|
||||||
useCQ = ((t.countTokens() == 1) && (propIndex == -1) && ((wildPosition == -1) || (wildPosition == (term.length() - 1))));
|
useCQ = ((tokens.length == 1) && (propIndex == -1) && ((wildPosition == -1) || (wildPosition == (term.length() - 1))));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// FTS
|
// FTS
|
||||||
List<NodeRef> personRefs = getPeopleImplSearch(filter, pagingRequest, sortBy, sortAsc);
|
List<NodeRef> personRefs = getPeopleImplSearch(term, tokens, pagingRequest, sortBy, sortAsc);
|
||||||
|
|
||||||
if (personRefs != null)
|
if (personRefs != null)
|
||||||
{
|
{
|
||||||
@@ -692,14 +692,12 @@ public class People extends BaseScopableProcessorExtension implements Initializi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// search query
|
// search query
|
||||||
protected List<NodeRef> getPeopleImplSearch(String filter, ScriptPagingDetails pagingRequest, String sortBy, Boolean sortAsc) throws Throwable
|
protected List<NodeRef> getPeopleImplSearch(String term, String[] tokens, ScriptPagingDetails pagingRequest, String sortBy, Boolean sortAsc) throws Throwable
|
||||||
{
|
{
|
||||||
List<NodeRef> personRefs = null;
|
List<NodeRef> personRefs = null;
|
||||||
|
|
||||||
Long start = (logger.isDebugEnabled() ? System.currentTimeMillis() : null);
|
Long start = (logger.isDebugEnabled() ? System.currentTimeMillis() : null);
|
||||||
|
|
||||||
String term = filter.replace("\\", "").replace("\"", "");
|
|
||||||
StringTokenizer t = new StringTokenizer(term, " ");
|
|
||||||
int propIndex = term.indexOf(':');
|
int propIndex = term.indexOf(':');
|
||||||
|
|
||||||
int maxResults = pagingRequest.getMaxItems();
|
int maxResults = pagingRequest.getMaxItems();
|
||||||
@@ -715,7 +713,7 @@ public class People extends BaseScopableProcessorExtension implements Initializi
|
|||||||
|
|
||||||
query.append("TYPE:\"").append(ContentModel.TYPE_PERSON).append("\" AND (");
|
query.append("TYPE:\"").append(ContentModel.TYPE_PERSON).append("\" AND (");
|
||||||
|
|
||||||
if (t.countTokens() == 1)
|
if (tokens.length == 1)
|
||||||
{
|
{
|
||||||
// single word with no field will go against _PERSON and expand
|
// single word with no field will go against _PERSON and expand
|
||||||
|
|
||||||
@@ -735,31 +733,28 @@ public class People extends BaseScopableProcessorExtension implements Initializi
|
|||||||
{
|
{
|
||||||
// scan for non-fts-alfresco property search tokens
|
// scan for non-fts-alfresco property search tokens
|
||||||
int nonFtsTokens = 0;
|
int nonFtsTokens = 0;
|
||||||
while (t.hasMoreTokens())
|
for (String token : tokens)
|
||||||
{
|
{
|
||||||
if (t.nextToken().indexOf(':') == -1)
|
if (token.indexOf(':') == -1) nonFtsTokens++;
|
||||||
nonFtsTokens++;
|
|
||||||
}
|
}
|
||||||
t = new StringTokenizer(term, " ");
|
tokens = term.split("(?<!\\\\) ");
|
||||||
|
|
||||||
// multiple terms supplied - look for first and second name etc.
|
// multiple terms supplied - look for first and second name etc.
|
||||||
// also allow fts-alfresco property search to reduce results
|
// also allow fts-alfresco property search to reduce results
|
||||||
params.setDefaultOperator(SearchParameters.Operator.AND);
|
params.setDefaultOperator(SearchParameters.Operator.AND);
|
||||||
boolean propertySearch = false;
|
boolean propertySearch = false;
|
||||||
StringBuilder multiPartNames = new StringBuilder(term.length());
|
StringBuilder multiPartNames = new StringBuilder(tokens.length);
|
||||||
int numOfTokens = t.countTokens();
|
boolean firstToken = true;
|
||||||
int counter = 1;
|
for (String token : tokens)
|
||||||
while (t.hasMoreTokens())
|
|
||||||
{
|
{
|
||||||
term = t.nextToken();
|
if (!propertySearch && token.indexOf(':') == -1)
|
||||||
if (!propertySearch && term.indexOf(':') == -1)
|
|
||||||
{
|
{
|
||||||
if (nonFtsTokens == 1)
|
if (nonFtsTokens == 1)
|
||||||
{
|
{
|
||||||
// simple search: first name, last name and username
|
// simple search: first name, last name and username
|
||||||
// starting with term
|
// starting with term
|
||||||
query.append("_PERSON:\"");
|
query.append("_PERSON:\"");
|
||||||
query.append(term);
|
query.append(token);
|
||||||
query.append("*\" ");
|
query.append("*\" ");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -767,26 +762,26 @@ public class People extends BaseScopableProcessorExtension implements Initializi
|
|||||||
// ALF-11311, in order to support multi-part firstNames/lastNames,
|
// ALF-11311, in order to support multi-part firstNames/lastNames,
|
||||||
// we need to use the whole tokenized term for both
|
// we need to use the whole tokenized term for both
|
||||||
// firstName and lastName
|
// firstName and lastName
|
||||||
if (term.endsWith("*"))
|
if (token.endsWith("*"))
|
||||||
{
|
{
|
||||||
term = term.substring(0, term.lastIndexOf("*"));
|
token = token.substring(0, token.lastIndexOf("*"));
|
||||||
}
|
}
|
||||||
multiPartNames.append("\"");
|
multiPartNames.append("\"");
|
||||||
multiPartNames.append(term);
|
multiPartNames.append(token);
|
||||||
multiPartNames.append("*\"");
|
multiPartNames.append("*\"");
|
||||||
if (numOfTokens > counter)
|
if (firstToken)
|
||||||
{
|
{
|
||||||
multiPartNames.append(' ');
|
multiPartNames.append(' ');
|
||||||
}
|
}
|
||||||
counter++;
|
firstToken = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// fts-alfresco property search i.e. "location:maidenhead"
|
// fts-alfresco property search i.e. "location:maidenhead"
|
||||||
propIndex = term.lastIndexOf(':');
|
propIndex = token.lastIndexOf(':');
|
||||||
query.append(term.substring(0, propIndex + 1)).append('"')
|
query.append(token.substring(0, propIndex + 1)).append('"')
|
||||||
.append(term.substring(propIndex + 1)).append('"').append(' ');
|
.append(token.substring(propIndex + 1)).append('"').append(' ');
|
||||||
|
|
||||||
propertySearch = true;
|
propertySearch = true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user