. Fix for AWC-589 (Error searching for "+ test")

- Fixed to ignore empty terms after stripping operators from search text

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2600 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2006-03-31 15:07:29 +00:00
parent 2ad12b2b1b
commit b29006fbca

View File

@@ -158,27 +158,30 @@ public final class SearchContext implements Serializable
text = text.substring(1); text = text.substring(1);
} }
// prepend NOT operator if supplied if (text.length() != 0)
if (operatorNOT)
{ {
fullTextBuf.append(OP_NOT); // prepend NOT operator if supplied
nameAttrBuf.append(OP_NOT); if (operatorNOT)
} {
fullTextBuf.append(OP_NOT);
// simple single word text search nameAttrBuf.append(OP_NOT);
if (text.charAt(0) != OP_WILDCARD) }
{
// escape characters and append the wildcard character // simple single word text search
String safeText = QueryParser.escape(text); if (text.charAt(0) != OP_WILDCARD)
fullTextBuf.append("TEXT:").append(safeText).append(OP_WILDCARD); {
nameAttrBuf.append("@").append(nameAttr).append(":").append(safeText).append(OP_WILDCARD); // escape characters and append the wildcard character
} String safeText = QueryParser.escape(text);
else fullTextBuf.append("TEXT:").append(safeText).append(OP_WILDCARD);
{ nameAttrBuf.append("@").append(nameAttr).append(":").append(safeText).append(OP_WILDCARD);
// found a leading wildcard - prepend it again after escaping the other characters }
String safeText = QueryParser.escape(text.substring(1)); else
fullTextBuf.append("TEXT:*").append(safeText).append(OP_WILDCARD); {
nameAttrBuf.append("@").append(nameAttr).append(":*").append(safeText).append(OP_WILDCARD); // found a leading wildcard - prepend it again after escaping the other characters
String safeText = QueryParser.escape(text.substring(1));
fullTextBuf.append("TEXT:*").append(safeText).append(OP_WILDCARD);
nameAttrBuf.append("@").append(nameAttr).append(":*").append(safeText).append(OP_WILDCARD);
}
} }
} }
else else
@@ -198,6 +201,8 @@ public final class SearchContext implements Serializable
fullTextBuf.append('('); fullTextBuf.append('(');
nameAttrBuf.append('('); nameAttrBuf.append('(');
int termCount = 0;
int tokenCount = t.countTokens(); int tokenCount = t.countTokens();
for (int i=0; i<tokenCount; i++) for (int i=0; i<tokenCount; i++)
{ {
@@ -215,7 +220,7 @@ public final class SearchContext implements Serializable
if (term.length() != 0) if (term.length() != 0)
{ {
// operators such as AND and OR are only make sense for full text searching // operators such as AND and OR are only make sense for full text searching
if (i != 0 && !operatorAND) if (termCount != 0 && !operatorAND)
{ {
fullTextBuf.append("OR "); fullTextBuf.append("OR ");
nameAttrBuf.append("OR "); nameAttrBuf.append("OR ");
@@ -248,6 +253,8 @@ public final class SearchContext implements Serializable
} }
fullTextBuf.append(' '); fullTextBuf.append(' ');
nameAttrBuf.append(' '); nameAttrBuf.append(' ');
termCount++;
} }
} }
fullTextBuf.append(')'); fullTextBuf.append(')');