I'm doing at the moment a project for university where I'm using the Play! framework 2.4 together with Ebean.
At the moment I'm trying to realize a live user search where a user can search for other users using a fulltext text input. A possible seach string could be "Michael Lee" or just a email address. Im passing the search string to this method where I try to access the database in a smart way:
public Result searchUser(String sstring) {
String query = "WHERE MATCH (firstname,lastname,email) AGAINST ('" + sstring + "' IN BOOLEAN MODE)";
List<User> resultUsers = User.find
.setQuery(query)
.findList();
String resultString = "";
for (User user: resultUsers) {
resultString += user.getFirstname() + user.getLastname() + "<br>";
}
return ok(resultString);
}
I'm trying to search in the columns firstname, lastname and email for the keyword but play gives me this error:
[PersistenceException: Query threw SQLException:The used table type doesn't support FULLTEXT indexes Bind values:[] Query was: select t0.id c0, t0.firstname c1, t0.lastname c2, t0.birthday c3, t0.email c4, t0.password c5, t0.author c6, t0.points c7, t0.locked c8, t0.last_online c9, t0.date_created c10, t0.date_updated c11 from users t0 where MATCH (t0.firstname,t0.lastname,t0.email) AGAINST ('erik' IN BOOLEAN MODE) ]
Is it possible to tell ebean to create the table users with the required fulltext indexes? Or is there a other smart way to search in a MySQL table for a searchstring in many columns? The searchstring can consist keywords from all columns.
Thanks.
Update:
I tried to add an index like it is mentioned in the ebean api doc but unfortunally it seems like the play ebean version does not support the columnNames keyword (and any others at all...).
@Index(name = "livesearch_index", columnNames = {"firstname","lastname","email"})
So what else can I do? Is it possible to set this index externally maybe in a second evolution file which is not generated automaticly?