Skip to content

Commit

Permalink
feat: allow database fulltext parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Mmx233 committed Aug 24, 2024
1 parent 868b0ec commit 3648d3e
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 39 deletions.
4 changes: 2 additions & 2 deletions drivers/139/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import (
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/pkg/cron"
"github.com/alist-org/alist/v3/pkg/utils"
log "github.com/sirupsen/logrus"
)

type Yun139 struct {
model.Storage
Addition
cron *cron.Cron
cron *cron.Cron
Account string
}

Expand Down
12 changes: 6 additions & 6 deletions drivers/139/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ type PersonalUploadResp struct {
}

type RefreshTokenResp struct {
XMLName xml.Name `xml:"root"`
Return string `xml:"return"`
Token string `xml:"token"`
Expiretime int32 `xml:"expiretime"`
AccessToken string `xml:"accessToken"`
Desc string `xml:"desc"`
XMLName xml.Name `xml:"root"`
Return string `xml:"return"`
Token string `xml:"token"`
Expiretime int32 `xml:"expiretime"`
AccessToken string `xml:"accessToken"`
Desc string `xml:"desc"`
}
2 changes: 1 addition & 1 deletion drivers/139/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (

"github.com/alist-org/alist/v3/drivers/base"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/op"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/pkg/utils/random"
"github.com/alist-org/alist/v3/internal/op"
"github.com/go-resty/resty/v2"
jsoniter "github.com/json-iterator/go"
log "github.com/sirupsen/logrus"
Expand Down
2 changes: 1 addition & 1 deletion drivers/aliyundrive/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (d *AliDrive) createSession() error {
"refreshToken": d.RefreshToken,
})
}, nil)
if err == nil{
if err == nil {
state.retry = 0
}
return err
Expand Down
4 changes: 2 additions & 2 deletions drivers/crypt/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ type Addition struct {
EncryptedSuffix string `json:"encrypted_suffix" required:"true" default:".bin" help:"for advanced user only! encrypted files will have this suffix"`
FileNameEncoding string `json:"filename_encoding" type:"select" required:"true" options:"base64,base32,base32768" default:"base64" help:"for advanced user only!"`

Thumbnail bool `json:"thumbnail" required:"true" default:"false" help:"enable thumbnail which pre-generated under .thumbnails folder"`
Thumbnail bool `json:"thumbnail" required:"true" default:"false" help:"enable thumbnail which pre-generated under .thumbnails folder"`

ShowHidden bool `json:"show_hidden" default:"true" required:"false" help:"show hidden directories and files"`
ShowHidden bool `json:"show_hidden" default:"true" required:"false" help:"show hidden directories and files"`
}

var config = driver.Config{
Expand Down
4 changes: 2 additions & 2 deletions drivers/google_photo/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type MediaItem struct {
CoverPhotoBaseUrl string `json:"coverPhotoBaseUrl,omitempty"`
MimeType string `json:"mimeType,omitempty"`
FileName string `json:"filename,omitempty"`
MediaMetadata MediaMetadata `json:"mediaMetadata,omitempty"`
MediaMetadata MediaMetadata `json:"mediaMetadata,omitempty"`
}

type MediaMetadata struct {
Expand All @@ -44,7 +44,7 @@ type Video struct {
}

func fileToObj(f MediaItem) *model.ObjThumb {
if !reflect.DeepEqual(f.MediaMetadata, MediaMetadata{}){
if !reflect.DeepEqual(f.MediaMetadata, MediaMetadata{}) {
return &model.ObjThumb{
Object: model.Object{
ID: f.Id,
Expand Down
16 changes: 8 additions & 8 deletions drivers/google_photo/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
// do others that not defined in Driver interface

const (
FETCH_ALL = "all"
FETCH_ALBUMS = "albums"
FETCH_ROOT = "root"
FETCH_ALL = "all"
FETCH_ALBUMS = "albums"
FETCH_ROOT = "root"
FETCH_SHARE_ALBUMS = "share_albums"
)

Expand Down Expand Up @@ -89,15 +89,15 @@ func (d *GooglePhoto) getFiles(id string) ([]MediaItem, error) {
func (d *GooglePhoto) getFakeRoot() ([]MediaItem, error) {
return []MediaItem{
{
Id: FETCH_ALL,
Id: FETCH_ALL,
Title: "全部媒体",
},
{
Id: FETCH_ALBUMS,
Id: FETCH_ALBUMS,
Title: "全部影集",
},
{
Id: FETCH_SHARE_ALBUMS,
Id: FETCH_SHARE_ALBUMS,
Title: "共享影集",
},
}, nil
Expand Down Expand Up @@ -131,7 +131,7 @@ func (d *GooglePhoto) getMedias(albumId string) ([]MediaItem, error) {
map[string]string{
"fields": "mediaItems(id,baseUrl,mimeType,mediaMetadata,filename),nextPageToken",
"pageSize": "100",
"albumId": albumId,
"albumId": albumId,
"pageToken": "first",
}, http.MethodPost)
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func (d *GooglePhoto) getMedia(id string) (MediaItem, error) {
return resp, nil
}

func (d *GooglePhoto) fetchItems(url string, query map[string]string, method string) ([]MediaItem, error){
func (d *GooglePhoto) fetchItems(url string, query map[string]string, method string) ([]MediaItem, error) {
res := make([]MediaItem, 0)
for query["pageToken"] != "" {
if query["pageToken"] == "first" {
Expand Down
1 change: 1 addition & 0 deletions drivers/lark.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build (linux || darwin || windows) && (amd64 || arm64)
// +build linux darwin windows
// +build amd64 arm64

Expand Down
2 changes: 1 addition & 1 deletion drivers/seafile/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Addition struct {
Address string `json:"address" required:"true"`
UserName string `json:"username" required:"false"`
Password string `json:"password" required:"false"`
Token string `json:"token" required:"false"`
Token string `json:"token" required:"false"`
RepoId string `json:"repoId" required:"false"`
RepoPwd string `json:"repoPwd" required:"false"`
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/seafile/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ type LibraryInfo struct {
LibraryItemResp
decryptedTime time.Time
decryptedSuccess bool
}
}
2 changes: 0 additions & 2 deletions drivers/seafile/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,3 @@ func (d *Seafile) decryptLibrary(repo *LibraryInfo) (err error) {
repo.decryptedSuccess = true
return nil
}


18 changes: 9 additions & 9 deletions drivers/trainbit/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import (
type Addition struct {
driver.RootID
AUSHELLPORTAL string `json:"AUSHELLPORTAL" required:"true"`
ApiKey string `json:"apikey" required:"true"`
ApiKey string `json:"apikey" required:"true"`
}

var config = driver.Config{
Name: "Trainbit",
LocalSort: false,
OnlyLocal: false,
OnlyProxy: false,
NoCache: false,
NoUpload: false,
NeedMs: false,
DefaultRoot: "0_000",
Name: "Trainbit",
LocalSort: false,
OnlyLocal: false,
OnlyProxy: false,
NoCache: false,
NoUpload: false,
NeedMs: false,
DefaultRoot: "0_000",
}

func init() {
Expand Down
2 changes: 1 addition & 1 deletion drivers/trainbit/types.go
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package trainbit
package trainbit
1 change: 1 addition & 0 deletions internal/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Database struct {
TablePrefix string `json:"table_prefix" env:"TABLE_PREFIX"`
SSLMode string `json:"ssl_mode" env:"SSL_MODE"`
DSN string `json:"dsn" env:"DSN"`
Parser string `json:"parser" env:"PARSER"`
}

type Meilisearch struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/offline_download/tool/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func AddURL(ctx context.Context, args *AddURLArgs) (tache.TaskWithInfo, error) {
// 防止将下载好的文件删除
deletePolicy = DeleteNever
}

t := &DownloadTask{
Url: args.URL,
DstDirPath: args.DstDirPath,
Expand Down
11 changes: 9 additions & 2 deletions internal/search/db/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,26 @@ var config = searcher.Config{
func init() {
searcher.RegisterSearcher(config, func() (searcher.Searcher, error) {
db := db.GetDb()
var parser string
switch conf.Conf.Database.Type {
case "mysql":
if conf.Conf.Database.Parser != "" {
parser = fmt.Sprintf(" WITH PARSER %s", parser)
}
tableName := fmt.Sprintf("%ssearch_nodes", conf.Conf.Database.TablePrefix)
tx := db.Exec(fmt.Sprintf("CREATE FULLTEXT INDEX idx_%s_name_fulltext ON %s(name);", tableName, tableName))
tx := db.Exec(fmt.Sprintf("CREATE FULLTEXT INDEX idx_%s_name_fulltext%s ON %s(name);", tableName, parser, tableName))
if err := tx.Error; err != nil && !strings.Contains(err.Error(), "Error 1061 (42000)") { // duplicate error
log.Errorf("failed to create full text index: %v", err)
return nil, err
}
case "postgres":
if conf.Conf.Database.Parser != "" {
parser = fmt.Sprintf(" gin_%s", parser)
}
db.Exec("CREATE EXTENSION pg_trgm;")
db.Exec("CREATE EXTENSION btree_gin;")
tableName := fmt.Sprintf("%ssearch_nodes", conf.Conf.Database.TablePrefix)
tx := db.Exec(fmt.Sprintf("CREATE INDEX idx_%s_name ON %s USING GIN (name);", tableName, tableName))
tx := db.Exec(fmt.Sprintf("CREATE INDEX idx_%s_name ON %s USING GIN (name%s);", tableName, parser, tableName))
if err := tx.Error; err != nil && !strings.Contains(err.Error(), "SQLSTATE 42P07") {
log.Errorf("failed to create index using GIN: %v", err)
return nil, err
Expand Down

0 comments on commit 3648d3e

Please sign in to comment.