diff --git a/models/commit.go b/models/commit.go index fc4dbfd0..0c8639ee 100644 --- a/models/commit.go +++ b/models/commit.go @@ -51,7 +51,8 @@ func FulltextSearchCommits(userid int64, q string, limit int, offset int) ([]*Co sess.Where("NOT repository.is_private") } if q != "" { - sess.Where(x.FulltextMatch("message"), q) + cond, params := x.FulltextMatch("message", q) + sess.Where(cond, params...) } var countSess xorm.Session countSess = *sess diff --git a/vendor/github.com/go-xorm/core/dialect.go b/vendor/github.com/go-xorm/core/dialect.go index 8442461c..508dff5d 100644 --- a/vendor/github.com/go-xorm/core/dialect.go +++ b/vendor/github.com/go-xorm/core/dialect.go @@ -52,7 +52,7 @@ type Dialect interface { IndexOnTable() bool ShowCreateNull() bool - FulltextMatch(column string) string + FulltextMatch(column string, query string) (string, []interface{}) IndexCheckSql(tableName, idxName string) (string, []interface{}) TableCheckSql(tableName string) (string, []interface{}) @@ -141,8 +141,8 @@ func (b *Base) EqStr() string { return "=" } -func (db *Base) FulltextMatch(column string) string { - return "? = ''" +func (db *Base) FulltextMatch(column string, query string) (string, []interface{}) { + return "1=0", nil } func (db *Base) RollBackStr() string { diff --git a/vendor/github.com/go-xorm/xorm/engine.go b/vendor/github.com/go-xorm/xorm/engine.go index 3f94d870..003f3b27 100644 --- a/vendor/github.com/go-xorm/xorm/engine.go +++ b/vendor/github.com/go-xorm/xorm/engine.go @@ -123,8 +123,8 @@ func (engine *Engine) QuoteStr() string { return engine.dialect.QuoteStr() } -func (engine *Engine) FulltextMatch(column string) string { - return engine.dialect.FulltextMatch(column) +func (engine *Engine) FulltextMatch(column string, query string) (string, []interface{}) { + return engine.dialect.FulltextMatch(column, query) } // Quote Use QuoteStr quote the string sql diff --git a/vendor/github.com/go-xorm/xorm/mysql_dialect.go b/vendor/github.com/go-xorm/xorm/mysql_dialect.go index 0ac92c0a..0537f919 100644 --- a/vendor/github.com/go-xorm/xorm/mysql_dialect.go +++ b/vendor/github.com/go-xorm/xorm/mysql_dialect.go @@ -10,6 +10,7 @@ import ( "strconv" "strings" "time" + "regexp" "github.com/go-xorm/core" ) @@ -275,8 +276,10 @@ func (db *mysql) IndexOnTable() bool { return true } -func (db *mysql) FulltextMatch(column string) string { - return fmt.Sprintf("match(%s) against (? in boolean mode)", db.Quote(column)) +func (db *mysql) FulltextMatch(column string, query string) (string, []interface{}) { + reg := regexp.MustCompile(`\s+`) + return fmt.Sprintf("match(%s) against (? in boolean mode)", db.Quote(column)), + []interface{}{ reg.ReplaceAllLiteralString(query, " +") } } func (db *mysql) IndexCheckSql(tableName, idxName string) (string, []interface{}) { diff --git a/vendor/github.com/go-xorm/xorm/postgres_dialect.go b/vendor/github.com/go-xorm/xorm/postgres_dialect.go index 3c7b62a1..37e78493 100644 --- a/vendor/github.com/go-xorm/xorm/postgres_dialect.go +++ b/vendor/github.com/go-xorm/xorm/postgres_dialect.go @@ -862,8 +862,8 @@ func (db *postgres) IndexOnTable() bool { return false } -func (db *postgres) FulltextMatch(column string) string { - return fmt.Sprintf("to_tsvector(%s) @@ to_tsquery(?)", db.Quote(column)) +func (db *postgres) FulltextMatch(column string, query string) (string, []interface{}) { + return fmt.Sprintf("to_tsvector(%s) @@ to_tsquery(?)", db.Quote(column)), []interface{} { query } } func (db *postgres) IndexCheckSql(tableName, idxName string) (string, []interface{}) {