From 0249c4e1c7fc1545536572150142cca9d22791b5 Mon Sep 17 00:00:00 2001 From: satori Date: Sun, 17 Nov 2024 00:31:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=85=A8=E6=96=87=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++++ api/graphql.go | 28 ++++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0f2b6db..67b4c9b 100644 --- a/README.md +++ b/README.md @@ -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_g ON web_images(color_1_g); CREATE INDEX idx_color_1_b ON web_images(color_1_b); + +-- 全文索引 +CREATE FULLTEXT INDEX idx_images_desc ON web_images (images_desc); + + ``` ```bash diff --git a/api/graphql.go b/api/graphql.go index bafdb19..8906f32 100644 --- a/api/graphql.go +++ b/api/graphql.go @@ -502,16 +502,12 @@ func NewSchema(config Config) (graphql.Schema, error) { }, }), Args: graphql.FieldConfigArgument{ - "style": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏风格筛选图像"}, - "device": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏平台筛选图像"}, - "orientation": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏版式筛选图像"}, - "era": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏年份筛选图像"}, - "category_id": &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: "按游戏材质筛选图像(支持多选)"}, - + "style": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏风格筛选图像"}, + "device": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏平台筛选图像"}, + "orientation": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏版式筛选图像"}, + "era": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏年份筛选图像"}, + "category_id": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏类型筛选图像(支持多选)"}, + "tags": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏标签筛选图像(支持多选)"}, "color": &graphql.ArgumentConfig{Type: graphql.String, Description: "按主色调筛选图像, 使用十六进制颜色代码(#FF1414)"}, "explorer_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 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 { @@ -666,6 +662,14 @@ func NewSchema(config Config) (graphql.Schema, error) { 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 { query = query.Join(goqu.T("web_praise"), goqu.On( @@ -733,7 +737,7 @@ func NewSchema(config Config) (graphql.Schema, error) { // 按游戏类型筛选图像(逗号分割且去除空格) if p.Args["category_id"] != nil { - category_ids := strings.Split(strings.ReplaceAll(p.Args["category_id"].(string), " ", ""), ", ") + category_ids := strings.Split(strings.ReplaceAll(p.Args["category_id"].(string), " ", ""), ",") query = query.Join(goqu.T("web_article_category"), goqu.On( goqu.I("web_images.article_id").Eq(goqu.I("web_article_category.article_id")), goqu.I("web_article_category.category_id").In(category_ids),