Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
admpub committed Aug 22, 2023
1 parent 8136ff5 commit 45ff0d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/factory/mysql/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func searchAllField(field string, keywords string, idFields ...string) *db.Compo
}
if strings.Contains(v, "||") {
vals := strings.Split(v, "||")
if fieldMode.operator == OperatorMatch {
if fieldMode.isMatchQuery() {
for _, val := range vals {
safelyMatchValues = append(safelyMatchValues, buildSafelyMatchValues(val, false)...)
}
Expand All @@ -161,7 +161,7 @@ func searchAllField(field string, keywords string, idFields ...string) *db.Compo
cd.Add(cond.Or())
continue
}
if fieldMode.operator == OperatorMatch {
if fieldMode.isMatchQuery() {
safelyMatchValues = append(safelyMatchValues, buildSafelyMatchValues(v, true)...)
continue
}
Expand Down
13 changes: 12 additions & 1 deletion lib/factory/mysql/search_fulltext.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ import (
"github.com/webx-top/db"
)

// ft_boolean_syntax: + -><()~*:""&|
var fulltextOperatorReplacer = strings.NewReplacer(
`'`, ``,
`+`, ``,
`-`, ``,
`*`, ``,
`"`, ``,
`\`, ``,
`>`, ``,
`<`, ``,
`(`, ``,
`)`, ``,
`~`, ``,
`*`, ``,
`:`, ``,
`&`, ``,
`|`, ``,
)

func CleanFulltextOperator(v string) string {
Expand Down Expand Up @@ -42,5 +52,6 @@ func match(safelyMatchValue string, booleanMode bool, keys ...string) db.Compoun
if booleanMode {
mode = ` IN BOOLEAN MODE`
}
return db.Raw("MATCH(" + strings.Join(fields, ",") + ") AGAINST ('" + safelyMatchValue + "'" + mode + ")")
// MATCH(`field`) AGAINST ('keywords' IN BOOLEAN MODE)
return db.Raw(`MATCH(` + strings.Join(fields, `,`) + `) AGAINST ('` + safelyMatchValue + `'` + mode + `)`)
}

0 comments on commit 45ff0d3

Please sign in to comment.