package util import ( "encoding/json" "errors" "fmt" "models" "qfw/util" "qfw/util/elastic" "regexp" sql "sqlmodel" "strings" "time" // "go.mongodb.org/mongo-driver/bson/primitive" "gopkg.in/mgo.v2/bson" ) const ( TitleMatchType = "1" //标题匹配 DetailMatchType = "2" //全文匹配 PurchasingMatchType = "3" //标的物匹配 AttachmentsMatchType = "4" //附件匹配 ProjectnameMatchType = "5" //项目名称匹配 BuyerMatchType = "6" //采购单位匹配 SWinnerMatchType = "7" //中标单位匹配 BuyerMatchType1 = "8" //采购单位(正则)匹配 SWinnerMatchType1 = "9" //中标单位(正则)匹配 TitleMatchTypeStr = "title" //标题匹配 DetailMatchTypeStr = "detail" //全文匹配 PurchasingMatchTypeStr = "purchasing" //标的物匹配 AttachmentsMatchTypeStr = "filetext" //附件匹配 ProjectnameMatchTypeStr = "projectname" //项目名称匹配 BuyerMatchTypeStr = "buyer" //项目名称匹配 SWinnerMatchTypeStr = "s_winner" //项目名称匹配 TitleMatchTypeField = "title" //标题匹配 DetailMatchTypeField = "detail" //全文匹配 PurchasingMatchTypeField = "purchasing" //标的物匹配 AttachmentsMatchTypeField = "filetext" //附件匹配 ProjectnameMatchTypeField = "projectname" //项目名称匹配 BuyerMatchTypeField = "buyer" //项目名称匹配 SWinnerMatchTypeField = "s_winner" //项目名称匹配 MultiMatchType = "phrase" Standard = 1 //1:标准字段包, Advanced = 2 //2:高级字段包 Standardstr = "standard" //1:标准字段包 Advancedstr = "advanced" //2:高级字段包 Url = "https://www.jianyu360.com/article/content/%s.html" ) func UtilEsSaveData(sdataid string, datas *[]map[string]interface{}) error { defer util.Catch() Mgo.Del("tagsdata", bson.M{"s_dataid": sdataid}) if Mgo.SaveBulk("tagsdata", *datas...) { return nil } else { return errors.New("mongo save err") } } //客户规则 func UtilEsFind1(tags map[string]interface{}) (error, int64) { defer util.Catch() sdataid := util.ObjToString(tags["s_dataid"]) esquery := util.ObjToString(tags["s_esquery"]) if len(esquery) < 1 || len(sdataid) < 1 { return errors.New("s_esquery or s_dataid no found"), 0 } i_maxnum := util.Int64All(tags["i_maxnum"]) if i_maxnum <= 0 { i_maxnum = 100 } maths := make([]map[string]string, 0) if orules, ok := tags["o_rules"].([]interface{}); ok { for _, v := range orules { orule, _ := v.(map[string]interface{}) maths = append(maths, map[string]string{ "s_matchkey": util.ObjToString(orule["s_matchkey"]), "s_keymatch": util.ObjToString(orule["s_keymatch"]), }) } } else if orules, ok := tags["o_rules"].([]map[string]interface{}); ok { for _, v := range orules { maths = append(maths, map[string]string{ "s_matchkey": util.ObjToString(v["s_matchkey"]), "s_keymatch": util.ObjToString(v["s_keymatch"]), }) } } else { return errors.New("o_rules no found"), 0 } client := elastic.GetEsConn() defer elastic.DestoryEsConn(client) esquery = esquery[:len(esquery)-1] + `,"size":` + fmt.Sprintf("%d", i_maxnum) + `}` searchResult, err := client.Search(EsIndex).Source(esquery).Do() if err == nil && searchResult.Hits != nil { datas := make([]map[string]interface{}, 0) util.Debug("es查询到的数量:", searchResult.Hits.TotalHits) for _, v := range searchResult.Hits.Hits { item := make(map[string]interface{}) if json.Unmarshal(*v.Source, &item) == nil { delete(item, "_id") item["info_id"] = v.Id item["s_dataid"] = sdataid item["s_jyhref"] = fmt.Sprintf(Url, util.CommonEncodeArticle("content", v.Id)) item["i_createtime"] = time.Now().Unix() var d *DFA = &DFA{} var analyKeys []string //找到的关键词 var matchType []string //匹配方式 for _, math := range maths { fileds := strsToArr(math["s_keymatch"], "field") d.AddWord(strings.Split(math["s_matchkey"], ",")...) mkMap := make(map[string]interface{}) tmpMap := make(map[string]interface{}) for _, mk := range strings.Split(math["s_matchkey"], ",") { if strings.Contains(mk, "&&") { arr := strings.Split(mk, "&&") for _, s := range arr { if s != "" { tmpMap[s] = mk if b, _ := regexp.MatchString("[A-Z]", s); b { mkMap[strings.ToLower(s)] = s d.AddWord(strings.ToLower(s)) } else { d.AddWord(s) } } } } else { if b, _ := regexp.MatchString("[A-Z]", mk); b { mkMap[strings.ToLower(mk)] = mk d.AddWord(strings.ToLower(mk)) } else { d.AddWord(mk) } } } for _, filed := range fileds { filed1 := strings.ToLower(util.ObjToString(item[filed])) ddds := d.Analy(filed1) analyKeys = append(analyKeys, ddds...) } if len(analyKeys) > 0 { matchType = append(matchType, strings.Join(fileds, ",")) for k, v := range analyKeys { if tmpMap[v] != "" && tmpMap[v] != nil { analyKeys[k] = util.ObjToString(tmpMap[v]) } } for _, v1 := range analyKeys { if mkMap[v1] != "" && mkMap[v1] != nil { analyKeys = deleteSlice(analyKeys, v1) analyKeys = append(analyKeys, util.ObjToString(mkMap[v1])) } } } d.Clear() } //去重 ssavekey := make(map[string]bool) for _, v := range analyKeys { ssavekey[v] = true } ssavekeys := []string{} for k := range ssavekey { ssavekeys = append(ssavekeys, k) } item["s_matchkey"] = GetMactchKey(maths, item) item["s_matchtype"] = strings.Join(matchType, ",") findwinner := strings.TrimSpace(util.ObjToString(item["winner"])) if findwinner != "" { finddata := MgoEnps.FindOne(EnpsColl, bson.M{"company_name": findwinner}) if finddata != nil { if legal_person := util.ObjToString(finddata["legal_person"]); legal_person != "" { item["legal_person"] = legal_person } if email := util.ObjToString(finddata["company_email"]); email != "" { item["company_email"] = email } if phone := util.ObjToString(finddata["company_phone"]); phone != "" { item["company_phone"] = phone } //从最新年报中获取 中标单位联系电话、中标单位邮箱 // if annual_reports, ok := finddata["annual_reports"].(primitive.A); ok && len(annual_reports) > 0 { // report_year := Sort_year_report(annual_reports) //最新年报 // if len(report_year) > 0 { // if email := util.ObjToString(report_year["company_email"]); email != "" { // item["company_email"] = email // } // if phone := util.ObjToString(report_year["company_phone"]); phone != "" { // item["company_phone"] = phone // } // } // } item["qyk"] = finddata } } datas = append(datas, item) } } Mgo.Update("cuserdepartrule", bson.M{"_id": tags["_id"]}, bson.M{ "$set": bson.M{ "i_estotal": searchResult.Hits.TotalHits, }}, false, false) count := searchResult.Hits.TotalHits return UtilEsSaveData(sdataid, &datas), count } else { util.Debug(err) return err, 0 } } func Utiltags(tag map[string]interface{}) string { defer util.Catch() tmpbyte, _ := json.Marshal(tag) tab := models.Tag{} err := json.Unmarshal(tmpbyte, &tab) if err != nil { return "json err:" + err.Error() } QueryObjecct := sql.QueryObjecct{} ffBoolObject := sql.BoolObject{} adsBoolObect := sql.NewEsObject{} if tab.Sarea != "" { adsBoolObect.Bool.Should = append(adsBoolObect.Bool.Should, sql.AreaCityDistrictMust{AreaCityDistrict: &sql.AreaCityDistrict{Area: strings.Split(tab.Sarea, ",")}}) } if tab.Scity != "" { adsBoolObect.Bool.Should = append(adsBoolObect.Bool.Should, sql.AreaCityDistrictMust{AreaCityDistrict: &sql.AreaCityDistrict{City: strings.Split(tab.Scity, ",")}}) } if tab.Sdistrict != "" { //城市——区县 cityds := strings.Split(tab.Sdistrict, ",") var ds []string for _, v := range cityds { ds = append(ds, strings.Split(v, "-")[1]) } adsBoolObect.Bool.Should = append(adsBoolObect.Bool.Should, sql.AreaCityDistrictMust{AreaCityDistrict: &sql.AreaCityDistrict{District: ds}}) } if len(adsBoolObect.Bool.Should) > 0 { ffBoolObject.Must = append(ffBoolObject.Must, adsBoolObect) } if tab.Stoptype != "" || tab.Ssubtype != "" { if len(tab.Stoptype) > 0 { toptypeSubtype := sql.ToptypeSubtype{} toptypeSubtype.Toptype = strings.Split(tab.Stoptype, ",") ffBoolObject.Must = append(ffBoolObject.Must, sql.ToptypeSubtypeMust{&toptypeSubtype}) } if len(tab.Ssubtype) > 0 { toptypeSubtype := sql.ToptypeSubtype{} toptypeSubtype.Subtype = strings.Split(tab.Ssubtype, ",") ffBoolObject.Must = append(ffBoolObject.Must, sql.ToptypeSubtypeMust{&toptypeSubtype}) } } if tab.Istarttime > 0 && tab.Iendtime > 0 { ffBoolObject.Must = append(ffBoolObject.Must, sql.PublishtimeMust{PublishtimeObject: &sql.PublishtimeObject{Publishtime: &sql.Publishtime{ Gte: tab.Istarttime, Lt: tab.Iendtime, }}}) } else if tab.Istarttime > 0 { ffBoolObject.Must = append(ffBoolObject.Must, sql.PublishtimeMust{PublishtimeObject: &sql.PublishtimeObject{Publishtime1: &sql.Publishtime1{ Gte: tab.Istarttime, }}}) } else if tab.Iendtime > 0 { ffBoolObject.Must = append(ffBoolObject.Must, sql.PublishtimeMust{PublishtimeObject: &sql.PublishtimeObject{Publishtime2: &sql.Publishtime2{ Lt: tab.Iendtime, }}}) } if tab.Sbudget != "" { if strings.Contains(tab.Sbudget, "大于") && strings.Contains(tab.Sbudget, "小于") { arr := strings.Split(tab.Sbudget, ",") limit := &sql.BudgetOrBidamount{ Gte: util.Float64All(strings.Replace(arr[0], "大于", "", -1)), Lt: util.Float64All(strings.Replace(arr[1], "小于", "", -1)), } ffBoolObject.Must = append(ffBoolObject.Must, sql.BudgetMust{BudgetObj: &sql.BudgetObj{Budget: limit}}) } else if strings.Contains(tab.Sbudget, "大于") { limit := &sql.BudgetOrBidamount{ Gte: util.Float64All(strings.Replace(tab.Sbudget, "大于", "", -1)), } ffBoolObject.Must = append(ffBoolObject.Must, sql.BudgetMust{BudgetObj: &sql.BudgetObj{Budget: limit}}) } else if strings.Contains(tab.Sbudget, "小于") { limit := &sql.BudgetOrBidamount{ Lt: util.Float64All(strings.Replace(tab.Sbudget, "小于", "", -1)), } ffBoolObject.Must = append(ffBoolObject.Must, sql.BudgetMust{BudgetObj: &sql.BudgetObj{Budget: limit}}) } } if tab.Sbidamount != "" { if strings.Contains(tab.Sbidamount, "大于") && strings.Contains(tab.Sbidamount, "小于") { arr := strings.Split(tab.Sbidamount, ",") limit := &sql.BudgetOrBidamount{ Gte: util.Float64All(strings.Replace(arr[0], "大于", "", -1)), Lt: util.Float64All(strings.Replace(arr[1], "小于", "", -1)), } ffBoolObject.Must = append(ffBoolObject.Must, sql.BidamountMust{BidamountObj: &sql.BidamountObj{Bidamount: limit}}) } else if strings.Contains(tab.Sbidamount, "大于") { limit := &sql.BudgetOrBidamount{ Gte: util.Float64All(strings.Replace(tab.Sbidamount, "大于", "", -1)), } ffBoolObject.Must = append(ffBoolObject.Must, sql.BidamountMust{BidamountObj: &sql.BidamountObj{Bidamount: limit}}) } else if strings.Contains(tab.Sbidamount, "小于") { limit := &sql.BudgetOrBidamount{ Lt: util.Float64All(strings.Replace(tab.Sbidamount, "小于", "", -1)), } ffBoolObject.Must = append(ffBoolObject.Must, sql.BidamountMust{BidamountObj: &sql.BidamountObj{Bidamount: limit}}) } } if tab.Sglobalbuyerclass != "" { if len(tab.Sglobalbuyerclass) > 0 { buyerclass := sql.BuyerclassObject{ Terms: struct { Buyerclass []string `json:"buyerclass,omitempty"` }{ Buyerclass: strings.Split(tab.Sglobalbuyerclass, ","), }, } ffBoolObject.Must = append(ffBoolObject.Must, buyerclass) } } if tab.Sglobaltopscopeclass != "" || tab.Sglobalsubscopeclass != "" { if len(tab.Sglobaltopscopeclass) > 0 { topScopeclass := sql.Scopeclass{} topScopeclass.Globaltopscopeclass = strings.Split(tab.Sglobaltopscopeclass, ",") ffBoolObject.Must = append(ffBoolObject.Must, sql.ScopeclassMust{&topScopeclass}) } else if len(tab.Sglobalsubscopeclass) > 0 { subScopeclass := sql.Scopeclass{} subScopeclass.Globalsubscopeclass = strings.Split(tab.Sglobalsubscopeclass, ",") ffBoolObject.Must = append(ffBoolObject.Must, sql.ScopeclassMust{&subScopeclass}) } } fqBoolObject := sql.BoolObject{} if len(tab.Sexistfields) > 0 { tmpsfields := strings.Split(tab.Sexistfields, ",") for _, v := range tmpsfields { fqBoolObject.MustNot = append(fqBoolObject.MustNot, sql.ExistfieldsObjectMust{ ExistfieldsObject: &sql.ExistfieldsObject{Filter: struct { Missing struct { Field string `json:"field,omitempty"` } `json:"missing,omitempty"` }{ Missing: struct { Field string `json:"field,omitempty"` }{Field: v}, }, }, }) } } newEsObject := sql.NewEsObject{} if tab.Sglobaladdkey != "" && tab.Sglobaladdkeymatch != "" { if tmps := strsToArr(tab.Sglobaladdkeymatch, "str"); tmps != nil { newEsObject = method1(newEsObject, tab.Sglobaladdkey, tab.Sglobaladdkeymatch, tmps) } } if len(newEsObject.Bool.Should) > 0 || len(newEsObject.Bool.MustNot) > 0 || len(newEsObject.Bool.Must) > 0 { fqBoolObject.Must = append(fqBoolObject.Must, newEsObject) } nots := sql.NewEsObject{} if tab.Sglobalnotkey != "" && tab.Sglobalnotkeymatch != "" { if tmps := strsToArr(tab.Sglobalnotkeymatch, "str"); tmps != nil { nots = method1(nots, tab.Sglobalnotkey, tab.Sglobalnotkeymatch, tmps) } } if len(nots.Bool.Should) > 0 { fqBoolObject.MustNot = append(fqBoolObject.MustNot, nots) } torules := sql.BoolObject{} for _, v := range tab.Orules { tmpses := sql.NewEsObject{} if skeymatchs := strsToArr(v.Skeymatch, "str"); skeymatchs != nil { tmpnewEsObject := sql.NewEsObject{} tmpnewEsObject = method1(tmpnewEsObject, v.Smatchkey, v.Skeymatch, skeymatchs) if len(tmpnewEsObject.Bool.Should) > 0 || len(tmpnewEsObject.Bool.Must) > 0 || len(tmpnewEsObject.Bool.MustNot) > 0 { tmpses.Bool.Must = append(tmpses.Bool.Must, tmpnewEsObject) } } if saddkeymatchs := strsToArr(v.Saddkeymatch, "str"); saddkeymatchs != nil { addkeyarr := sql.NewEsObject{} addkeyarr = method1(addkeyarr, v.Saddkey, v.Saddkeymatch, saddkeymatchs) if len(addkeyarr.Bool.Should) > 0 { tmpses.Bool.Must = append(tmpses.Bool.Must, addkeyarr) } } if snotkeymatchs := strsToArr(v.Snotkeymatch, "str"); snotkeymatchs != nil { tmpses = method2(tmpses, v.Snotkey, v.Snotkeymatch, snotkeymatchs) } if len(v.Stopscopeclass) > 0 { sArr := strings.Split(v.Stopscopeclass, ",") tmpses.Bool.Must = append(tmpses.Bool.Must, sql.TopscopeclassObject{ Terms: struct { Topscopeclass []string `json:"s_topscopeclass,omitempty"` }{ Topscopeclass: sArr, }, }) } else if len(v.Ssubscopeclass) > 0 { tmpses.Bool.Must = append(tmpses.Bool.Must, sql.SubscopeclassObject{ Terms: struct { Subscopeclass []string `json:"s_subscopeclass,omitempty"` }{ Subscopeclass: strings.Split(v.Ssubscopeclass, ","), }, }) } if len(v.Sbuyerclass) > 0 { tmpses.Bool.Must = append(tmpses.Bool.Must, sql.BuyerclassObject{ Terms: struct { Buyerclass []string `json:"buyerclass,omitempty"` }{ Buyerclass: strings.Split(v.Sbuyerclass, ","), }, }) } torules.Should = append(torules.Should, tmpses) } if len(ffBoolObject.Must) > 0 || len(ffBoolObject.MustNot) > 0 || len(ffBoolObject.Should) > 0 { QueryObjecct.Filtered.Filter = &sql.Filter{} QueryObjecct.Filtered.Filter.Bool = &ffBoolObject } if len(fqBoolObject.Must) > 0 || len(fqBoolObject.MustNot) > 0 || len(fqBoolObject.Should) > 0 { QueryObjecct.Filtered.Query = &sql.Query{} QueryObjecct.Filtered.Query.Bool = &fqBoolObject if len(torules.Should) > 0 { QueryObjecct.Filtered.Query.Bool.Must = append(QueryObjecct.Filtered.Query.Bool.Must, map[string]interface{}{ "bool": torules, }) } } else if len(torules.Should) > 0 { if QueryObjecct.Filtered.Query == nil { QueryObjecct.Filtered.Query = &sql.Query{} QueryObjecct.Filtered.Query.Bool = &fqBoolObject } QueryObjecct.Filtered.Query.Bool.Must = append(QueryObjecct.Filtered.Query.Bool.Must, map[string]interface{}{ "bool": torules, }) } rdata := make(map[string]interface{}) rdata["query"] = QueryObjecct esbytes, _ := json.Marshal(rdata) esStr := strings.Replace(string(esbytes), "regexp1", "regexp", -1) esStr = strings.Replace(esStr, "publishtime1", "publishtime", -1) esStr = strings.Replace(esStr, "publishtime2", "publishtime", -1) return strings.Replace(esStr, "regexp2", "regexp", -1) } func strsToArr(strs string, typestr string) []string { if len(strs) > 0 { tmps := strings.Split(strs, ",") switch typestr { case "str": for index, vint := range tmps { switch vint { case TitleMatchType: tmps[index] = TitleMatchTypeStr case DetailMatchType: tmps[index] = DetailMatchTypeStr case PurchasingMatchType: tmps[index] = PurchasingMatchTypeStr case AttachmentsMatchType: tmps[index] = AttachmentsMatchTypeStr case ProjectnameMatchType: tmps[index] = ProjectnameMatchTypeStr case BuyerMatchType: tmps[index] = BuyerMatchTypeStr case SWinnerMatchType: tmps[index] = SWinnerMatchTypeStr case BuyerMatchType1: tmps[index] = BuyerMatchTypeStr case SWinnerMatchType1: tmps[index] = SWinnerMatchTypeStr } } return tmps case "field": for index, vint := range tmps { switch vint { case TitleMatchType: tmps[index] = TitleMatchTypeField case DetailMatchType: tmps[index] = DetailMatchTypeField case PurchasingMatchType: tmps[index] = PurchasingMatchTypeField case AttachmentsMatchType: tmps[index] = AttachmentsMatchTypeField case ProjectnameMatchType: tmps[index] = ProjectnameMatchTypeField case BuyerMatchType: tmps[index] = BuyerMatchTypeField case SWinnerMatchType: tmps[index] = SWinnerMatchTypeField case BuyerMatchType1: tmps[index] = BuyerMatchTypeField case SWinnerMatchType1: tmps[index] = SWinnerMatchTypeField } } return tmps } } return nil } func init() { EsIndex = util.ObjToString(Sysconfig["elasticsearch_index"]) EsType = util.ObjToString(Sysconfig["elasticsearch_type"]) } func method1(newEsObject sql.NewEsObject, keyword, keymatch string, tmps []string) sql.NewEsObject { for _, vv := range strings.Split(keyword, ",") { if vv == "" { continue } if len(tmps) == 1 && (strings.Contains(keymatch, "8") || strings.Contains(keymatch, "9")) { //中标单位、采购单位、中标单位(正则)、采购单位(正则) 单选 strs := "" if strings.Contains(vv, "&&") { strs = ".*" + strings.Replace(vv, "&&", ".*", -1) + ".*" } else { strs = ".*" + vv + ".*" } if tmps[0] == "buyer" { newEsObject.Bool.Should = append(newEsObject.Bool.Should, sql.Regular{ Regexp1: &sql.Regular_Buyer{Buyer: strs}, }) } else if tmps[0] == "s_winner" { newEsObject.Bool.Should = append(newEsObject.Bool.Should, sql.Regular{ Regexp2: &sql.Regular_winner{Winner: strs}, }) } } else { addkeylines := strings.Split(vv, "&&") if len(addkeylines) > 1 { addkeyline := sql.NewEsObject{} for _, vvv := range addkeylines { if vvv == "" { continue } addkeyline.Bool.Must = append(addkeyline.Bool.Must, sql.ShouldObj{ MultiMatch: &sql.MultiMatch{ Query: vvv, Type: MultiMatchType, Fields: tmps, }, }) } if len(addkeyline.Bool.Must) > 0 { newEsObject.Bool.Should = append(newEsObject.Bool.Should, addkeyline) } } else { newEsObject.Bool.Should = append(newEsObject.Bool.Should, sql.ShouldObj{ MultiMatch: &sql.MultiMatch{ Query: vv, Type: MultiMatchType, Fields: tmps, }, }) } } } return newEsObject } func method2(newEsObject sql.NewEsObject, keyword, keymatch string, tmps []string) sql.NewEsObject { for _, vv := range strings.Split(keyword, ",") { if vv == "" { continue } if len(tmps) == 1 && (strings.Contains(keymatch, "8") || strings.Contains(keymatch, "9")) { //中标单位、采购单位、中标单位(正则)、采购单位(正则) 单选 strs := "" if strings.Contains(vv, "&&") { strs = ".*" + strings.Replace(vv, "&&", ".*", -1) + ".*" } else { strs = ".*" + vv + ".*" } if tmps[0] == "buyer" { newEsObject.Bool.MustNot = append(newEsObject.Bool.MustNot, sql.Regular{ Regexp1: &sql.Regular_Buyer{Buyer: strs}, }) } else if tmps[0] == "s_winner" { newEsObject.Bool.MustNot = append(newEsObject.Bool.MustNot, sql.Regular{ Regexp2: &sql.Regular_winner{Winner: strs}, }) } } else { addkeylines := strings.Split(vv, "&&") if len(addkeylines) > 1 { addkeyline := sql.NewEsObject{} for _, vvv := range addkeylines { if vvv == "" { continue } addkeyline.Bool.Must = append(addkeyline.Bool.Must, sql.ShouldObj{ MultiMatch: &sql.MultiMatch{ Query: vvv, Type: MultiMatchType, Fields: tmps, }, }) } if len(addkeyline.Bool.Must) > 0 { newEsObject.Bool.MustNot = append(newEsObject.Bool.MustNot, addkeyline) } } else { newEsObject.Bool.MustNot = append(newEsObject.Bool.MustNot, sql.ShouldObj{ MultiMatch: &sql.MultiMatch{ Query: vv, Type: MultiMatchType, Fields: tmps, }, }) } } } return newEsObject } /** * 一级公告行业处理 d、t、p */ func method3(arr []string) []string { var sArr []string for _, v := range arr { sArr = append(sArr, v+"d") sArr = append(sArr, v+"t") sArr = append(sArr, v+"p") } return sArr } func GetMactchKey(match []map[string]string, data map[string]interface{}) string { keyWord := []string{} for _, keys := range match { types := keys["s_keymatch"] key := keys["s_matchkey"] if strings.Contains(types, "1") { title := util.ObjToString(data["title"]) keyWord = KeyWordToData(types, title, key, keyWord) } if strings.Contains(types, "2") { detail := util.ObjToString(data["detail"]) keyWord = KeyWordToData(types, detail, key, keyWord) } if strings.Contains(types, "3") { purchasing := util.ObjToString(data["purchasing"]) keyWord = KeyWordToData(types, purchasing, key, keyWord) } if strings.Contains(types, "4") { filetext := util.ObjToString(data["filetext"]) keyWord = KeyWordToData(types, filetext, key, keyWord) } if strings.Contains(types, "5") { projectname := util.ObjToString(data["projectname"]) keyWord = KeyWordToData(types, projectname, key, keyWord) } if strings.Contains(types, "6") || strings.Contains(types, "8") { buyer := util.ObjToString(data["buyer"]) keyWord = KeyWordToData(types, buyer, key, keyWord) } if strings.Contains(types, "7") || strings.Contains(types, "9") { winner := util.ObjToString(data["s_winner"]) keyWord = KeyWordToData(types, winner, key, keyWord) } } keyMap := map[string]bool{} keyArr := []string{} for _, key := range keyWord { keyMap[key] = true } for k, _ := range keyMap { keyArr = append(keyArr, k) } return strings.Join(keyArr, ",") } func KeyWordToData(types, item, key string, keyWord []string) []string { for _, mk := range strings.Split(key, ",") { if strings.Contains(mk, "&&") { arr := strings.Split(mk, "&&") isok := true for _, s := range arr { if s != "" { if !strings.Contains(item, s) { isok = false } } } if isok { keyWord = append(keyWord, mk) } } else { if strings.Contains(item, mk) { keyWord = append(keyWord, mk) } } } return keyWord }