Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
search_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
38bd01b0
authored
Jul 23, 2020
by
孙龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
up
parent
5f5216e7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
241 additions
and
25 deletions
controller/ziyin_controller.go
model/goods.go
pkg/common/page.go
routes/router.go
service/ziyin_service.go
test/test7.go
controller/ziyin_controller.go
View file @
38bd01b0
...
@@ -18,7 +18,7 @@ func Zyh(ctx *gin.Context){
...
@@ -18,7 +18,7 @@ func Zyh(ctx *gin.Context){
zyhRequest
[
requestName
]
=
strings
.
TrimSpace
(
requstValue
[
0
])
zyhRequest
[
requestName
]
=
strings
.
TrimSpace
(
requstValue
[
0
])
}
}
}
}
fmt
.
Println
(
zyhRequest
)
//
fmt.Println(zyhRequest)
zyServiceImpl
:=
service
.
NewZyServiceImpl
()
zyServiceImpl
:=
service
.
NewZyServiceImpl
()
...
...
model/goods.go
View file @
38bd01b0
...
@@ -72,6 +72,11 @@ type ApiGoods struct {
...
@@ -72,6 +72,11 @@ type ApiGoods struct {
type
ZiyinGoodsInfo
struct
{
type
ZiyinGoodsInfo
struct
{
GoodsNameOrg
string
`json:"goods_name_org"`
GoodsNameOrg
string
`json:"goods_name_org"`
SampleStatus
string
`json:"sample_status"`
SampleMaxNumber
string
`json:"sample_max_number"`
SampleClassId
string
`json:"sample_class_id"`
SampleClassIdName
string
`json:"sample_class_id_name"`
Quota
int
`json:"quota"`
DullGoodsData
DullGoodsData
}
}
...
...
pkg/common/page.go
0 → 100644
View file @
38bd01b0
package
common
import
"math"
//分页方法,根据传递过来的页数,每页数,总数,返回分页的内容 7个页数 前 1,2,3,4,5 后 的格式返回,小于5页返回具体页数
func
Paginator
(
page
,
prepage
int
,
nums
int64
)
map
[
string
]
interface
{}
{
var
firstpage
int
//前一页地址
var
lastpage
int
//后一页地址
//根据nums总数,和prepage每页数量 生成分页总数
totalpages
:=
int
(
math
.
Ceil
(
float64
(
nums
)
/
float64
(
prepage
)))
//page总数
if
page
>
totalpages
{
page
=
totalpages
}
if
page
<=
0
{
page
=
1
}
var
pages
[]
int
switch
{
case
page
>=
totalpages
-
5
&&
totalpages
>
5
:
//最后5页
start
:=
totalpages
-
5
+
1
firstpage
=
page
-
1
lastpage
=
int
(
math
.
Min
(
float64
(
totalpages
),
float64
(
page
+
1
)))
pages
=
make
([]
int
,
5
)
for
i
,
_
:=
range
pages
{
pages
[
i
]
=
start
+
i
}
case
page
>=
3
&&
totalpages
>
5
:
start
:=
page
-
3
+
1
pages
=
make
([]
int
,
5
)
firstpage
=
page
-
3
for
i
,
_
:=
range
pages
{
pages
[
i
]
=
start
+
i
}
firstpage
=
page
-
1
lastpage
=
page
+
1
default
:
pages
=
make
([]
int
,
int
(
math
.
Min
(
5
,
float64
(
totalpages
))))
for
i
,
_
:=
range
pages
{
pages
[
i
]
=
i
+
1
}
firstpage
=
int
(
math
.
Max
(
float64
(
1
),
float64
(
page
-
1
)))
lastpage
=
page
+
1
//fmt.Println(pages)
}
paginatorMap
:=
make
(
map
[
string
]
interface
{})
paginatorMap
[
"pages"
]
=
pages
paginatorMap
[
"totalpages"
]
=
totalpages
paginatorMap
[
"firstpage"
]
=
firstpage
paginatorMap
[
"lastpage"
]
=
lastpage
paginatorMap
[
"currpage"
]
=
page
return
paginatorMap
}
\ No newline at end of file
routes/router.go
View file @
38bd01b0
...
@@ -20,6 +20,7 @@ func InitRouter() *gin.Engine {
...
@@ -20,6 +20,7 @@ func InitRouter() *gin.Engine {
r
.
POST
(
"/search/bom/autospu"
,
controller
.
AutoSpu
)
r
.
POST
(
"/search/bom/autospu"
,
controller
.
AutoSpu
)
r
.
POST
(
"/search/bom/recommend"
,
controller
.
Recommend
)
r
.
POST
(
"/search/bom/recommend"
,
controller
.
Recommend
)
r
.
POST
(
"search/ZiYing/zyh"
,
controller
.
Zyh
)
r
.
POST
(
"search/ZiYing/zyh"
,
controller
.
Zyh
)
r
.
GET
(
"search/ZiYing/zyh"
,
controller
.
Zyh
)
r
.
POST
(
"search/mouser/GetMouserData"
,
controller
.
GetMouserData
)
r
.
POST
(
"search/mouser/GetMouserData"
,
controller
.
GetMouserData
)
r
.
GET
(
"search/mouser/GetMouserData"
,
controller
.
GetMouserData
)
r
.
GET
(
"search/mouser/GetMouserData"
,
controller
.
GetMouserData
)
...
...
service/ziyin_service.go
View file @
38bd01b0
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
"github.com/syyongx/php2go"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5"
"gopkg.in/olivere/elastic.v5"
"math"
"regexp"
"regexp"
"search_server/middleware"
"search_server/middleware"
"search_server/model"
"search_server/model"
...
@@ -24,6 +25,9 @@ import (
...
@@ -24,6 +25,9 @@ import (
type
ZyServiceImpl
struct
{}
type
ZyServiceImpl
struct
{}
var
isAdmin
bool
var
zy_orgin_search
=
make
(
map
[
string
]
string
)
/*
/*
自营搜索
自营搜索
...
@@ -33,10 +37,11 @@ func (this *ZyServiceImpl) Zyh(ctx *gin.Context, req map[string]string) (rsp *mo
...
@@ -33,10 +37,11 @@ func (this *ZyServiceImpl) Zyh(ctx *gin.Context, req map[string]string) (rsp *mo
need_aggs
bool
need_aggs
bool
_type
byte
_type
byte
)
)
if
req
[
"need_aggs"
]
!=
""
{
isAdmin
=
false
need_aggs
=
false
if
req
[
"need_aggs"
]
==
"1"
{
}
else
{
need_aggs
=
true
need_aggs
=
true
}
else
{
need_aggs
=
false
}
}
need_aggs
=
need_aggs
need_aggs
=
need_aggs
...
@@ -125,6 +130,7 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){
...
@@ -125,6 +130,7 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){
}
}
req2
:=
make
(
map
[
string
]
string
,
0
)
req2
:=
make
(
map
[
string
]
string
,
0
)
req2
=
common
.
CopyMapString
(
req
)
req2
=
common
.
CopyMapString
(
req
)
zy_orgin_search
=
common
.
CopyMapString
(
req
)
//原始搜索數據
delete
(
req2
,
"class_id/condition"
)
delete
(
req2
,
"class_id/condition"
)
rsp
=
searchZiYingGoods
(
req2
,
true
,
zhyClassList
,
classLight
,
_type
)
rsp
=
searchZiYingGoods
(
req2
,
true
,
zhyClassList
,
classLight
,
_type
)
//fmt.Printf("返回數據:%+v",rsp)
//fmt.Printf("返回數據:%+v",rsp)
...
@@ -147,8 +153,9 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
...
@@ -147,8 +153,9 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
is_sample
bool
is_sample
bool
redisConn
redis
.
Conn
redisConn
redis
.
Conn
response
map
[
string
]
interface
{}
response
map
[
string
]
interface
{}
responseDataList
[]
interface
{}
defaultSort
bool
)
)
defer
func
()
{
defer
func
()
{
redisConn
.
Close
()
redisConn
.
Close
()
}()
}()
...
@@ -156,7 +163,9 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
...
@@ -156,7 +163,9 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
rsp
=
&
model
.
ZyhResponse
{}
rsp
=
&
model
.
ZyhResponse
{}
rsp
.
ErrorMsg
=
""
rsp
.
ErrorMsg
=
""
rsp
.
ErrorCode
=
0
rsp
.
ErrorCode
=
0
defaultSort
=
true
response
=
make
(
map
[
string
]
interface
{},
0
)
response
=
make
(
map
[
string
]
interface
{},
0
)
responseDataList
=
make
([]
interface
{},
0
)
keyword
=
""
keyword
=
""
goods_name_arr
=
make
([]
string
,
0
)
goods_name_arr
=
make
([]
string
,
0
)
...
@@ -219,37 +228,45 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
...
@@ -219,37 +228,45 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
//有货排序
//有货排序
if
avail_rank
,
ok
:=
req
[
"avail_rank"
];
ok
&&
strings
.
TrimSpace
(
avail_rank
)
==
"1"
{
if
avail_rank
,
ok
:=
req
[
"avail_rank"
];
ok
&&
strings
.
TrimSpace
(
avail_rank
)
==
"1"
{
avail_rank
=
strings
.
TrimSpace
(
avail_rank
)
avail_rank
=
strings
.
TrimSpace
(
avail_rank
)
source
.
Sort
(
"sort"
,
true
)
source
.
Sort
(
"sort"
,
false
)
////desc
query
.
Must
(
elastic
.
NewTermQuery
(
"sort"
,
31
))
query
.
Must
(
elastic
.
NewTermQuery
(
"sort"
,
31
))
defaultSort
=
false
}
}
//价格排序
//价格排序
if
single_rank
,
ok
:=
req
[
"single_rank"
];
ok
&&
single_rank
!=
""
{
if
single_rank
,
ok
:=
req
[
"single_rank"
];
ok
&&
single_rank
!=
""
{
switch
{
switch
{
case
single_rank
==
"1"
:
case
single_rank
==
"1"
:
source
.
Sort
(
"single_price"
,
fals
e
)
//asc
source
.
Sort
(
"single_price"
,
tru
e
)
//asc
case
single_rank
==
"2"
:
case
single_rank
==
"2"
:
source
.
Sort
(
"single_price"
,
tru
e
)
//desc
source
.
Sort
(
"single_price"
,
fals
e
)
//desc
}
}
defaultSort
=
false
}
}
//库存排序
//库存排序
if
stock_rank
,
ok
:=
req
[
"stock_rank"
];
ok
&&
stock_rank
!=
""
{
if
stock_rank
,
ok
:=
req
[
"stock_rank"
];
ok
&&
stock_rank
!=
""
{
switch
{
switch
{
case
strings
.
TrimSpace
(
stock_rank
)
==
"1"
:
case
strings
.
TrimSpace
(
stock_rank
)
==
"1"
:
source
.
Sort
(
"stock"
,
tru
e
)
//desc
source
.
Sort
(
"stock"
,
fals
e
)
//desc
case
strings
.
TrimSpace
(
stock_rank
)
==
"2"
:
case
strings
.
TrimSpace
(
stock_rank
)
==
"2"
:
source
.
Sort
(
"stock"
,
fals
e
)
//asc
source
.
Sort
(
"stock"
,
tru
e
)
//asc
}
}
defaultSort
=
false
}
}
//综合排序
//综合排序
if
com_rank
,
ok
:=
req
[
"com_rank"
];
ok
&&
strings
.
TrimSpace
(
com_rank
)
==
"1"
{
if
com_rank
,
ok
:=
req
[
"com_rank"
];
ok
&&
strings
.
TrimSpace
(
com_rank
)
==
"1"
{
source
.
Sort
(
"sort"
,
true
)
//desc
source
.
Sort
(
"sort"
,
true
)
//asc
source
.
Sort
(
"single_price"
,
false
)
//asc
source
.
Sort
(
"single_price"
,
false
)
//desc
defaultSort
=
false
}
if
defaultSort
{
source
.
Sort
(
"sort"
,
false
)
//desc
}
}
}
}
length
:=
int64
(
10
)
length
:=
int64
(
10
)
if
offset
,
ok
:=
req
[
"offset"
];
ok
{
if
offset
,
ok
:=
req
[
"offset"
];
ok
{
if
offsetInt
,
err
:=
strconv
.
ParseInt
(
offset
,
10
,
64
);
err
!=
nil
&&
offsetInt
>
0
{
if
offsetInt
,
err
:=
strconv
.
ParseInt
(
offset
,
10
,
64
);
err
!=
nil
&&
offsetInt
>
0
{
...
@@ -280,7 +297,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
...
@@ -280,7 +297,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
source
.
Query
(
query
)
source
.
Query
(
query
)
queryJson
,
_
:=
elastic
.
NewSearchRequest
()
.
Source
(
source
)
.
Body
()
queryJson
,
_
:=
elastic
.
NewSearchRequest
()
.
Source
(
source
)
.
Body
()
//
fmt.Println(queryJson)
fmt
.
Println
(
queryJson
)
result
,
err
:=
es
.
CurlES
(
config
.
Get
(
"ZIYING_CONFIG.Index"
)
.
String
(),
queryJson
)
result
,
err
:=
es
.
CurlES
(
config
.
Get
(
"ZIYING_CONFIG.Index"
)
.
String
(),
queryJson
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
err
)
log
.
Error
(
err
)
...
@@ -341,7 +358,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
...
@@ -341,7 +358,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
}
}
case
"packing"
:
case
"packing"
:
Self_UnitAliasInfo
,
err
:=
redis
.
String
(
redisConn
.
Do
(
"Hget"
,
"Self_UnitAlias"
,
aggregationsKeyBuckets
[
"key"
]))
Self_UnitAliasInfo
,
err
:=
redis
.
String
(
redisConn
.
Do
(
"Hget"
,
"Self_UnitAlias"
,
aggregationsKeyBuckets
[
"key"
]))
fmt
.
Println
(
"packing"
,
aggregationsKeyBuckets
[
"key"
],
Self_UnitAliasInfo
)
//
fmt.Println("packing",aggregationsKeyBuckets["key"],Self_UnitAliasInfo)
if
err
==
nil
{
if
err
==
nil
{
aggregationsKeyBucketsStr
=
Self_UnitAliasInfo
aggregationsKeyBucketsStr
=
Self_UnitAliasInfo
}
}
...
@@ -405,7 +422,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
...
@@ -405,7 +422,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
hitsHits
:=
gjson
.
Get
(
result
,
"hits.hits"
)
.
Array
()
hitsHits
:=
gjson
.
Get
(
result
,
"hits.hits"
)
.
Array
()
if
hitsTotal
>
0
&&
len
(
hits2_source
)
>
0
{
if
hitsTotal
>
0
&&
len
(
hits2_source
)
>
0
{
goodsIds
:=
gjson
.
Get
(
result
,
"hits.hits.#._id"
)
.
Array
()
goodsIds
:=
gjson
.
Get
(
result
,
"hits.hits.#._id"
)
.
Array
()
fmt
.
Println
(
"goodsIds"
,
goodsIds
)
//
fmt.Println("goodsIds",goodsIds)
goodsIdsStrArr
:=
make
([]
string
,
0
)
goodsIdsStrArr
:=
make
([]
string
,
0
)
for
_
,
v
:=
range
goodsIds
{
for
_
,
v
:=
range
goodsIds
{
goodsIdsStrArr
=
append
(
goodsIdsStrArr
,
v
.
String
())
goodsIdsStrArr
=
append
(
goodsIdsStrArr
,
v
.
String
())
...
@@ -419,19 +436,157 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
...
@@ -419,19 +436,157 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
//goods_id := esGoodsInfo.Map()["_id"].Int()
//goods_id := esGoodsInfo.Map()["_id"].Int()
goods_id_str
:=
esGoodsInfo
.
Map
()[
"_id"
]
.
String
()
goods_id_str
:=
esGoodsInfo
.
Map
()[
"_id"
]
.
String
()
//整理自营数据参数
//整理自营数据参数
_
,
ok
:=
dullZiYingGoodsInfo
(
goods_id_str
,
keyword
,
goods_name_arr
,
goodsList
)
goodsInfo
,
ok
:=
dullZiYingGoodsInfo
(
goods_id_str
,
keyword
,
goods_name_arr
,
goodsList
)
if
ok
{
if
!
ok
{
continue
}
//获取可领取样片数量
quota
,
err
:=
redis
.
String
(
redisConn
.
Do
(
"Hget"
,
"Self_sample_list"
,
goods_id_str
))
if
err
==
nil
&&
quota
!=
""
{
quotaValInt
:=
gjson
.
Get
(
quota
,
"quota"
)
.
Int
()
if
quotaValInt
>
0
{
goodsInfo
.
Quota
=
int
(
quotaValInt
)
}
else
{
goodsInfo
.
Quota
=
1
}
}
//存在样品数据
if
_
,
ok
:=
source
[
"sample_max_number"
];
ok
{
goodsInfo
.
SampleStatus
=
source
[
"sample_status"
]
.
String
()
goodsInfo
.
SampleMaxNumber
=
source
[
"sample_max_number"
]
.
String
()
goodsInfo
.
SampleClassId
=
source
[
"sample_class_id"
]
.
String
()
sampleInfo
,
err
:=
redis
.
String
(
redisConn
.
Do
(
"Hget"
,
"Self_sample_class_list"
,
source
[
"sample_class_id"
]
.
String
()))
if
err
==
nil
{
goodsInfo
.
SampleClassIdName
=
gjson
.
Get
(
sampleInfo
,
"class_name"
)
.
String
()
}
}
responseDataList
=
append
(
responseDataList
,
goodsInfo
)
}
if
len
(
responseDataList
)
>
0
{
response
[
"data"
]
=
map
[
string
]
interface
{}{
"data_list"
:
responseDataList
,
}
}
}
}
}
}
referer
:=
middleware
.
Context
.
GetHeader
(
"Referer"
)
if
flag
<=
0
&&
referer
!=
""
&&
php2go
.
Stripos
(
referer
,
"/s/?k="
,
0
)
==
-
1
{
pagesize
:=
length
totalPage
:=
math
.
Ceil
(
float64
(
hitsTotal
)
/
float64
(
pagesize
))
var
total
int64
if
totalPage
>
1
{
if
hitsTotal
>
10000
{
total
=
10000
}
else
{
total
=
hitsTotal
}
_zy_orgin_search
:=
zy_orgin_search
p
:=
_zy_orgin_search
[
"p"
]
if
p
==
""
{
p
=
"1"
}
offset
:=
_zy_orgin_search
[
"offset"
]
offsetInt
,
err
:=
strconv
.
Atoi
(
offset
)
if
err
==
nil
&&
offsetInt
>
0
{
offset
=
strconv
.
FormatInt
(
int64
(
offsetInt
),
10
)
}
else
{
offset
=
"10"
}
if
isAdmin
{
//如果是自营同步输出
//自定義分頁
delete
(
_zy_orgin_search
,
"callback"
)
delete
(
_zy_orgin_search
,
"PHPSESSID"
)
delete
(
_zy_orgin_search
,
"hcy_test"
)
delete
(
_zy_orgin_search
,
"Array"
)
page
:=
make
(
map
[
string
]
interface
{},
0
)
page
[
"orgin_search"
]
=
_zy_orgin_search
page
[
"total"
]
=
strconv
.
FormatInt
(
total
,
10
)
page
[
"current_page"
]
=
p
page
[
"offset"
]
=
offset
if
totalPage
>
1000
{
page
[
"total_page"
]
=
"1000"
}
else
{
page
[
"total_page"
]
=
strconv
.
FormatInt
(
int64
(
totalPage
),
10
)
}
pageData
:=
make
(
map
[
int
]
int
,
0
)
pInt
:=
int
(
1
)
pInt
,
err
=
strconv
.
Atoi
(
p
)
if
err
!=
nil
{
pInt
=
int
(
1
)
}
if
pInt
>
1000
{
pInt
=
1000
}
if
pInt
>
996
{
for
i
:=
pInt
-
10
;
i
<=
pInt
;
i
++
{
//原始查询参数拼接
pageData
[
i
]
=
i
}
}
else
{
pageNum
:=
0
for
i
:=
1
;
i
<=
int
(
totalPage
);
i
++
{
if
pageNum
==
10
{
break
}
if
pInt
>
6
&&
pInt
<=
996
{
//大于10页只获取中间10页
if
i
<
pInt
-
5
||
i
>
pInt
+
5
{
continue
}
}
fmt
.
Println
(
"i:"
,
i
)
pageData
[
i
]
=
i
pageNum
++
}
}
page
[
"page_data"
]
=
pageData
response
[
"page"
]
=
page
}
else
{
//非同步输出自己输出分页样式
page
,
err
:=
strconv
.
Atoi
(
p
)
if
err
!=
nil
{
page
=
int
(
1
)
}
pageSize
:=
10
if
page
<
1
{
page
=
1
}
if
pageSize
<
1
{
pageSize
=
10
}
paging
:=
common
.
Paginator
(
page
,
pageSize
,
365
)
pageHtml
:=
makePageInfo
(
paging
,
page
)
response
[
"page"
]
=
pageHtml
}
}
else
{
response
[
"page"
]
=
map
[
string
]
interface
{}{
"total"
:
totalPage
}
}
}
rsp
.
Data
=
response
rsp
.
Data
=
response
return
rsp
return
rsp
}
}
func
makePageInfo
(
paginator
map
[
string
]
interface
{},
currentPage
int
)
string
{
pageHtml
:=
""
pageHtml
+=
`<div class="pagination">`
pageHtml
+=
fmt
.
Sprintf
(
`<a class="prev" href="/product-%d.html">«</a> `
,
paginator
[
"firstpage"
])
pages
:=
paginator
[
"pages"
]
.
([]
int
)
for
_
,
page
:=
range
pages
{
if
currentPage
==
page
{
pageHtml
+=
fmt
.
Sprintf
(
`<span>%d</span>`
,
page
)
}
else
{
pageHtml
+=
fmt
.
Sprintf
(
`<a class="am-active"><a href="/product-%d.html">%d</a>`
,
page
,
page
)
}
}
pageHtml
+=
fmt
.
Sprintf
(
`<a class="prev" href="/product-%d.html">»</a> `
,
paginator
[
"lastpage"
])
pageHtml
+=
`</div>`
return
pageHtml
}
func
makeQuery
(
query
*
elastic
.
BoolQuery
,
source
*
elastic
.
SearchSource
,
conditions
[]
string
,
goods_temp_status
*
int
,
searchValue
*
string
,
func
makeQuery
(
query
*
elastic
.
BoolQuery
,
source
*
elastic
.
SearchSource
,
conditions
[]
string
,
goods_temp_status
*
int
,
searchValue
*
string
,
keyword
*
string
,
is_sample
*
bool
)
bool
{
keyword
*
string
,
is_sample
*
bool
)
bool
{
...
@@ -527,7 +682,7 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
...
@@ -527,7 +682,7 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
}
}
}
}
goods_name_arr
:=
append
(
term_v
,
goods_name_cn
...
)
goods_name_arr
:=
append
(
term_v
,
goods_name_cn
...
)
fmt
.
Println
(
"goods_name_arr"
,
goods_name_arr
)
//
fmt.Println("goods_name_arr",goods_name_arr)
*
keyword
=
*
searchValue
*
keyword
=
*
searchValue
for
_
,
v
:=
range
term_v
{
for
_
,
v
:=
range
term_v
{
if
v
!=
""
{
if
v
!=
""
{
...
@@ -626,11 +781,11 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
...
@@ -626,11 +781,11 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
if
attrs_matchs
,
ok
:=
gjson
.
Parse
(
*
searchValue
)
.
Value
()
.
(
map
[
string
]
interface
{});
ok
{
if
attrs_matchs
,
ok
:=
gjson
.
Parse
(
*
searchValue
)
.
Value
()
.
(
map
[
string
]
interface
{});
ok
{
fmt
.
Println
(
attrs_matchs
)
//
fmt.Println(attrs_matchs)
for
attr_name
,
attr_value
:=
range
attrs_matchs
{
for
attr_name
,
attr_value
:=
range
attrs_matchs
{
filterNestedAttrsBoolQuery
:=
elastic
.
NewBoolQuery
()
filterNestedAttrsBoolQuery
:=
elastic
.
NewBoolQuery
()
fmt
.
Println
(
attr_name
)
//
fmt.Println(attr_name)
fmt
.
Println
(
attr_value
)
//
fmt.Println(attr_value)
filterNestedAttrsBoolQuery
.
Must
(
elastic
.
NewTermQuery
(
"attrs.attr_name"
,
attr_name
),
elastic
.
NewTermQuery
(
"attrs.attr_value"
,
attr_value
))
filterNestedAttrsBoolQuery
.
Must
(
elastic
.
NewTermQuery
(
"attrs.attr_name"
,
attr_name
),
elastic
.
NewTermQuery
(
"attrs.attr_value"
,
attr_value
))
query
.
Must
(
elastic
.
NewNestedQuery
(
"attrs"
,
filterNestedAttrsBoolQuery
))
query
.
Must
(
elastic
.
NewNestedQuery
(
"attrs"
,
filterNestedAttrsBoolQuery
))
}
}
...
@@ -737,7 +892,7 @@ func dullZiYingGoodsInfo(goods_id_str string,keyword string,goods_name_arr []str
...
@@ -737,7 +892,7 @@ func dullZiYingGoodsInfo(goods_id_str string,keyword string,goods_name_arr []str
ziyinGoodsInfo
.
SkuName
=
reg
.
ReplaceAllString
(
ziyinGoodsInfo
.
GoodsName
,
"<b class='f-red'>"
+
strings
.
ToUpper
(
keyword
)
+
"</b>"
)
ziyinGoodsInfo
.
SkuName
=
reg
.
ReplaceAllString
(
ziyinGoodsInfo
.
GoodsName
,
"<b class='f-red'>"
+
strings
.
ToUpper
(
keyword
)
+
"</b>"
)
}
}
}
else
{
}
else
{
if
ziyinGoodsInfo
.
SkuName
!
=
""
{
if
ziyinGoodsInfo
.
SkuName
=
=
""
{
ziyinGoodsInfo
.
SkuName
=
ziyinGoodsInfo
.
GoodsName
ziyinGoodsInfo
.
SkuName
=
ziyinGoodsInfo
.
GoodsName
}
else
{
}
else
{
ziyinGoodsInfo
.
SkuName
=
ziyinGoodsInfo
.
SkuName
ziyinGoodsInfo
.
SkuName
=
ziyinGoodsInfo
.
SkuName
...
@@ -759,7 +914,7 @@ func dullZiYingGoodsInfo(goods_id_str string,keyword string,goods_name_arr []str
...
@@ -759,7 +914,7 @@ func dullZiYingGoodsInfo(goods_id_str string,keyword string,goods_name_arr []str
}
}
ziyinGoodsInfo
.
LastSearchTime
=
common
.
GetLastSearchTime
(
goods_id_str
)
ziyinGoodsInfo
.
LastSearchTime
=
common
.
GetLastSearchTime
(
goods_id_str
)
go
transformer
.
ShowSku
(
model
.
DullGoodsData
{
ApiGoods
:
ziyinGoodsInfo
.
ApiGoods
})
//
go transformer.ShowSku(model.DullGoodsData{ApiGoods:ziyinGoodsInfo.ApiGoods})
if
keyword
!=
"---"
{
if
keyword
!=
"---"
{
dullGoodsData
,
err
:=
transformer
.
MetGoodsInfo
(
ziyinGoodsInfo
.
DullGoodsData
)
dullGoodsData
,
err
:=
transformer
.
MetGoodsInfo
(
ziyinGoodsInfo
.
DullGoodsData
)
if
err
==
nil
{
if
err
==
nil
{
...
...
test/test7.go
0 → 100644
View file @
38bd01b0
package
main
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment