2013-02-19 34 views
0

我只想使用JPA編寫簡單的搜索引擎。 這裏的例子本地SQL請求與PHP的工作原理:帶有createQuery的搜索引擎不起作用

"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)] 

有人能幫助我嗎?
在此先感謝您的幫助。

回答

0

MATCH ... AGAINST在Hibernate中不受支持。你將不得不修改你的查詢或使用SQL與entityManager.createSqlQuery(...)