我只想使用 JPA 编写一个简单的搜索引擎。以下是适用于 PHP 的本机 sql 请求示例:
"SELECT mobiles.brand, argus_waitings_mobiles_prices.mobile, argus_waitings_mobiles_prices.argus_buyer_id, "
. "MATCH(mobile) AGAINST('$mobile_tags' IN BOOLEAN MODE) AS pertinence "
. "FROM argus_waitings_mobiles_prices "
. "WHERE argus_waitings_mobiles_prices.argus_buyer_id = $buyerId "
. "ORDER BY pertinence DESC "
. "LIMIT 10");
我想这样做,但它不起作用:
@Override
@SuppressWarnings("unchecked")
@Transactional(readOnly=true)
public List<Thread> findAllWithReferer(String referer) {
EntityManager entityManager = EntityManagerUtil.createEntityManagerAndOpenTransaction();
Query query = entityManager.createQuery("SELECT t "
+ "MATCH(t.title) AGAINST(:referer IN BOOLEAN MODE) AS pertinence "
+ "FROM Thread t MATCH(t.title) AGAINST(:referer IN BOOLEAN MODE)"
+ "ORDER BY pertinence DESC "
+ "LIMIT 10");
return (query.getResultList());
}
这是错误消息的开头:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: MATCH near line 1, column 40 [SELECT t FROM fr.dorian.model.Thread t MATCH(t.title) AGAINST(:referer IN BOOLEAN MODE)]
有人可以帮助我吗?
在此先感谢您的帮助。