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
aabd44c2
authored
Jul 22, 2020
by
孙龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
up
parent
45f76ff4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
195 additions
and
9 deletions
conf/rabmq_key.ini
controller/ziyin_controller.go
model/goods.go
pkg/common/function.go
service/ziyin_service.go
test/test6.go
conf/rabmq_key.ini
View file @
aabd44c2
[rabmq]
url
=
amqp:
;
guest:guest@192.168.2.232:5672/
url
=
amqp:
//
guest:guest@192.168.2.232:5672/
;存放本系统所有的队列名称
[rabmq_all]
; bom任务id
...
...
controller/ziyin_controller.go
View file @
aabd44c2
...
...
@@ -31,7 +31,6 @@ func Zyh(ctx *gin.Context){
ctx
.
JSON
(
200
,
zyhResponse
)
}
fmt
.
Println
(
"6666666666666"
)
fmt
.
Printf
(
"%+v"
,
zyhResponse
)
//fmt.Printf("%+v",zyhResponse)
ctx
.
JSON
(
200
,
zyhResponse
)
}
model/goods.go
View file @
aabd44c2
...
...
@@ -70,6 +70,11 @@ type ApiGoods struct {
ActivityEndTime
int64
`json:"activity_end_time,omitempty"`
}
type
ZiyinGoodsInfo
struct
{
GoodsNameOrg
string
`json:"goods_name_org"`
DullGoodsData
}
//经过处理后的商品数据
type
DullGoodsData
struct
{
ApiGoods
...
...
pkg/common/function.go
View file @
aabd44c2
...
...
@@ -301,3 +301,14 @@ func isSlice(arg interface{}) (val reflect.Value, ok bool) {
return
}
//移除字符串切片中某個元素
func
RemoveSliceString
(
s
[]
string
,
i
string
)
[]
string
{
b
:=
make
([]
string
,
0
)
for
_
,
v
:=
range
s
{
if
v
!=
i
{
b
=
append
(
b
,
v
)
}
}
return
b
}
service/ziyin_service.go
View file @
aabd44c2
...
...
@@ -11,11 +11,13 @@ import (
"github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5"
"regexp"
"search_server/middleware"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/config"
"search_server/pkg/es"
"search_server/pkg/gredis"
"search_server/service/transformer"
"strconv"
"strings"
)
...
...
@@ -140,7 +142,7 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){
*/
func
searchZiYingGoods
(
req
map
[
string
]
string
,
zy
bool
,
classList
*
model
.
ZhyClassList
,
classLight
[]
*
model
.
ZhyClassListModel
,
aType
byte
)
(
rsp
*
model
.
ZyhResponse
){
var
(
goods_name_arr
[]
map
[
string
]
string
goods_name_arr
[]
string
keyword
string
is_sample
bool
redisConn
redis
.
Conn
...
...
@@ -157,12 +159,12 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
response
=
make
(
map
[
string
]
interface
{},
0
)
keyword
=
""
goods_name_arr
=
make
([]
map
[
string
]
string
,
0
)
goods_name_arr
=
make
([]
string
,
0
)
if
req
[
"goods_name/condition"
]
!=
""
{
goodsNameCondition
:=
strings
.
ToUpper
(
req
[
"goods_name/condition"
])
ziyingBrandReplace
:=
config
.
Cfg
.
Section
(
"ZIYING_BRAND_REPLACE"
)
.
KeysHash
()
if
ziyingBrandReplace
!=
nil
&&
ziyingBrandReplace
[
goodsNameCondition
]
!=
""
{
goods_name_arr
=
append
(
goods_name_arr
,
map
[
string
]
string
{
"brand_name/condition"
:
ziyingBrandReplace
[
goodsNameCondition
]}
)
goods_name_arr
=
append
(
goods_name_arr
,
req
[
"brand_name/condition"
]
)
delete
(
req
,
"goods_name/condition"
)
}
}
...
...
@@ -398,6 +400,34 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
return
rsp
}
hits2_source
:=
gjson
.
Get
(
result
,
"hits.hits.#._source"
)
.
Array
()
hitsTotal
:=
gjson
.
Get
(
result
,
"hits.total"
)
.
Int
()
hitsHits
:=
gjson
.
Get
(
result
,
"hits.hits"
)
.
Array
()
if
hitsTotal
>
0
&&
len
(
hits2_source
)
>
0
{
goodsIds
:=
gjson
.
Get
(
result
,
"hits.hits.#._id"
)
.
Array
()
fmt
.
Println
(
"goodsIds"
,
goodsIds
)
goodsIdsStrArr
:=
make
([]
string
,
0
)
for
_
,
v
:=
range
goodsIds
{
goodsIdsStrArr
=
append
(
goodsIdsStrArr
,
v
.
String
())
}
goodsList
,
_
:=
GetGoodsInfo
(
goodsIdsStrArr
)
flag
=
0
response
[
"total"
]
=
gjson
.
Get
(
result
,
"hits.total"
)
.
String
()
for
_
,
esGoodsInfo
:=
range
hitsHits
{
source
:=
esGoodsInfo
.
Map
()[
"_source"
]
.
Map
()
source
=
source
//goods_id := esGoodsInfo.Map()["_id"].Int()
goods_id_str
:=
esGoodsInfo
.
Map
()[
"_id"
]
.
String
()
//整理自营数据参数
_
,
ok
:=
dullZiYingGoodsInfo
(
goods_id_str
,
keyword
,
goods_name_arr
,
goodsList
)
if
ok
{
}
}
}
rsp
.
Data
=
response
return
rsp
}
...
...
@@ -456,7 +486,7 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
}
}
fmt
.
Println
(
*
searchValue
)
//
fmt.Println(*searchValue)
keywordUper
:=
strings
.
ToUpper
(
*
searchValue
)
mathExactGoodsName
:=
config
.
Cfg
.
Section
(
"mathExactGoodsName"
)
.
KeysHash
()
...
...
@@ -507,6 +537,7 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
if
len
(
goods_name_arr
)
>
0
{
query
.
Must
(
elastic
.
NewMatchQuery
(
"goods_name_cn"
,
strings
.
Join
(
goods_name_cn
,
" "
))
.
MinimumShouldMatch
(
"100%"
))
}
case
"brand_name"
:
term_v
=
strings
.
Split
(
*
searchValue
,
","
)
*
searchValue
=
strings
.
ToUpper
(
strings
.
TrimSpace
(
*
searchValue
))
...
...
@@ -639,4 +670,102 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
}
return
true
}
\ No newline at end of file
}
//整理自营数据参数
func
dullZiYingGoodsInfo
(
goods_id_str
string
,
keyword
string
,
goods_name_arr
[]
string
,
goods_list
[]
model
.
ApiGoods
)
(
ziyinGoodsInfo
model
.
ZiyinGoodsInfo
,
ok
bool
){
isHas
:=
false
for
_
,
goods_info
:=
range
goods_list
{
if
goods_info
.
GoodsId
==
goods_id_str
{
isHas
=
true
ziyinGoodsInfo
.
ApiGoods
=
goods_info
ziyinGoodsInfo
.
GoodsNameOrg
=
goods_info
.
GoodsName
break
}
}
if
!
isHas
{
return
ziyinGoodsInfo
,
false
}
//高亮
if
len
(
goods_name_arr
)
>
0
{
goods_name_arr_tmp
:=
goods_name_arr
for
_
,
v
:=
range
goods_name_arr
{
if
strings
.
TrimSpace
(
v
)
==
""
{
goods_name_arr_tmp
=
common
.
RemoveSliceString
(
goods_name_arr_tmp
,
v
)
}
}
goods_name_arr
=
goods_name_arr_tmp
str_temp
:=
strings
.
Join
(
goods_name_arr
,
"|"
)
str_temp
=
strings
.
ToUpper
(
strings
.
ReplaceAll
(
str_temp
,
"Μ"
,
"μ"
))
str_temp
=
regexp
.
QuoteMeta
(
str_temp
)
str_temp
=
strings
.
ToUpper
(
strings
.
ReplaceAll
(
str_temp
,
"/"
,
"
\\
/"
))
reg
:=
regexp
.
MustCompile
(
`(`
+
str_temp
+
`)`
)
for
k
,
v
:=
range
[]
string
{
ziyinGoodsInfo
.
SkuName
,
ziyinGoodsInfo
.
BrandName
,
ziyinGoodsInfo
.
GoodsName
,
ziyinGoodsInfo
.
GoodsBrief
}{
re_temp
:=
reg
.
ReplaceAllString
(
v
,
"<b class='f-red'>${1}</b>"
)
if
re_temp
!=
""
{
switch
k
{
case
0
:
ziyinGoodsInfo
.
SkuName
=
re_temp
case
1
:
ziyinGoodsInfo
.
BrandName
=
re_temp
case
2
:
ziyinGoodsInfo
.
GoodsName
=
re_temp
case
3
:
ziyinGoodsInfo
.
GoodsBrief
=
re_temp
}
}
}
}
if
keyword
!=
""
{
if
ziyinGoodsInfo
.
SkuName
!=
""
{
//如果是属性搜索
if
(
php2go
.
Strpos
(
keyword
,
","
,
0
))
>=
0
{
keywordSlice
:=
strings
.
Split
(
keyword
,
","
)
for
_
,
v
:=
range
keywordSlice
{
reg
:=
regexp
.
MustCompile
(
"(?i)"
+
v
)
ziyinGoodsInfo
.
SkuName
=
reg
.
ReplaceAllString
(
ziyinGoodsInfo
.
SkuName
,
"<b class='f-red'>"
+
strings
.
ToUpper
(
v
)
+
"</b>"
)
}
}
}
else
{
reg
:=
regexp
.
MustCompile
(
"(?i)"
+
keyword
)
ziyinGoodsInfo
.
SkuName
=
reg
.
ReplaceAllString
(
ziyinGoodsInfo
.
GoodsName
,
"<b class='f-red'>"
+
strings
.
ToUpper
(
keyword
)
+
"</b>"
)
}
}
else
{
if
ziyinGoodsInfo
.
SkuName
!=
""
{
ziyinGoodsInfo
.
SkuName
=
ziyinGoodsInfo
.
GoodsName
}
else
{
ziyinGoodsInfo
.
SkuName
=
ziyinGoodsInfo
.
SkuName
}
}
referer
:=
middleware
.
Context
.
GetHeader
(
"Referer"
)
if
referer
!=
""
{
dome
:=
strings
.
Split
(
referer
,
".com"
)
if
len
(
dome
)
>
0
{
ziyinGoodsInfo
.
GoodsUrl
=
dome
[
0
]
+
".com/item/"
+
ziyinGoodsInfo
.
GoodsId
+
".html"
ziyinGoodsInfo
.
BrandUrl
=
dome
[
0
]
+
".com/v3/brand/list/"
+
strconv
.
Itoa
(
ziyinGoodsInfo
.
BrandId
)
+
".html"
}
}
///立创商品增加编码L
if
ziyinGoodsInfo
.
Encoded
!=
""
&&
ziyinGoodsInfo
.
SelfSupplierType
==
2
{
ziyinGoodsInfo
.
Encoded
=
ziyinGoodsInfo
.
Encoded
+
"-L"
}
ziyinGoodsInfo
.
LastSearchTime
=
common
.
GetLastSearchTime
(
goods_id_str
)
go
transformer
.
ShowSku
(
model
.
DullGoodsData
{
ApiGoods
:
ziyinGoodsInfo
.
ApiGoods
})
if
keyword
!=
"---"
{
dullGoodsData
,
err
:=
transformer
.
MetGoodsInfo
(
ziyinGoodsInfo
.
DullGoodsData
)
if
err
==
nil
{
ziyinGoodsInfo
.
DullGoodsData
=
dullGoodsData
}
}
return
ziyinGoodsInfo
,
true
}
test/test6.go
0 → 100644
View file @
aabd44c2
package
main
import
(
"fmt"
"reflect"
"regexp"
"strings"
)
func
remove2
(
s
interface
{},
deleteVal
int
)
[]
interface
{}
{
val
:=
reflect
.
ValueOf
(
s
)
sliceLen
:=
val
.
Len
()
out
:=
make
([]
interface
{},
sliceLen
)
if
val
.
Kind
()
==
reflect
.
Slice
{
sliceLen
:=
val
.
Len
()
for
i
:=
0
;
i
<
sliceLen
;
i
++
{
if
val
.
Index
(
i
)
.
Int
()
!=
int64
(
deleteVal
){
out
[
i
]
=
val
.
Index
(
i
)
.
Interface
()
}
}
}
return
out
}
func
main
(){
a
:=
[]
int
{
1
,
2
,
3
,
4
,
5
}
fmt
.
Println
(
remove2
(
a
,
3
))
test
:=
"a,b,c,d,e"
aaa
:=
test
keywordSlice
:=
strings
.
Split
(
test
,
","
)
for
_
,
v
:=
range
keywordSlice
{
reg
:=
regexp
.
MustCompile
(
"(?i)"
+
v
)
aaa
=
reg
.
ReplaceAllString
(
aaa
,
"<b class='f-red'>"
+
strings
.
ToUpper
(
v
)
+
"</b>"
)
fmt
.
Println
(
aaa
)
}
}
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