String[] word = title.split(" ");
for (int j = 0; j < word.length; j++) {
- critext.add(Restrictions.like(PROP_TITLE, "%" + word[j] + "%"));
+ critext.add(Restrictions.like(PROP_TITLE, "%"
+ + processWildcards(word[j]) + "%"));
}
topJunction.add(critext);
}
}
+ /**
+ * Escape wildcard characters and insert them instead of ? and *.
+ *
+ * @param str
+ * the original string
+ * @return the transformed string
+ */
+ private String processWildcards(final String str) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(" Original search string: " + str);
+ LOG.debug("Transformed search string: "
+ + str.replaceAll("\\\\", "\\\\\\\\").replaceAll("%",
+ "\\\\%").replaceAll("_", "\\\\_").replaceAll("\\?",
+ "_").replaceAll("\\*", "%"));
+ }
+ return str.replaceAll("\\\\", "\\\\\\\\").replaceAll("%", "\\\\%")
+ .replaceAll("_", "\\\\_").replaceAll("\\?", "_").replaceAll(
+ "\\*", "%");
+ }
+
/**
* {@inheritDoc}
*
}
String refid = filter.getReference(); // Reference
if (refid != null && !refid.isEmpty()) {
- topJunction.add(Restrictions.eq("sid", refid));
+ topJunction.add(Restrictions.like("sid", processWildcards(refid)));
}
// Filter by creation date