Skip to content

Commit

Permalink
fix: mysql FULLTEXT search (#2840)
Browse files Browse the repository at this point in the history
  • Loading branch information
BoYanZh authored Dec 30, 2022
1 parent f777a2f commit 143e4cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
9 changes: 5 additions & 4 deletions internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ var db *gorm.DB

func Init(d *gorm.DB) {
db = d
var err error
err := AutoMigrate(new(model.Storage), new(model.User), new(model.Meta), new(model.SettingItem), new(model.SearchNode))
switch conf.Conf.Database.Type {
case "sqlite3":
err = AutoMigrate(new(model.Storage), new(model.User), new(model.Meta), new(model.SettingItem), new(model.SearchNode))
case "mysql":
err = AutoMigrate(new(model.Storage), new(model.User), new(model.Meta), new(model.SettingItem), new(model.SearchNodeMySQL))
if err == nil {
tableName := fmt.Sprintf("%ssearch_nodes", conf.Conf.Database.TablePrefix)
db.Exec(fmt.Sprintf("CREATE FULLTEXT INDEX idx_%s_name_fulltext ON %s(name);", tableName, tableName))
}
case "postgres":
err = AutoMigrate(new(model.Storage), new(model.User), new(model.Meta), new(model.SettingItem), new(model.SearchNode))
if err == nil {
db.Exec("CREATE EXTENSION pg_trgm;")
db.Exec("CREATE EXTENSION btree_gin;")
Expand Down
7 changes: 0 additions & 7 deletions internal/model/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ type SearchReq struct {
PageReq
}

type SearchNodeMySQL struct {
Parent string `json:"parent" gorm:"index"`
Name string `json:"name" gorm:"index:,class:FULLTEXT"`
IsDir bool `json:"is_dir"`
Size int64 `json:"size"`
}

type SearchNode struct {
Parent string `json:"parent" gorm:"index"`
Name string `json:"name"`
Expand Down

0 comments on commit 143e4cd

Please sign in to comment.