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
3d04f1db
authored
Nov 17, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
849bd436
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
5 deletions
go.mod
service/alike_service.go
service/query/alike_query.go
go.mod
View file @
3d04f1db
...
...
@@ -11,6 +11,7 @@ require (
github.com/go-playground/validator/v10 v10.4.0 // indirect
github.com/go-sql-driver/mysql v1.5.0
github.com/go-xorm/xorm v0.7.9
github.com/gogf/gf v1.14.2
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/protobuf v1.4.3
github.com/gomodule/redigo v2.0.1-0.20180401191855-9352ab68be13+incompatible
...
...
service/alike_service.go
View file @
3d04f1db
...
...
@@ -8,6 +8,7 @@ import (
"regexp"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/config"
"search_server/pkg/es"
"search_server/service/query"
"strconv"
...
...
@@ -20,14 +21,21 @@ type AlikeService struct {}
返回供应商详情
*/
func
(
qs
*
AlikeService
)
AlikeSearchInfo
(
ctx
*
gin
.
Context
)
(
results
model
.
LyResponse
)
{
target
:=
ctx
.
Request
.
FormValue
(
"target"
)
//搜索目标: 1 国产 2 所有sku
index
:=
"zhuanmai"
//搜索国产替代 索引
if
target
==
"2"
{
//搜索所有
index
=
config
.
Get
(
"es.index_name"
)
.
String
()
}
//索引字典
queryString
,
err
:=
query
.
GetDemeQuery
(
ctx
)
queryString
,
err
:=
query
.
GetDemeQuery
(
ctx
,
target
)
if
err
!=
nil
{
results
.
ErrorCode
=
1001
;
results
.
ErrorMsg
=
err
.
Error
()
return
}
esResult
,
err
:=
es
.
CurlES
(
"zhuanmai"
,
queryString
)
esResult
,
err
:=
es
.
CurlES
(
index
,
queryString
)
if
err
!=
nil
{
results
.
ErrorCode
=
0
;
results
.
ErrorMsg
=
err
.
Error
()
...
...
service/query/alike_query.go
View file @
3d04f1db
...
...
@@ -10,16 +10,21 @@ import (
/*
获取国产查询es语句
@param string target 搜索目标: 1 国产 2 所有sku
*/
func
GetDemeQuery
(
ctx
*
gin
.
Context
)
(
param
string
,
err
error
){
func
GetDemeQuery
(
ctx
*
gin
.
Context
,
target
string
)
(
param
string
,
err
error
){
query
:=
elastic
.
NewBoolQuery
()
goods_name
:=
ctx
.
Request
.
FormValue
(
"alike_goods_en/eq"
)
//国外型号
if
target
==
"1"
{
query
.
Must
(
elastic
.
NewTermQuery
(
"supplier_type"
,
1
))
}
goods_name
:=
ctx
.
Request
.
FormValue
(
"alike_spu_name/eq"
)
//国外型号
if
goods_name
!=
""
{
//型号搜索
replace
,
_
:=
regexp
.
Compile
(
"[^A-Za-z0-9]+"
)
goods_name
=
replace
.
ReplaceAllString
(
goods_name
,
""
)
goods_name
=
strings
.
ToUpper
(
goods_name
)
query
.
Must
(
elastic
.
NewTermQuery
(
"alike_
goods_en
.raw"
,
goods_name
))
query
.
Must
(
elastic
.
NewTermQuery
(
"alike_
spu_name
.raw"
,
goods_name
))
}
alike_spu_id
:=
ctx
.
Request
.
FormValue
(
"alike_spu_id/eq"
)
//国外型号spu_id
if
alike_spu_id
!=
""
{
...
...
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