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
849bd436
authored
Nov 11, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
a1078193
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
0 deletions
controller/api_controller.go
routes/router.go
service/alike_service.go
controller/api_controller.go
View file @
849bd436
...
...
@@ -20,3 +20,18 @@ func AlikeSearch(ctx *gin.Context) {
common
.
Output
(
ctx
,
apiData
.
ErrorCode
,
apiData
.
ErrorMsg
,
apiData
.
Data
)
common
.
PrintDebugHtml
(
ctx
,
"-----执行结束----"
)
//debug
}
/*
联想词搜索
@param source 来源:1国产 2普通
@param goods_name_en 国外类似型号名称
*/
func
ThinkSearch
(
ctx
*
gin
.
Context
)
{
common
.
PrintDebugHeader
(
ctx
)
//debug
service
:=
service
.
AlikeService
{}
apiData
:=
service
.
ThinkGoods
(
ctx
)
common
.
Output
(
ctx
,
apiData
.
ErrorCode
,
apiData
.
ErrorMsg
,
apiData
.
Data
)
common
.
PrintDebugHtml
(
ctx
,
"-----执行结束----"
)
//debug
}
routes/router.go
View file @
849bd436
...
...
@@ -24,6 +24,8 @@ func InitRouter() *gin.Engine {
{
v2
.
POST
(
"alike"
,
controller
.
AlikeSearch
)
v2
.
GET
(
"alike"
,
controller
.
AlikeSearch
)
v2
.
GET
(
"think"
,
controller
.
ThinkSearch
)
v2
.
POST
(
"think"
,
controller
.
ThinkSearch
)
}
//商品分类
v3
:=
r
.
Group
(
"/optimum/"
)
...
...
service/alike_service.go
View file @
849bd436
...
...
@@ -4,6 +4,8 @@ import (
"github.com/gin-gonic/gin"
"github.com/iancoleman/orderedmap"
"github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5"
"regexp"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/es"
...
...
@@ -89,3 +91,47 @@ func (qs *AlikeService) AlikeSearchInfo(ctx *gin.Context) (results model.LyRespo
results
.
Data
=
A
;
return
}
/*
联想词
*/
func
(
qs
*
AlikeService
)
ThinkGoods
(
ctx
*
gin
.
Context
)
(
results
model
.
LyResponse
)
{
goodsName
:=
ctx
.
Request
.
FormValue
(
"k"
);
if
goodsName
==
""
{
results
.
ErrorCode
=
0
;
results
.
ErrorMsg
=
""
return
}
//字符过滤
replace
,
_
:=
regexp
.
Compile
(
"[^A-Za-z0-9]+"
)
goodsName
=
replace
.
ReplaceAllString
(
goodsName
,
""
)
goodsName
=
strings
.
ToUpper
(
goodsName
)
//查询es
query
:=
elastic
.
NewBoolQuery
()
query
.
Filter
(
elastic
.
NewTermQuery
(
"auto_goods_name"
,
goodsName
))
source
:=
elastic
.
NewSearchSource
()
.
Query
(
query
)
source
=
source
.
From
(
0
)
.
Size
(
10
)
searchRequestStr
,
_
:=
elastic
.
NewSearchRequest
()
.
Source
(
source
)
.
Body
()
common
.
PrintDebugHtml
(
ctx
,
searchRequestStr
)
result
,
err
:=
es
.
CurlES
(
"digikey"
,
searchRequestStr
)
if
err
!=
nil
{
results
.
ErrorCode
=
0
;
results
.
ErrorMsg
=
err
.
Error
()
return
}
goodsNameList
:=
make
([]
string
,
0
)
goodsList
:=
gjson
.
Get
(
result
,
"hits.hits.#._source"
)
.
Array
()
for
_
,
goods
:=
range
goodsList
{
goodsName
:=
gjson
.
Get
(
goods
.
String
(),
"auto_goods_name"
)
.
String
()
goodsNameList
=
append
(
goodsNameList
,
goodsName
)
}
results
.
ErrorCode
=
0
;
results
.
ErrorMsg
=
"查询成功"
results
.
Data
=
goodsNameList
return
}
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