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
5f5216e7
authored
Jul 22, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'dev' of
http://119.23.72.7/mushishixian/search_server
into dev
parents
e5c069bf
ababccc9
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
197 additions
and
11 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 @
5f5216e7
[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 @
5f5216e7
...
...
@@ -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 @
5f5216e7
...
...
@@ -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 @
5f5216e7
...
...
@@ -267,8 +267,8 @@ func auth() bool {
return
false
}
// interface{}转为 []interface{}
//將任意類型的切片轉為 []interface{}
func
CreateAnyTypeSlice
(
slice
interface
{})
([]
interface
{},
bool
)
{
val
,
ok
:=
isSlice
(
slice
)
...
...
@@ -312,3 +312,14 @@ func StrPadLeft(input string, padLength int, padString string) string {
return
output
[
:
padLength
-
len
(
input
)]
+
input
}
//移除字符串切片中某個元素
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 @
5f5216e7
...
...
@@ -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 @
5f5216e7
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