11package de .rwth .idsg .steve .utils ;
22
33import org .joda .time .DateTime ;
4+ import org .jooq .Condition ;
45import org .jooq .Field ;
56import org .jooq .impl .DSL ;
67
1112 * @since 03.09.2015
1213 */
1314public final class CustomDSL {
14- private CustomDSL () { }
15+ private CustomDSL () {
16+ }
1517
1618 public static Field <DateTime > utcTimestamp () {
1719 return field ("{utc_timestamp(6)}" , DateTime .class );
@@ -31,4 +33,24 @@ public static Field<DateTime> date(Field<DateTime> dt) {
3133 public static Field <Integer > lastInsertId () {
3234 return field ("last_insert_id()" , Integer .class );
3335 }
36+
37+ /**
38+ * http://dev.mysql.com/doc/refman/5.7/en/pattern-matching.html
39+ *
40+ * It's not as advanced as fuzzy full-text search, but still better than nothing. DB will look
41+ * for all the fields that include the input. On the downside, it has the potential to be inefficient,
42+ * when the table is big. We should probably keep an eye on this.
43+ */
44+ public static Condition includes (Field <String > field , String input ) {
45+
46+ // The user can send the search parameter with empty spaces within the input. We replace this
47+ // with '%' since DB uses it to match any string of zero or more characters.
48+ //
49+ // The method returns a reference to the old object, when empty space does not occur in the string.
50+ // Therefore, no if-statement is needed.
51+ //
52+ input = input .replaceAll ("\\ s+" , "%" );
53+
54+ return field .like ("%" + input + "%" );
55+ }
3456}
0 commit comments