From 5defa670b10ad872597e9e6d0811d25d5f60663d Mon Sep 17 00:00:00 2001 From: Andrew Hind Date: Wed, 23 Nov 2011 20:30:49 +0000 Subject: [PATCH] Fix for ALF-11656 Person search starting with * goes the DB and return no results - it should go to the query - DB is only used for * and * only at the end git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32257 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/repo/jscript/People.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/source/java/org/alfresco/repo/jscript/People.java b/source/java/org/alfresco/repo/jscript/People.java index c630b33c3d..f00e9fbe47 100644 --- a/source/java/org/alfresco/repo/jscript/People.java +++ b/source/java/org/alfresco/repo/jscript/People.java @@ -534,8 +534,9 @@ public final class People extends BaseScopableProcessorExtension implements Init String term = filter.replace("\\", "").replace("\"", ""); StringTokenizer t = new StringTokenizer(term, " "); int propIndex = term.indexOf(':'); + int wildPosition = term.indexOf('*'); - if ((t.countTokens() == 1) && (propIndex == -1)) + if ((t.countTokens() == 1) && (propIndex == -1) && ((wildPosition == -1) || (wildPosition == (term.length() - 1) ))) { // simple non-FTS filter: firstname or lastname or username starting with term (ignoring case) @@ -557,6 +558,8 @@ public final class People extends BaseScopableProcessorExtension implements Init else { SearchParameters params = new SearchParameters(); + params.addQueryTemplate("_PERSON", "|%firstName OR |%lastName OR |%userName"); + params.setDefaultFieldName("_PERSON"); StringBuilder query = new StringBuilder(256); @@ -564,11 +567,20 @@ public final class People extends BaseScopableProcessorExtension implements Init if (t.countTokens() == 1) { + // 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)) - .append('"'); + .append(term.substring(propIndex+1)); + if(propIndex > 0) + { + query.append('"'); + } + else + { + query.append("*\""); + } } else { @@ -595,13 +607,9 @@ public final class People extends BaseScopableProcessorExtension implements Init if (nonFtsTokens == 1) { // simple search: first name, last name and username starting with term - query.append("(firstName:\""); + query.append("_PERSON:\""); query.append(term); - query.append("*\" OR lastName:\""); - query.append(term); - query.append("*\" OR userName:\""); - query.append(term); - query.append("*\") "); + query.append("*\" "); } else {