Skip to content

Commit

Permalink
Corrige les parenthèses dans la tsquery
Browse files Browse the repository at this point in the history
  • Loading branch information
niladic committed Oct 21, 2024
1 parent 6e9cce5 commit 11736d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
7 changes: 1 addition & 6 deletions app/services/UserGroupService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,7 @@ class UserGroupService @Inject() (
Future(
Try(
db.withConnection { implicit connection =>
val query =
StringHelper
.commonStringInputNormalization(searchQuery)
.replace(' ', '+')
.replace('@', '+')
.replace('.', '+') + ":*"
val query = UserService.toStarTsquery(searchQuery)
SQL(s"""SELECT $fieldsInSelect
FROM "user_group"
WHERE (
Expand Down
21 changes: 15 additions & 6 deletions app/services/UserService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ import scala.concurrent.Future
import scala.util.Try
import views.editMyGroups.UserInfos

object UserService {

def toStarTsquery(searchQuery: String): String =
StringHelper
.commonStringInputNormalization(searchQuery)
.replace(' ', '+')
.replace('(', '+')
.replace(')', '+')
.replace(':', '+')
.replace('@', '+') // emails are considered single tokens
.replace('.', '+') + ":*"

}

@Singleton
class UserService @Inject() (
config: AppConfig,
Expand Down Expand Up @@ -283,12 +297,7 @@ class UserService @Inject() (
Future(
Try(
db.withConnection { implicit connection =>
val query =
StringHelper
.commonStringInputNormalization(searchQuery)
.replace(' ', '+')
.replace('@', '+') // emails are considered single tokens
.replace('.', '+') + ":*"
val query = UserService.toStarTsquery(searchQuery)
SQL(s"""SELECT $fieldsInSelect
FROM "user"
WHERE (
Expand Down

0 comments on commit 11736d6

Please sign in to comment.