From 024efe154781c14d1d3bb4b9dfea134cf69a25b7 Mon Sep 17 00:00:00 2001 From: rkv Date: Mon, 22 Apr 2013 13:25:03 +0000 Subject: [PATCH] Wildcards in search are processed now. --- .../org/splat/service/SearchServiceImpl.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java index 9c9182d..2baaf40 100644 --- a/Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java @@ -230,12 +230,33 @@ public class SearchServiceImpl implements SearchService { 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} * @@ -316,7 +337,7 @@ public class SearchServiceImpl implements SearchService { } 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 -- 2.39.2