Commit ac67a6be by 孙龙

up

parent c3ef9a6d
...@@ -93,6 +93,20 @@ Index=liexin_ziying ...@@ -93,6 +93,20 @@ Index=liexin_ziying
16=g4 16=g4
17=x4 17=x4
;自营以某些单位进行搜索时,进行特殊处理
[ZIYING_MEASURE]
0=
1=uf
2=v
3=kg
4=MHz
5=pf
6=pin
7=ppm
8=kw
[official_website] [official_website]
1 = https://www.futureelectronics.cn/search/?text=liexin 1 = https://www.futureelectronics.cn/search/?text=liexin
2 = http://www.powerandsignal.com/Products/Search?searchBox=liexin 2 = http://www.powerandsignal.com/Products/Search?searchBox=liexin
......
...@@ -149,3 +149,10 @@ func Rand(min, max int) int { ...@@ -149,3 +149,10 @@ func Rand(min, max int) int {
return int(n.Int64()) + min return int(n.Int64()) + min
} }
func CopyMapString(distmap map[string]string) map[string]string{
tmpmap := make(map[string]string,0)
for k, v := range distmap {
tmpmap[k] = v
}
return tmpmap
}
\ No newline at end of file
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"gopkg.in/olivere/elastic.v5" "gopkg.in/olivere/elastic.v5"
"regexp" "regexp"
"search_server/model" "search_server/model"
"search_server/pkg/common"
"search_server/pkg/config" "search_server/pkg/config"
"search_server/pkg/gredis" "search_server/pkg/gredis"
"strconv" "strconv"
...@@ -95,7 +96,7 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){ ...@@ -95,7 +96,7 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){
if err != nil{ if err != nil{
logger.Error("解析自营分类列表失败 s%,%s",err,classList) logger.Error("解析自营分类列表失败 s%,%s",err,classList)
} }
//fmt.Println(classList)
classidstr := req["class_id/condition"] classidstr := req["class_id/condition"]
classid,err = strconv.ParseInt(classidstr, 10, 64) classid,err = strconv.ParseInt(classidstr, 10, 64)
if err != nil{ if err != nil{
...@@ -107,20 +108,23 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){ ...@@ -107,20 +108,23 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){
if classid > 0 && item.ClassID1 == classid{ if classid > 0 && item.ClassID1 == classid{
item.Flag = 1 item.Flag = 1
classLight = append(classLight,item) classLight = append(classLight,item)
req["class_id1/condition"] = strconv.FormatInt(item.ClassID1,10)
break OuterLoop break OuterLoop
} }
for _,item2 := range item.ClassID2List{ for _,item2 := range item.ClassID2List{
if classid > 0 && item2.ClassID2 == classid{ if classid > 0 && item2.ClassID2 == classid{
item2.Flag = 1 item2.Flag = 1
req["class_id2/condition"] = strconv.FormatInt(item2.ClassID2,10)
classLight = append(classLight,item) classLight = append(classLight,item)
break OuterLoop break OuterLoop
} }
} }
} }
} }
req2 := make(map[string]string,0)
searchZiYingGoods(req,true,zhyClassList,classLight,_type) req2 = common.CopyMapString(req)
delete(req2,"class_id/condition")
searchZiYingGoods(req2,true,zhyClassList,classLight,_type)
return nil return nil
} }
...@@ -145,21 +149,17 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL ...@@ -145,21 +149,17 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
ziyingBrandReplace := config.Cfg.Section("ZIYING_BRAND_REPLACE").KeysHash() ziyingBrandReplace := config.Cfg.Section("ZIYING_BRAND_REPLACE").KeysHash()
if ziyingBrandReplace != nil && ziyingBrandReplace[goodsNameCondition] != "" { 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,map[string]string{"brand_name/condition":ziyingBrandReplace[goodsNameCondition]})
delete(req,"goods_name/condition")
} }
} }
if req["p"] == "" || req["p"] == "0"{ if req["p"] == "" || req["p"] == "0"{
req["p"] = "1" req["p"] = "1"
} }
//index := config.Get("ZIYING_CONFIG")
goods_temp_status := 0 goods_temp_status := 0
source := elastic.NewSearchSource() source := elastic.NewSearchSource()
source.StoredFields("goods_id","goods_name","sample_max_number","sample_status","sample_class_id") source.StoredFields("goods_id","goods_name","sample_max_number","sample_status","sample_class_id")
query := elastic.NewBoolQuery() query := elastic.NewBoolQuery()
if(len(req) > 0){ if(len(req) > 0){
for k,v:=range req{ for k,v:=range req{
...@@ -204,15 +204,13 @@ func makeQuery(query *elastic.BoolQuery,conditions []string,goods_temp_status *i ...@@ -204,15 +204,13 @@ func makeQuery(query *elastic.BoolQuery,conditions []string,goods_temp_status *i
switch searchCondition{ switch searchCondition{
case "condition": case "condition":
//status
if searchKey == "status"{
*goods_temp_status = 1
}
if searchKey != "status" && searchCondition == ""{ if searchKey != "status" && searchCondition == ""{
return false; return false;
} }
//goods_name switch searchKey {
if searchKey == "goods_name"{ case "status":
*goods_temp_status = 1
case "goods_name":
//fmt.Println(5569) //fmt.Println(5569)
strNo := []string{"/" , "," ,"、" ,"?" , "," , ":",",","?",",","、",":"} strNo := []string{"/" , "," ,"、" ,"?" , "," , ":",",","?",",","、",":"}
for _,strNoV:=range strNo{ for _,strNoV:=range strNo{
...@@ -279,21 +277,17 @@ func makeQuery(query *elastic.BoolQuery,conditions []string,goods_temp_status *i ...@@ -279,21 +277,17 @@ func makeQuery(query *elastic.BoolQuery,conditions []string,goods_temp_status *i
goods_name_arr := append(term_v,goods_name_cn...) goods_name_arr := append(term_v,goods_name_cn...)
fmt.Println("goods_name_arr",goods_name_arr) fmt.Println("goods_name_arr",goods_name_arr)
*keyword = *searchValue *keyword = *searchValue
for _,v:=range term_v{
fmt.Println("goods_name",term_v) if v != ""{
query.Must(elastic.NewTermQuery("goods_name",v))
}
}
if len(goods_name_arr) > 0{ if len(goods_name_arr) > 0{
query.Must(elastic.NewMatchQuery("goods_name_cn",strings.Join(goods_name_cn," ")).MinimumShouldMatch("100%")) query.Must(elastic.NewMatchQuery("goods_name_cn",strings.Join(goods_name_cn," ")).MinimumShouldMatch("100%"))
} }
case "brand_name":
}else{
term_v = strings.Split(*searchValue,",") term_v = strings.Split(*searchValue,",")
} *searchValue = strings.ToUpper(strings.TrimSpace(*searchValue))
//fmt.Println(term_v)
*searchValue = strings.ToUpper(strings.TrimSpace(*searchValue))
if searchKey == "brand_name"{
reg := regexp.MustCompile(`[[:^alnum:]]+`) reg := regexp.MustCompile(`[[:^alnum:]]+`)
if len(term_v) > 0{ if len(term_v) > 0{
for k,v:=range term_v{ for k,v:=range term_v{
...@@ -301,16 +295,33 @@ func makeQuery(query *elastic.BoolQuery,conditions []string,goods_temp_status *i ...@@ -301,16 +295,33 @@ func makeQuery(query *elastic.BoolQuery,conditions []string,goods_temp_status *i
} }
query.Must(elastic.NewTermsQuery("auto_brand_name2",term_v)) query.Must(elastic.NewTermsQuery("auto_brand_name2",term_v))
} }
} case "stock":
//stock
if searchKey == "stock"{
if stockValue,err = strconv.ParseInt(*searchValue, 10, 64);err == nil{ if stockValue,err = strconv.ParseInt(*searchValue, 10, 64);err == nil{
if stockValue > 1000000 { if stockValue > 1000000 {
stockValue = 1000000 stockValue = 1000000
} }
query.Must(elastic.NewRangeQuery("stock").Gte(stockValue)) query.Must(elastic.NewRangeQuery("stock").Gte(stockValue))
} }
default:
*searchValue = strings.ToUpper(strings.TrimSpace(*searchValue))
term_v = strings.Split(*searchValue,",")
term_v_interface := make([]interface{},0)
for _,v:=range term_v{
term_v_interface = append(term_v_interface,v)
}
for _,field:=range int_field{
if searchKey == field{
for k,v:=range term_v{
if stockValue,err = strconv.ParseInt(v, 10, 64);err == nil{
term_v_interface[k] = stockValue
}
}
break
}
}
query.Must(elastic.NewTermsQuery(searchKey,term_v_interface))
} }
case "order":
case "range": case "range":
case "sr": case "sr":
......
package main package main
import ( import (
<<<<<<< HEAD
"bytes" "bytes"
"fmt" "fmt"
"strconv"
) )
func intsToString(values []int) string { func intsToString(values []int) string {
...@@ -19,30 +19,23 @@ func intsToString(values []int) string { ...@@ -19,30 +19,23 @@ func intsToString(values []int) string {
return buf.String() return buf.String()
} }
func main() {
fmt.Println(intsToString([]int{1, 2, 3})) // "[1, 2, 3]"
=======
"fmt"
"strconv"
)
func main() { func main() {
var a,b,c float64 var a,b,c float64
a=1.69*100 a=1.69*100
b=1.7*10 b=1.7*10
c=a*b/(100*10) c=a*b/(100*10)
//ȷ2.873 //��ȷ���2.873
fmt.Println(c) fmt.Println(c)
//fmt.Println(fmt.Sprintf("%.2f",c)) //fmt.Println(fmt.Sprintf("%.2f",c))
//fmt.Println(FloatRound(c,2)) //fmt.Println(FloatRound(c,2))
} }
// ȡСλ // ��ȡС��λ��
func FloatRound(f float64, n int) float64 { func FloatRound(f float64, n int) float64 {
format := "%." + strconv.Itoa(n) + "f" format := "%." + strconv.Itoa(n) + "f"
//fmt.Println(format) //fmt.Println(format)
res, _ := strconv.ParseFloat(fmt.Sprintf(format, f), 64) res, _ := strconv.ParseFloat(fmt.Sprintf(format, f), 64)
return res return res
>>>>>>> 326ae7ed67d5d2db331dddd1277d36b8b1992b08
} }
\ No newline at end of file
package main
import (
"log"
"os"
)
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 crawl(url string) []string {
fmt.Println(url)
list, err := links.Extract(url)
if err != nil {
log.Print(err)
}
return list
}
func main() {
// Crawl the web breadth-first,
// starting from the command-line arguments.
breadthFirst(crawl, os.Args[1:])
}
\ 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