Salome HOME
Wildcards in search are processed now.
authorrkv <rkv@opencascade.com>
Mon, 22 Apr 2013 13:25:03 +0000 (13:25 +0000)
committerrkv <rkv@opencascade.com>
Mon, 22 Apr 2013 13:25:03 +0000 (13:25 +0000)
Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java

index 9c9182d97bfbcc24944e33c7fc2b3e0df7a7be4e..2baaf40465a22fe33f4766392c8c34755c63da60 100644 (file)
@@ -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