admin管理员组

文章数量:1355202

I’m working on a Spring Boot 3.2 + Hibernate 6.6.11 + QueryDSL 5 project, using MySQL and attempting to implement full-text search using MATCH ... AGAINST (with ngram parser).

I have already created the full-text index in MySQL:

ALTER TABLE stores ADD FULLTEXT INDEX ft_store_name (name) WITH PARSER ngram;

In my repository, I tried to use QueryDSL like this:

import static com.querydsl.core.types.dsl.Expressions.stringTemplate;

BooleanBuilder builder = new BooleanBuilder();

if (name != null && !name.isEmpty()) {
    builder.and(
        stringTemplate(
            "MATCH({0}) AGAINST ({1} IN NATURAL LANGUAGE MODE)",
            store.name, name
        ).isNotNull()
    );
}

However, I get this error:

.hibernate.query.SyntaxException: At 3:24 and token 'AGAINST', mismatched input 'AGAINST', expecting one of the following tokens...

Root cause: As far as I understand, MATCH ... AGAINST is not valid JPQL, so Hibernate fails when trying to parse it.

I want to keep using QueryDSL and avoid using full native SQL if possible.

How can I use MATCH ... AGAINST in Hibernate 6 with QueryDSL?

本文标签: mysqlHow to use MATCHAGAINST (FullText Search) with Hibernate 6 and QueryDSLStack Overflow