if (!textSearch.isEmpty()) {
String searchExpression = getSearchExpressionForMatchType(
textSearch.getTerm(), textSearch.getMatch());
SearchFields searchFields = textSearch.getFields();
StringBuilder textSearchConstraints = new StringBuilder(256);
if (searchFields.isSiteContent() || (!searchFields.isTags() && !searchFields.isFileContent() && !searchFields.isDescription() && !searchFields.isTitle() && !searchFields.isKeywords() && !searchFields.isFilename())) {
addConstraint(textSearchConstraints, "or", "jcr:contains(., " + searchExpression + ")");
}
if (searchFields.isFileContent()) {
addConstraint(textSearchConstraints, "or", "jcr:contains(jcr:content, " + searchExpression + ")");
}
if (searchFields.isDescription()) {
addConstraint(textSearchConstraints, "or", "jcr:contains(@jcr:description, " + searchExpression
+ ")");
}
if (searchFields.isTitle()) {
addConstraint(textSearchConstraints, "or", "jcr:contains(@jcr:title, " + searchExpression + ")");
}
if (searchFields.isKeywords()) {
addConstraint(textSearchConstraints, "or", "jcr:contains(@j:keywords, " + searchExpression + ")");
}
if (searchFields.isFilename()) {
String[] terms = null;
String constraint = "or";
if (textSearch.getMatch() == MatchType.ANY_WORD || textSearch.getMatch() == MatchType.ALL_WORDS || textSearch.getMatch() == MatchType.WITHOUT_WORDS) {
terms = cleanMultipleWhiteSpaces(textSearch.getTerm()).split(" ");
if (textSearch.getMatch() == MatchType.ALL_WORDS || textSearch.getMatch() == MatchType.WITHOUT_WORDS) {
constraint = "and";
}
} else {
terms = new String[]{textSearch.getTerm()};
}
StringBuilder nameSearchConstraints = new StringBuilder(256);
for (String term : terms) {
String termConstraint = "jcr:like(@j:nodename, "
+ (term.contains("*") ? stringToQueryLiteral(StringUtils
.replaceChars(term, '*', '%'))
: stringToQueryLiteral("%" + term + "%")
+ ")");
if (textSearch.getMatch() == MatchType.WITHOUT_WORDS) {
termConstraint = "not(" + termConstraint + ")";
}
addConstraint(nameSearchConstraints, constraint,
termConstraint);
}
addConstraint(textSearchConstraints,
"or", nameSearchConstraints.toString());
}
if (searchFields.isTags() && getTaggingService() != null
&& (params.getSites().getValue() != null || params.getOriginSiteKey() != null)
&& !StringUtils.containsAny(textSearch.getTerm(), "?*")) {
try {
JCRNodeWrapper tag = getTaggingService().getTag(textSearch.getTerm(), params.getSites().getValue() != null ? params.getSites().getValue() : params.getOriginSiteKey(), session);
if (tag != null) {