标签全文索引搜索

This commit is contained in:
2024-11-17 00:31:31 +08:00
parent 84a0b8e711
commit 0249c4e1c7
2 changed files with 21 additions and 12 deletions

View File

@@ -32,6 +32,11 @@ CREATE INDEX idx_color_0_b ON web_images(color_0_b);
CREATE INDEX idx_color_1_r ON web_images(color_1_r); CREATE INDEX idx_color_1_r ON web_images(color_1_r);
CREATE INDEX idx_color_1_g ON web_images(color_1_g); CREATE INDEX idx_color_1_g ON web_images(color_1_g);
CREATE INDEX idx_color_1_b ON web_images(color_1_b); CREATE INDEX idx_color_1_b ON web_images(color_1_b);
-- 全文索引
CREATE FULLTEXT INDEX idx_images_desc ON web_images (images_desc);
``` ```
```bash ```bash

View File

@@ -507,11 +507,7 @@ func NewSchema(config Config) (graphql.Schema, error) {
"orientation": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏版式筛选图像"}, "orientation": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏版式筛选图像"},
"era": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏年份筛选图像"}, "era": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏年份筛选图像"},
"category_id": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏类型筛选图像(支持多选)"}, "category_id": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏类型筛选图像(支持多选)"},
"tags": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏标签筛选图像(支持多选)"},
"tags": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏标签筛选图像(支持多选)(主题)"},
"paramImagesDescFunc": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏功能筛选图像(支持多选)"},
"paramImagesDescMaterial": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏材质筛选图像(支持多选)"},
"color": &graphql.ArgumentConfig{Type: graphql.String, Description: "按主色调筛选图像, 使用十六进制颜色代码(#FF1414)"}, "color": &graphql.ArgumentConfig{Type: graphql.String, Description: "按主色调筛选图像, 使用十六进制颜色代码(#FF1414)"},
"explorer_id": &graphql.ArgumentConfig{Type: graphql.Int, Description: "筛选图像中指定收藏夹的"}, "explorer_id": &graphql.ArgumentConfig{Type: graphql.Int, Description: "筛选图像中指定收藏夹的"},
"collect_id": &graphql.ArgumentConfig{Type: graphql.Int, Description: "筛选图像中指定收藏夹的"}, "collect_id": &graphql.ArgumentConfig{Type: graphql.Int, Description: "筛选图像中指定收藏夹的"},
@@ -562,7 +558,7 @@ func NewSchema(config Config) (graphql.Schema, error) {
var query = goqu.Dialect("mysql").From("web_images") var query = goqu.Dialect("mysql").From("web_images")
// 参数映射 // 参数映射
var argFormat = []string{"id", "width", "height", "content", "remark", "description", "tags", "rank", "comment_num", "praise_count", "collect_count", "article_id", "user_id"} var argFormat = []string{"id", "width", "height", "content", "remark", "description", "rank", "comment_num", "praise_count", "collect_count", "article_id", "user_id"}
// 筛选条件 // 筛选条件
for _, format := range argFormat { for _, format := range argFormat {
@@ -666,6 +662,14 @@ func NewSchema(config Config) (graphql.Schema, error) {
applyTimeCondition("update_time", p.Args["update_time"].(string)) applyTimeCondition("update_time", p.Args["update_time"].(string))
} }
// 数据库中筛选:按游戏标签
if p.Args["tags"] != nil {
tags := strings.Split(strings.ReplaceAll(p.Args["tags"].(string), " ", ""), ",")
for _, tag := range tags {
query = query.Where(goqu.L("MATCH(images_desc) AGAINST (? IN NATURAL LANGUAGE MODE)", tag))
}
}
// 数据库中筛选:喜欢的截图 // 数据库中筛选:喜欢的截图
if p.Args["praise"] != nil { if p.Args["praise"] != nil {
query = query.Join(goqu.T("web_praise"), goqu.On( query = query.Join(goqu.T("web_praise"), goqu.On(