. 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);
}
// prepend NOT operator if supplied
if (operatorNOT)
if (text.length() != 0)
{
fullTextBuf.append(OP_NOT);
nameAttrBuf.append(OP_NOT);
}
// simple single word text search
if (text.charAt(0) != OP_WILDCARD)
{
// escape characters and append the wildcard character
String safeText = QueryParser.escape(text);
fullTextBuf.append("TEXT:").append(safeText).append(OP_WILDCARD);
nameAttrBuf.append("@").append(nameAttr).append(":").append(safeText).append(OP_WILDCARD);
}
else
{
// 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);
// prepend NOT operator if supplied
if (operatorNOT)
{
fullTextBuf.append(OP_NOT);
nameAttrBuf.append(OP_NOT);
}
// simple single word text search
if (text.charAt(0) != OP_WILDCARD)
{
// escape characters and append the wildcard character
String safeText = QueryParser.escape(text);
fullTextBuf.append("TEXT:").append(safeText).append(OP_WILDCARD);
nameAttrBuf.append("@").append(nameAttr).append(":").append(safeText).append(OP_WILDCARD);
}
else
{
// 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
@@ -198,6 +201,8 @@ public final class SearchContext implements Serializable
fullTextBuf.append('(');
nameAttrBuf.append('(');
int termCount = 0;
int tokenCount = t.countTokens();
for (int i=0; i<tokenCount; i++)
{
@@ -215,7 +220,7 @@ public final class SearchContext implements Serializable
if (term.length() != 0)
{
// 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 ");
nameAttrBuf.append("OR ");
@@ -248,6 +253,8 @@ public final class SearchContext implements Serializable
}
fullTextBuf.append(' ');
nameAttrBuf.append(' ');
termCount++;
}
}
fullTextBuf.append(')');