Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrige les parenthèses dans la tsquery #2111

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions app/services/UserGroupService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package services
import anorm._
import aplus.macros.Macros
import cats.syntax.all._
import helper.{StringHelper, Time, UUIDHelper}
import helper.{Time, UUIDHelper}
import java.sql.ResultSet
import java.util.UUID
import javax.inject.Inject
Expand Down 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