The implementation of fuzzy query in MySQL has like and regexp.
------------------------
The use of like is known to many people, and the most common case is select * from a where name like '%a% ';
Where '% ' represents any character, its effect is like ' * ' in a regular expression, it has several uses: ' a% ', '%a% ', '%a ', which means the beginning of what, what is, and what ends.
You can also use the ' _ ' character, which represents an arbitrary character. The effect is similar to the '. ' Inside the regular expression.
Like is a comparison of all the strings in this field, the efficiency is not high.
------------------------
RegExp is the regular matching operator for MySQL.
RegExp uses such as: SELECT * from a WHERE name regexp ' a '; it can be written in reference to regular expressions. Like ' * ', ' [A-z] ', ' a|b ', ' cc$ ', ' ^b{2}$ '.
------------------------
The direct use of regexp is not available in Hibernate, but can be implemented by adding custom functions.
public class Mysql5dialectregexp extends org.hibernate.dialect.mysqlinnodbdialect{public
mysql5dialectregexp () {
super ();
Registerfunction ("RegExp", New Sqlfunctiontemplate (Hibernate.boolean, "1 regexp? 2")
}
Where Org.hibernate.dialect.MySQLInnoDBDialect is the value of the Hibernate configuration information Hibernate.dialect, then the MYSQL5DIALECTREGEXP path can be used instead.
HQL statements can be written:
From a where regexp (A, ' a|b|c ') = 1;