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

fix: mysql FULLTEXT search #2840

Merged
merged 1 commit into from
Dec 30, 2022
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: 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