From: rkv Date: Mon, 22 Apr 2013 13:25:03 +0000 (+0000) Subject: Wildcards in search are processed now. X-Git-Tag: Root_Delivery2_2013_04_22~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=024efe154781c14d1d3bb4b9dfea134cf69a25b7;p=tools%2Fsiman.git Wildcards in search are processed now. --- 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