feat(cool): 修改关键词搜索逻辑以支持文本类型匹配 将 WhereOrLike 查询方式改为 WhereOrf,使用 PostgreSQL 的文本类型转换语法, 通过 field::text LIKE 来实现更准确的关键词匹配功能。 fix(config): 为店铺服务添加默认查询条件和字段选择 在 ShopService 中增加 ListQueryOp 配置,设置默认查询条件 is_enable=1 和指定的字段选择列表,优化查询性能并确保数据有效性。 ```
This commit is contained in:
@@ -208,7 +208,9 @@ func (s *Service) ServiceList(ctx context.Context, req *ListReq) (data interface
|
||||
for _, field := range s.ListQueryOp.KeyWordField {
|
||||
// g.DumpWithType(field)
|
||||
// builder.WhereLike(field, "%"+r.Get("keyWord").String()+"%")
|
||||
builder = builder.WhereOrLike(field, "%"+r.Get("keyWord").String()+"%")
|
||||
|
||||
builder = builder.WhereOrf(field+"::text LIKE ?", "%"+r.Get("keyWord").String()+"%")
|
||||
//builder = builder.WhereOrLike(field, "%"+r.Get("keyWord").String()+"%")
|
||||
}
|
||||
m.Where(builder)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ package service
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type ShopService struct {
|
||||
@@ -13,6 +16,15 @@ func NewShopService() *ShopService {
|
||||
return &ShopService{
|
||||
&cool.Service{
|
||||
Model: model.NewShopConfig(),
|
||||
ListQueryOp: &cool.QueryOp{
|
||||
Where: func(ctx context.Context) []g.Array {
|
||||
return [][]interface{}{
|
||||
|
||||
{"is_enable", 1, true},
|
||||
}
|
||||
},
|
||||
Select: "product_id,product_name,seerdou_price,jindou_price,remark",
|
||||
},
|
||||
|
||||
PageQueryOp: &cool.QueryOp{
|
||||
KeyWordField: []string{"desc", "product_name"},
|
||||
|
||||
Reference in New Issue
Block a user