Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a Slick query for fulltext sql column

I have a list of 'entries' with a corresponding list of tags. I need to write a slick query where I am given a list of 'tags' and I must search through an MYSQL table to search for table entries who have those given 'tags' as a subset of one column of type 'fulltext'. Each post is a row of the table and contains the post number in one column and a list of tags of type FULLTEXT in another column. There can be more than one tag in this list. There can also be more than one tag in the list of tags I am searching for. Is there a way to do a FULLTEXT boolean search in Slick to find the posts with the correct tags?

like image 926
skrakAttack Avatar asked Feb 13 '23 21:02

skrakAttack


1 Answers

This is an older question, but in case somebody else runs into this (like me) - maybe this helps. As Christopher pointed out it works straightforward with SimpleExpression.

    val fulltextMatch = SimpleExpression.binary[String,String,Boolean] { (col,search,qb) =>
      qb.sqlBuilder += "match("
      qb.expr(col)
      qb.sqlBuilder += ") against ("
      qb.expr(search)
      qb.sqlBuilder += " in boolean mode)" 
    }

and then use as: .. if fulltextMatch(t.comment, s.bind)

like image 135
Ossip Avatar answered Feb 15 '23 09:02

Ossip