Commit a362780b by huangchengyi

Merge branch 'dev' of http://119.23.72.7/mushishixian/search_server into dev

parents 99bc6df0 38af2c53
[DINGDING]
SEARCH_API_MONITOR = 6d0fa85e01a02c39347d011ae973fd21b76c6c7ce582d3ea470c6b65a318848d
\ No newline at end of file
[rabmq]
url = amqp://guest:guest@192.168.2.232:5672/
;存放本系统所有的队列名称
[rabmq_all]
;联营数据推送入队列-》go后台任务消费(斌哥脚本)
......
......@@ -42,7 +42,7 @@
MOUSER_API = 'http://footstone.liexin.net/webapi/handle_mouser'
[brand]
[BRAND]
IS_NOT_TI = 0
TI_LY_BRAND_IDS = 23,45069,7754,17484,43215,13421,5220,7636,44534,43556,44543,9429,758,9470,10430,10653,10707,11227,11276,11819,12608,12965,12997,13327,13675,13680,13752
TI_ZY_BRAND_IDS = 23
......@@ -120,7 +120,7 @@ Index = liexin_ziying
8=kw
[official_website]
[OFFICIAL_WEBSITE]
1 = https://www.futureelectronics.cn/search/?text=liexin
2 = http://www.powerandsignal.com/Products/Search?searchBox=liexin
3 = https://www.rocelec.com/search?q=liexin
......
......@@ -36,11 +36,12 @@ func GetDataIndex(c *gin.Context) {
if r.SupplierId != "" && r.IsSort == 2 {
//所有供应商列表
//如果供应商不在合并供应商列表,则实时更新数据
if supplierName != "" && !php2go.InArray(r.SupplierName, supplierList) {
if supplierName != "" && !php2go.InArray(supplierName, supplierList) {
redisCon := gredis.Conn("search_w")
defer redisCon.Close()
//获取stockFlag
res, err := redis.Bool(redisCon.Do("SADD", "search_keyword_member", r.Keyword+"_"+r.SupplierName))
fmt.Println(r.Keyword+"_"+r.SupplierName)
if err != nil {
fmt.Println(err)
}
......
......@@ -3,12 +3,10 @@ module search_server
go 1.14
require (
github.com/basgys/goxml2json v1.1.0
github.com/coreos/etcd v3.3.18+incompatible
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd // indirect
github.com/gin-contrib/cors v1.3.1
github.com/gin-gonic/gin v1.6.3
github.com/go-ini/ini v1.57.0
github.com/go-playground/locales v0.13.0
github.com/go-sql-driver/mysql v1.5.0
github.com/go-xorm/xorm v0.7.9
github.com/gogo/protobuf v1.3.1 // indirect
......@@ -18,39 +16,28 @@ require (
github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.14.3 // indirect
github.com/ichunt2019/go-rabbitmq v1.0.1
github.com/ichunt2019/logger v1.0.5
github.com/idoubi/goz v1.0.0
github.com/imroc/req v0.3.0
github.com/jinzhu/gorm v1.9.12
github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 // indirect
github.com/mholt/certmagic v0.9.3 // indirect
github.com/mattn/go-sqlite3 v2.0.1+incompatible // indirect
github.com/micro/go-micro v1.16.0
github.com/micro/go-micro/v2 v2.9.0
github.com/micro/micro/v2 v2.9.1 // indirect
github.com/micro/protoc-gen-micro v1.0.0 // indirect
github.com/prometheus/client_golang v1.5.1 // indirect
github.com/prometheus/common v0.10.0
github.com/prometheus/procfs v0.0.11 // indirect
github.com/silenceper/gowatch v0.0.0-20200624073703-8e473a9db258 // indirect
github.com/sirupsen/logrus v1.5.0 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/stretchr/testify v1.5.1 // indirect
github.com/syyongx/php2go v0.9.4
github.com/tidwall/gjson v1.6.0
github.com/uniplaces/carbon v0.1.6
github.com/urfave/cli v1.22.4 // indirect
go.etcd.io/bbolt v1.3.4
go.uber.org/zap v1.14.1 // indirect
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2 // indirect
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361
google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece // indirect
google.golang.org/grpc v1.29.1 // indirect
google.golang.org/protobuf v1.24.0
gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/olivere/elastic.v5 v5.0.85
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)
......
......@@ -7,20 +7,20 @@ import (
//获取需要排除的品牌id
//branType = 1 : 联营 2 : 自营
func GetExcludeBrandIds(brandType int) (excludeBrandIds []int) {
isNoTi := config.Get("brand.IS_NOT_TI").String()
isNoTi := config.Get("BRAND.IS_NOT_TI").String()
//如果关闭,直接返回空数据
if isNoTi == "0" {
return
}
//返回联营的brand_id切片
if brandType == 1 {
tiLyBrandIds := config.Get("brand.TI_LY_BRAND_IDS").Ints(",")
tiLyBrandIds := config.Get("BRAND.TI_LY_BRAND_IDS").Ints(",")
excludeBrandIds = tiLyBrandIds
//获取的是字符串
return
}
//返回自营的ti的brand_id切片
tiZyBrandId := config.Get("brand.TI_ZY_BRAND_IDS").Ints(",")
tiZyBrandId := config.Get("BRAND.TI_ZY_BRAND_IDS").Ints(",")
excludeBrandIds = tiZyBrandId
return
......
package model
......@@ -12,7 +12,7 @@ var (
func SetUp(path string) (err error) {
//引入多个文件
Cfg, err = ini.LooseLoad(path+"/config.ini", path+"/search.ini", path+"/redis_key.ini", path+"/rabmq_key.ini", path+"/database.ini",
path+"/redis_config.ini")
path+"/redis_config.ini", path+"/message.ini")
return
}
......
......@@ -73,7 +73,7 @@ func BulkES(param string) (result string, err error) {
func CurlESMSearch(queryJson string) (result string, err error) {
endpoints := config.Get("es.urls").Strings(",")
//随机获取一个节点进行请求
req.Debug = true
req.Debug = false
esUrl := endpoints[rand.Intn(len(endpoints))]
params := req.BodyJSON(queryJson)
resp, err := req.Post(esUrl+"/_msearch", params)
......
package message
import (
"encoding/json"
"fmt"
"github.com/imroc/req"
"github.com/prometheus/common/log"
"github.com/tidwall/gjson"
"search_server/pkg/config"
"strings"
)
//发送钉钉消息的包
......@@ -12,26 +16,33 @@ type DingDingRequest struct {
IsAtAll bool `json:"isAtAll"`
}
func SendDingdingMessage(content string) {
var (
requestData DingDingRequest
apiUrl, token string
//resp *req.Resp
err error
)
//todo: 需要配置一个搜索服务的专属警告
content = "仓储同步告警 : " + content
requestData.MsgType = "text"
requestData.Text = map[string]string{
type DingDingResponse struct {
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
}
func DingDingPush(content string) (result DingDingResponse, err error) {
accessToken := config.Get("DINGDING.SEARCH_API_MONITOR").String()
webhook := "https://oapi.dingtalk.com/robot/send?access_token=" + accessToken
data := make(map[string]interface{})
data["msgtype"] = "text"
data["text"] = map[string]string{
"content": content,
}
req.Debug = false
requestData.IsAtAll = false
token = "3c048caba514a5252aa8bdbb3e10994def6409a2f0d5212e5626c1a071152ec3"
apiUrl = "https://api.ichunt.com/public/dingtalkrobot?access_token=" + token
params := req.BodyJSON(requestData)
_, err = req.Post(apiUrl, params)
if err != nil {
log.Error(err)
dataStrByte, _ := json.Marshal(data)
dataStr := string(dataStrByte)
fmt.Println(dataStr)
dataStr = strings.Replace(dataStr, "\\", "\\\\", -1)
params := req.BodyJSON(dataStr)
resp, err := req.Post(webhook, params, req.Header{
"Content-Type": "application/json",
"charset": "UTF-8",
})
if resp == nil {
return
}
result.Errcode = int(gjson.Get(resp.String(), "errcode").Int())
result.Errmsg = gjson.Get(resp.String(), "errmsg").String()
return
}
package mq
import (
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"search_server/pkg/config"
)
func PushMsg(listName string, data string) {
queueExchange := rabbitmq.QueueExchange{
listName,
listName,
"",
"direct",
config.Get("rabmq.url").String(),
}
rabbitmq.Send(queueExchange, data)
}
......@@ -44,11 +44,13 @@ mgo包的文档 : https://godoc.org/gopkg.in/mgo.v2
#### 5.钉钉群消息以及短信
直接在pkg/message包调用对应的函数即可:
钉钉的为```message.SendDingdingMessage```
短信为```message.SendMessage```
钉钉的为```message.DingDingPush```
#### 6.商品信息获取
直接调用```service.GetGoodsInfo```函数即可,传入goods_id的字符串,多个goods_id用逗号隔开(商品服务的请求本来亦是如此),会返回json字符串,然后可以根据自己的需求用gjson获取对应的信息即可
#### 7.ES的基本请求
直接调用```es.CurlES```函数即可,传入索引名称和请求的json参数即可,得到的返回结果是ES的原生结果,可以根据自己的需求用gjson获取对应的信息
#### 7.队列推送
直接调用```mq.PushMsg("xian_test","test")```函数即可(调用方式保持和PHP一致),第一个参数队列名同时也是路由名,第二个是要传的值
package routes
import (
"fmt"
"github.com/gin-gonic/gin"
"search_server/controller"
"search_server/middleware"
......@@ -28,8 +29,11 @@ func InitRouter() *gin.Engine {
r.POST("/search/quote/getDataPur", controller.GetDataPur)
//GetData控制器相关
r.GET("/search/get_data/index", controller.GetDataIndex)
r.POST("/search/get_data/index", controller.GetDataIndex)
r.GET("/search/get_data", controller.GetDataIndex)
r.POST("/search/get_data", controller.GetDataIndex)
r.GET("/test", func(c *gin.Context) {
fmt.Println(c.Query("test"))
})
return r
}
package query
import (
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/uniplaces/carbon"
......@@ -33,6 +34,7 @@ func GetSupplierIndex(supplierId string) (supplierIndex string) {
return
}
//根据供应商名称查询商品的ES查询
func GetGoodsBySupplierNameQuery(r requests.GetGoodsBySupplierRequest) (string, error) {
query := elastic.NewBoolQuery()
subQuery := elastic.NewBoolQuery()
......@@ -44,7 +46,6 @@ func GetGoodsBySupplierNameQuery(r requests.GetGoodsBySupplierRequest) (string,
stockFlag, _ := redis.Int(redisCon.Do("GET", "StockSwitch"))
//todo : type=goods
keywordSlice := strings.Split(strings.ToUpper(strings.TrimSpace(r.Keyword)), " ")
r1, _ := regexp.Compile(`/[\x{4e00}-\x{9fff}]+/u`)
//去除中文?
removeCnKeyword := r1.ReplaceAllString(r.Keyword, "")
......@@ -168,7 +169,6 @@ func GetGoodsBySupplierNameQuery(r requests.GetGoodsBySupplierRequest) (string,
source.Query(query)
searchRequest := elastic.NewSearchRequest().Source(source).Preference("_primary_first")
return searchRequest.Body()
}
......@@ -332,6 +332,6 @@ func GetGoodsBySupplierIdQuery(r requests.GetGoodsBySupplierRequest) (string, er
}
source.Query(query)
searchRequest := elastic.NewSearchRequest().Source(source).Preference("_primary_first")
fmt.Println(searchRequest.Body())
return searchRequest.Body()
}
......@@ -2,7 +2,6 @@ package service
import (
"encoding/json"
"fmt"
"github.com/imroc/req"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
......@@ -44,8 +43,6 @@ func (qs *QuoteService) GetGoodsBySupplier(r requests.GetGoodsBySupplierRequest)
func (qs *QuoteService) GetGoodsBySupplierName(r requests.GetGoodsBySupplierRequest) (result map[string]interface{}, err error) {
supplierIndex := r.SupplierName
queryString, err := query.GetGoodsBySupplierNameQuery(r)
fmt.Println(supplierIndex)
fmt.Println(queryString)
esResult, err := es.CurlES(supplierIndex, queryString)
if err != nil {
return
......@@ -53,6 +50,9 @@ func (qs *QuoteService) GetGoodsBySupplierName(r requests.GetGoodsBySupplierRequ
goodsIds := GetGoodsIdsByEs(esResult)
goodsList, err := GetGoodsInfo(goodsIds)
dullData, err := transformer.DullDataInfo(r.Keyword, goodsList)
quoteTransformer := transformer.QuoteTransformer{}
//还要去转一下阶梯价比例
dullData = quoteTransformer.TransformLadderPrice(dullData)
result = GetReturnSupplierData(dullData)
result["total"] = gjson.Get(esResult, "hits.total").Int()
result["took"] = gjson.Get(esResult, "took").Int()
......
package service
import (
"search_server/middleware"
"search_server/model"
"strings"
)
//推送搜索关键词
func ShowSku(goods model.DullGoodsData) {
len := len(goods.GoodsId)
if goods.GoodsId == "" || goods.BrandName == "" || goods.SupplierName == "" {
return
}
referer := middleware.Context.Request.Header.Get("referer")
if strings.Contains(referer, "www.ichunt.com/s/?k") {
if goods.ProviderName != "" {
goods.BrandName = goods.ProviderName
}
if goods.CompanyName != "" {
goods.SupplierName = goods.CompanyName
}
result := make(map[string]string)
result["goods_id"] = goods.GoodsId
//todo : brand_name正则转换
result["brand_name"] = goods.BrandName
if goods.SupplierId == 17 {
result["supplier_name"] = goods.SupplierName + "-" + goods.Canal
result["supplier_type"] = goods.SupplierName
} else if goods.CompanyName != "" && goods.ProviderName != "" {
result["supplier_name"] = "撮合-" + goods.SupplierName
result["supplier_type"] = "撮合"
} else {
result["supplier_name"] = goods.SupplierName
result["supplier_type"] = goods.SupplierName
}
//todo : goods_name正则替换
result["goods_name"] = goods.GoodsName
if (len < 19 || goods.SupplierId == 10000) && result["supplier_type"] != "撮合" {
result["keyword"] = strings.TrimSpace("keyword")
}
result["adtag"], _ = middleware.Context.Cookie("adtag")
if len < 19 {
result["status"] = "1"
}
}
type SkuService struct {
}
package transformer
import (
"encoding/json"
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/tidwall/gjson"
"regexp"
"search_server/dao"
"search_server/middleware"
"search_server/model"
......@@ -10,6 +13,7 @@ import (
"search_server/pkg/config"
"search_server/pkg/gredis"
"strings"
"time"
)
//处理商品信息数据
......@@ -46,8 +50,7 @@ func DullDataInfo(keyword string, goodsListMap map[string]model.ApiGoods) (resul
goods.LastSearchTime = common.GetLastSearchTime(goods.GoodsId)
//关税信息
goods.CustomsTax = common.GetCustomsTax(goods.GoodsName, goods.BrandName)
//todo : showsku方法
ShowSku(goods)
//价格等信息混淆
if keyword != "---" {
goods, err = MetGoodsInfo(goods)
......@@ -123,7 +126,7 @@ func getSupplierInfo(goods model.DullGoodsData) (model.DullGoodsData, error) {
}
goods.PageFlag = 2
//获取官网信息
officialWebsites := config.Cfg.Section("official_website").KeysHash()
officialWebsites := config.Cfg.Section("OFFICIAL_WEBSITE").KeysHash()
if website, exist := officialWebsites[common.ToString(goods.SupplierId)]; exist {
goods.SupplierWebsite = strings.Replace(website, "liexin", goods.SupplierName, -1)
} else {
......@@ -281,3 +284,81 @@ func MetGoodsInfo(data model.DullGoodsData) (result model.DullGoodsData, err err
return data, err
}
}
//推送搜索商品信息
func ShowSku(goods model.DullGoodsData) {
//绑定需要接收的参数
type ShowSkuParams struct {
GoodsNameEq string `form:"goods_name/eq"`
Keyword string `form:"keyword"`
}
var params ShowSkuParams
middleware.Context.Bind(&params)
goodsIdLen := len(goods.GoodsId)
if goods.GoodsId == "" || goods.BrandName == "" || goods.SupplierName == "" {
return
}
referer := middleware.Context.Request.Header.Get("referer")
//if strings.Contains(referer, "www.ichunt.com/s/?k") {
if strings.Contains(referer, "") {
if goods.ProviderName != "" {
goods.BrandName = goods.ProviderName
}
if goods.CompanyName != "" {
goods.SupplierName = goods.CompanyName
}
r := regexp.MustCompile(`<b .+?>(.+?)<\/b>`)
result := make(map[string]interface{})
result["goods_id"] = goods.GoodsId
//brand_name正则转换
goods.BrandName = r.ReplaceAllString(goods.BrandName, `${1}`)
result["brand_name"] = goods.BrandName
if goods.SupplierId == 17 {
result["supplier_name"] = goods.SupplierName + "-" + goods.Canal
result["supplier_type"] = goods.SupplierName
} else if goods.CompanyName != "" && goods.ProviderName != "" {
result["supplier_name"] = "撮合-" + goods.SupplierName
result["supplier_type"] = "撮合"
} else {
result["supplier_name"] = goods.SupplierName
result["supplier_type"] = goods.SupplierName
}
//goods_name正则替换
goods.GoodsName = r.ReplaceAllString(goods.GoodsName, `${1}`)
result["goods_name"] = goods.GoodsName
if (goodsIdLen < 19 || goods.SupplierId == 10000) && result["supplier_type"] != "撮合" {
result["keyword"] = strings.TrimSpace(params.GoodsNameEq)
} else {
if params.Keyword != "" {
result["keyword"] = strings.TrimSpace(params.Keyword)
} else {
result["keyword"] = goods.GoodsName
}
}
//价格记录
if len(goods.LadderPrice) > 0 {
result["ladder_price"] = goods.LadderPrice
} else {
result["ladder_price"] = []string{}
}
//moq
result["moq"] = goods.Moq
result["show_time"] = time.Now().Unix()
//cookie获取
result["adtag"], _ = middleware.Context.Cookie("adtag")
//状态判断
if goodsIdLen < 19 {
result["status"] = 1
} else {
if goods.Status == 1 {
result["status"] = 1
} else {
result["status"] = 2
}
}
res, _ := json.Marshal(result)
fmt.Println(string(res))
//mq.PushMsg("search_show_sku_list", string(res))
}
}
......@@ -48,3 +48,21 @@ func (qt *QuoteTransformer) TransformCollectData(keyword, supplierName string, c
}
return
}
//提供给客服报价系统专用
func (qt *QuoteTransformer) TransformLadderPrice(dullData []model.DullGoodsData) (result []model.DullGoodsData) {
for key, data := range dullData {
if len(data.LadderPrice) > 0 {
for k, price := range data.LadderPrice {
if price.PriceUs != 0 {
if data.SupplierId == 6 {
dullData[key].LadderPrice[k].PriceUs = data.OriginalPrice[k].PriceUs * data.PriceHkxs
} else {
dullData[key].LadderPrice[k].PriceUs = data.OriginalPrice[k].PriceUs * data.ApiGoods.Coefficient.ExtraRatio
}
}
}
}
}
return dullData
}
......@@ -7,6 +7,7 @@ import (
"github.com/gomodule/redigo/redis"
"github.com/ichunt2019/logger"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5"
"regexp"
"search_server/model"
......@@ -141,6 +142,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
var (
goods_name_arr []map[string]string
keyword string
is_sample bool
)
keyword = ""
goods_name_arr = make([]map[string]string,0)
......@@ -166,20 +168,96 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
if strings.Contains(k,"/") {
k_temp = strings.Split(k,"/")
if len(k_temp) == 2 {
isok := makeQuery(query,source,k_temp,&goods_temp_status,&v,&keyword)
isok := makeQuery(query,source,k_temp,&goods_temp_status,&v,&keyword,&is_sample)
if !isok {
continue;
}
}
}
}
if goods_temp_status <= 0{
query.Must(elastic.NewTermQuery("goods_status",1))
}
//聚合属性
if aType == 1 || aType == 2{
source.Aggregation("brand_id",elastic.NewTermsAggregation().Field("brand_id").Size(1000))
source.Aggregation("encap",elastic.NewTermsAggregation().Field("encap").Size(1000))
source.Aggregation("packing",elastic.NewTermsAggregation().Field("packing").Size(1000))
if zy{
source.Aggregation("attrs",elastic.NewNestedAggregation().Path("attrs").
SubAggregation("attr_name",elastic.NewTermsAggregation().Field("attrs.attr_name").Size(5000).
SubAggregation("attr_value",elastic.NewTermsAggregation().Field("attrs.attr_value").Size(5000))))
}else{
aggClassIdField := ""
if !is_sample{
aggClassIdField = "class_id2"
}else{
aggClassIdField = "sample_class_id"
}
source.Aggregation(aggClassIdField,elastic.NewTermsAggregation().Field(aggClassIdField).Size(1000))
}
}
//排序
//有货排序
if avail_rank,ok :=req["avail_rank"];ok && strings.TrimSpace(avail_rank) == "1"{
avail_rank = strings.TrimSpace(avail_rank)
source.Sort("sort",true)
query.Must(elastic.NewTermQuery("sort",31))
}
//价格排序
if single_rank,ok :=req["single_rank"];ok && single_rank != "" {
switch {
case single_rank == "1":
source.Sort("single_price",false) //asc
case single_rank == "2":
source.Sort("single_price",true) //desc
}
}
//库存排序
if stock_rank,ok :=req["stock_rank"];ok && stock_rank != "" {
switch {
case strings.TrimSpace(stock_rank) == "1":
source.Sort("stock",true) //desc
case strings.TrimSpace(stock_rank) == "2":
source.Sort("stock",false) //asc
}
}
//综合排序
if com_rank,ok :=req["com_rank"];ok && strings.TrimSpace(com_rank) == "1" {
source.Sort("sort",true) //desc
source.Sort("single_price",false) //asc
}
}
length := int64(10)
if offset,ok := req["offset"];ok {
if offsetInt,err:=strconv.ParseInt(offset, 10, 64); err != nil && offsetInt > 0{
length = offsetInt
}
}
page := int64(1)
if p,ok := req["p"];ok {
if pInt,err:=strconv.ParseInt(p, 10, 64); err != nil && pInt > 0{
page = pInt
}
}
start := (page-1)*length
from := start
if start+length >= 10000 {
from = 10000-length
}
source.From(int(from)).Size(int(length))
source.Query(query)
res,_ := elastic.NewSearchRequest().Source(source).Body()
fmt.Println(res)
}
func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions []string,goods_temp_status *int,searchValue *string,keyword *string) bool{
func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions []string,goods_temp_status *int,searchValue *string,
keyword *string,is_sample *bool) bool{
var (
err error
......@@ -193,13 +271,10 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
int_field = int_field
searchKey := conditions[0]
searchCondition := conditions[1]
redisConn :=gredis.Conn("search_r")
defer func(){
redisConn.Close()
}()
searchKey = strings.TrimSpace(searchKey)
searchCondition = strings.TrimSpace(searchCondition)
*searchValue = strings.TrimSpace(*searchValue)
......@@ -344,7 +419,6 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
}
}
query.Must(elastic.NewRangeQuery(searchKey).Gte(paramsRange[0]).Lte(paramsRange[1]))
case "sr":
term_v := make([]string,0)
term_v = strings.Split(*searchValue,",")
......@@ -368,11 +442,48 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
}
}
case "nested":
case "eq":
if attrs_matchs,ok := gjson.Parse(*searchValue).Value().(map[string]interface{});ok{
fmt.Println(attrs_matchs)
for attr_name,attr_value:=range attrs_matchs{
filterNestedAttrsBoolQuery := elastic.NewBoolQuery()
fmt.Println(attr_name)
fmt.Println(attr_value)
filterNestedAttrsBoolQuery.Must(elastic.NewTermQuery("attrs.attr_name",attr_name),elastic.NewTermQuery("attrs.attr_value",attr_value))
query.Must(elastic.NewNestedQuery("attrs",filterNestedAttrsBoolQuery))
}
}
case "eq":
switch searchKey {
case "goods_name","brand_name":
reg := regexp.MustCompile(`[[:^alnum:]]+`)
*searchValue = reg.ReplaceAllString(*searchValue,"")
*searchValue = strings.ReplaceAll(*searchValue,"-","")
newTermQueryName := ""
if searchKey == "goods_name"{
newTermQueryName = "auto_goods_name.raw"
}else if(searchKey == "brand_name"){
newTermQueryName = "auto_brand_name2.raw"
}
query.Must(elastic.NewTermQuery(newTermQueryName,*searchValue))
case "sample_max_number","sample_status", "sample_class_id":
*is_sample = true
query.Must(elastic.NewTermQuery(searchKey,*searchValue))
case "supplier_id":
term_v = strings.Split(*searchValue,",")
termsQuerySlice := make([]int64,0)
for _,v:=range term_v{
if term_v1_int,err := strconv.ParseInt(v, 10, 64);err == nil{
termsQuerySlice = append(termsQuerySlice,term_v1_int)
}
}
query.Must(elastic.NewTermsQuery("supplier_id",termsQuerySlice))
}
}
return true
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"github.com/syyongx/php2go"
"reflect"
"search_server/boot"
)
......@@ -28,4 +29,23 @@ func main() {
if err := boot.Boot(path); err != nil {
fmt.Println(err)
}
a := []int{1,2,3}
fmt.Println(InterfaceSlice(a))
}
func InterfaceSlice(slice interface{}) []interface{} {
s := reflect.ValueOf(slice)
if s.Kind() != reflect.Slice {
panic("InterfaceSlice() given a non-slice type")
}
ret := make([]interface{}, s.Len())
for i := 0; i < s.Len(); i++ {
ret[i] = s.Index(i).Interface()
}
return ret
}
......@@ -2,34 +2,23 @@ package main
import (
"log"
"os"
"time"
)
func breadthFirst(f func(item string) []string, worklist []string) {
seen := make(map[string]bool)
for len(worklist) > 0 {
items := worklist
worklist = nil
for _, item := range items {
if !seen[item] {
seen[item] = true
worklist = append(worklist, f(item)...)
}
}
}
func main(){
bigSlowOperation()
}
func crawl(url string) []string {
fmt.Println(url)
list, err := links.Extract(url)
if err != nil {
log.Print(err)
}
return list
}
func bigSlowOperation() {
defer trace("bigSlowOperation")() // don't forget the
// ...lots of work…
time.Sleep(10 * time.Second) // simulate slow
func main() {
// Crawl the web breadth-first,
// starting from the command-line arguments.
breadthFirst(crawl, os.Args[1:])
}
func trace(msg string) func() {
start := time.Now()
log.Printf("enter %s", msg)
return func() {
log.Printf("exit %s (%s)", msg,time.Since(start))
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment