0

I just want to code a simple search engine using JPA. Here's example of native sql request that works with PHP :

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

I want to do the same like this but it does not work :

  @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());
    }

Here's the begin of the error message :

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

Does anyone can help me, please?
Thanks in advance for your help.

user1364743
  • 5,283
  • 6
  • 51
  • 90

1 Answers1

0

MATCH ... AGAINST is not supported in Hibernate. You will have to modify your query or use SQL with entityManager.createSqlQuery(...)

overmeulen
  • 1,158
  • 6
  • 15