How to use MySQL's full text search from JPA

前端 未结 7 1901
谎友^
谎友^ 2020-12-15 13:55

I want to use MySQL\'s full text search features using JPA, without having to use a native query.

I am using EclipseLink, which has a function to support native SQL

7条回答
  •  猫巷女王i
    2020-12-15 14:24

    To elaborate on the answer of James:

    It seems like I had luck extending the mysql dialect using

    registerFunction("match", new SQLFunctionTemplate(DoubleType.INSTANCE,     "match(?1) against  (?2 in boolean mode)")); 
    

    and invoking the function via the following jpql fragment

    match(" + binaryDataColumn + ",'" + StringUtils.join(words, " ") + "') > 0 
    

    I had to guess the return type, but this should get you started.

提交回复
热议问题