| Hi to all!
I am using a native query in MySQL to find a match in a fulltext field (I have to use the MATCH ...AGAINST function in MySQL).
 I can retrieve the result of my query:
 
 private static String SQLQuery = "SELECT {users.*} FROM users WHERE MATCH(firstName, lastName, email, address, city, province, state, nationality, phone, mobile, profession, attributes) AGAINST(:search)";
 
 here the Java method to get it from Hibernate:
 
 /**
 * Searches information in fulltext fields
 * @param string
 * @return
 * @throws BusinessException
 */
 public List searchInfo(String string) throws BusinessException {
 try {
 Session session = HibernateUtil.currentSession();	return session.createSQLQuery(SQLQuery).addEntity("users", HBUser.class).setString("search", string ).setMaxResults(50).list();
 } catch (HibernateException e) {
 throw new BusinessException(e);
 }
 finally{
 HibernateUtil.closeSession();
 }
 }
 
 
 It works, but I am not satisfied and i want to get the score of the MySQL's function MATCH...AGAINST. So I added the following to my query:
 
 MATCH(firstName, lastName, email, address, city, province, state, nationality, phone, mobile, profession, attributes) AGAINST(:search) as score
 
 Here the complete final query:
 
 private static String SQLQuery = "SELECT {users.*}, MATCH(firstName, lastName, email, " +
 "address, city, province, state, nationality, " +		"phone, mobile, profession, attributes) AGAINST(:search) as score FROM users WHERE MATCH(firstName, lastName, email, " +				"address, city, province, state, nationality, " +
 "phone, mobile, profession, attributes) AGAINST(:search)";
 
 
 How can I retrieve the score from Hibernate? I don't have mapped it into the POJO class.
 Is the a specific method to retrieve a renamed field from a native query?
 
 Thank you in advance for your time,
 Nicola
 
 
 |