I am trying to build an API which can search by HQL regex keywords,
EDITED: The best way to perform regex search in HQL is to use criteria, Restrictions.like() or Restrictions.ilike().
public static List<Object> createQueryAnd(Criteria cri,
ArrayList<Parameters> list) {
for (Parameters p : list) {
String value = (String) p.value;
if (value.contains("*")) {
value = value.replace("*", "%");
} else {
value += "%";
}
Criterion c1 = Restrictions.ilike(p.property, value);
cri.add(c1);
}
return cri.list();
}
Hope this helps someone