Create fulltext index on commit.message
parent
2055178f3c
commit
43a14306dc
|
@ -12,7 +12,7 @@ type Commit struct {
|
||||||
ID int64
|
ID int64
|
||||||
RepoID int64 `xorm:"UNIQUE(commit_repo_sha)"`
|
RepoID int64 `xorm:"UNIQUE(commit_repo_sha)"`
|
||||||
Sha string `xorm:"VARCHAR(40) UNIQUE(commit_repo_sha)"`
|
Sha string `xorm:"VARCHAR(40) UNIQUE(commit_repo_sha)"`
|
||||||
Message string
|
Message string `xorm:"TEXT FULLTEXT(commit_message)"`
|
||||||
AuthorEmail string
|
AuthorEmail string
|
||||||
AuthorName string
|
AuthorName string
|
||||||
AuthorTime time.Time
|
AuthorTime time.Time
|
||||||
|
@ -20,8 +20,3 @@ type Commit struct {
|
||||||
CommitterName string
|
CommitterName string
|
||||||
CommitterTime time.Time
|
CommitterTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommitParent struct {
|
|
||||||
ParentId int64 `xorm:"pk"`
|
|
||||||
ChildId int64 `xorm:"pk"`
|
|
||||||
}
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ func init() {
|
||||||
new(Mirror), new(Release), new(LoginSource), new(Webhook), new(HookTask),
|
new(Mirror), new(Release), new(LoginSource), new(Webhook), new(HookTask),
|
||||||
new(ProtectBranch), new(ProtectBranchWhitelist),
|
new(ProtectBranch), new(ProtectBranchWhitelist),
|
||||||
new(Team), new(OrgUser), new(TeamUser), new(TeamRepo),
|
new(Team), new(OrgUser), new(TeamUser), new(TeamRepo),
|
||||||
new(Notice), new(EmailAddress), new(Commit), new(CommitParent))
|
new(Notice), new(EmailAddress), new(Commit))
|
||||||
|
|
||||||
gonicNames := []string{"SSL"}
|
gonicNames := []string{"SSL"}
|
||||||
for _, name := range gonicNames {
|
for _, name := range gonicNames {
|
||||||
|
|
|
@ -201,6 +201,8 @@ func (db *Base) CreateIndexSql(tableName string, index *Index) string {
|
||||||
var idxName string
|
var idxName string
|
||||||
if index.Type == UniqueType {
|
if index.Type == UniqueType {
|
||||||
unique = " UNIQUE"
|
unique = " UNIQUE"
|
||||||
|
} else if index.Type == FulltextType {
|
||||||
|
unique = " FULLTEXT"
|
||||||
}
|
}
|
||||||
idxName = index.XName(tableName)
|
idxName = index.XName(tableName)
|
||||||
return fmt.Sprintf("CREATE%s INDEX %v ON %v (%v)", unique,
|
return fmt.Sprintf("CREATE%s INDEX %v ON %v (%v)", unique,
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
const (
|
const (
|
||||||
IndexType = iota + 1
|
IndexType = iota + 1
|
||||||
UniqueType
|
UniqueType
|
||||||
|
FulltextType
|
||||||
)
|
)
|
||||||
|
|
||||||
// database index
|
// database index
|
||||||
|
|
|
@ -909,7 +909,7 @@ func (engine *Engine) mapType(v reflect.Value) *core.Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
indexNames := make(map[string]int)
|
indexNames := make(map[string]int)
|
||||||
var isIndex, isUnique bool
|
var isIndex, isUnique, isFulltext bool
|
||||||
var preKey string
|
var preKey string
|
||||||
for j, key := range tags {
|
for j, key := range tags {
|
||||||
k := strings.ToUpper(key)
|
k := strings.ToUpper(key)
|
||||||
|
@ -971,6 +971,11 @@ func (engine *Engine) mapType(v reflect.Value) *core.Table {
|
||||||
indexNames[indexName] = core.UniqueType
|
indexNames[indexName] = core.UniqueType
|
||||||
case k == "UNIQUE":
|
case k == "UNIQUE":
|
||||||
isUnique = true
|
isUnique = true
|
||||||
|
case strings.HasPrefix(k, "FULLTEXT(") && strings.HasSuffix(k, ")"):
|
||||||
|
indexName := k[len("FULLTEXT")+1 : len(k)-1]
|
||||||
|
indexNames[indexName] = core.FulltextType
|
||||||
|
case k == "FULLTEXT":
|
||||||
|
isFulltext = true
|
||||||
case k == "NOTNULL":
|
case k == "NOTNULL":
|
||||||
col.Nullable = false
|
col.Nullable = false
|
||||||
case k == "CACHE":
|
case k == "CACHE":
|
||||||
|
@ -1056,6 +1061,8 @@ func (engine *Engine) mapType(v reflect.Value) *core.Table {
|
||||||
|
|
||||||
if isUnique {
|
if isUnique {
|
||||||
indexNames[col.Name] = core.UniqueType
|
indexNames[col.Name] = core.UniqueType
|
||||||
|
} else if isFulltext {
|
||||||
|
indexNames[col.Name] = core.FulltextType
|
||||||
} else if isIndex {
|
} else if isIndex {
|
||||||
indexNames[col.Name] = core.IndexType
|
indexNames[col.Name] = core.IndexType
|
||||||
}
|
}
|
||||||
|
|
|
@ -879,6 +879,15 @@ func (db *postgres) TableCheckSql(tableName string) (string, []interface{}) {
|
||||||
" AND column_name = ?", args
|
" AND column_name = ?", args
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
func (db *postgres) CreateIndexSql(tableName string, index *core.Index) string {
|
||||||
|
if index.Type == core.FulltextType {
|
||||||
|
idxName := index.XName(tableName)
|
||||||
|
return fmt.Sprintf("CREATE INDEX %v ON %v USING GIN (to_tsvector(%v))",
|
||||||
|
db.Quote(idxName), db.Quote(tableName), db.Quote(strings.Join(index.Cols, db.Quote("||' '||"))))
|
||||||
|
}
|
||||||
|
return db.Base.CreateIndexSql(tableName, index)
|
||||||
|
}
|
||||||
|
|
||||||
func (db *postgres) ModifyColumnSql(tableName string, col *core.Column) string {
|
func (db *postgres) ModifyColumnSql(tableName string, col *core.Column) string {
|
||||||
return fmt.Sprintf("alter table %s ALTER COLUMN %s TYPE %s",
|
return fmt.Sprintf("alter table %s ALTER COLUMN %s TYPE %s",
|
||||||
tableName, col.Name, db.SqlType(col))
|
tableName, col.Name, db.SqlType(col))
|
||||||
|
@ -1073,9 +1082,16 @@ func (db *postgres) GetIndexes(tableName string) (map[string]*core.Index, error)
|
||||||
} else {
|
} else {
|
||||||
indexType = core.IndexType
|
indexType = core.IndexType
|
||||||
}
|
}
|
||||||
cs := strings.Split(indexdef, "(")
|
cs := strings.SplitN(indexdef, "(", 2)
|
||||||
colNames = strings.Split(cs[1][0:len(cs[1])-1], ",")
|
colNames = strings.Split(cs[1][0:len(cs[1])-1], ",")
|
||||||
|
|
||||||
|
for i, colName := range colNames {
|
||||||
|
if strings.HasPrefix(colName, "to_tsvector(") {
|
||||||
|
colNames[i] = colName[len("to_tsvector("):len(colName)-1]
|
||||||
|
indexType = core.FulltextType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
||||||
newIdxName := indexName[5+len(tableName):]
|
newIdxName := indexName[5+len(tableName):]
|
||||||
if newIdxName != "" {
|
if newIdxName != "" {
|
||||||
|
|
|
@ -1046,11 +1046,9 @@ func (statement *Statement) genCreateTableSQL() string {
|
||||||
func (statement *Statement) genIndexSQL() []string {
|
func (statement *Statement) genIndexSQL() []string {
|
||||||
var sqls []string
|
var sqls []string
|
||||||
tbName := statement.TableName()
|
tbName := statement.TableName()
|
||||||
quote := statement.Engine.Quote
|
for _, index := range statement.RefTable.Indexes {
|
||||||
for idxName, index := range statement.RefTable.Indexes {
|
if index.Type == core.IndexType || index.Type == core.FulltextType {
|
||||||
if index.Type == core.IndexType {
|
sql := statement.Engine.dialect.CreateIndexSql(tbName, index)
|
||||||
sql := fmt.Sprintf("CREATE INDEX %v ON %v (%v);", quote(indexName(tbName, idxName)),
|
|
||||||
quote(tbName), quote(strings.Join(index.Cols, quote(","))))
|
|
||||||
sqls = append(sqls, sql)
|
sqls = append(sqls, sql)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue