最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

mysql - How to use MATCH ... AGAINST (FullText Search) with Hibernate 6 and QueryDSL? - Stack Overflow

programmeradmin8浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论