|
@@ -35,7 +35,7 @@ const (
|
|
)
|
|
)
|
|
|
|
|
|
//GetWxsearchlistData 移动端招标信息搜索
|
|
//GetWxsearchlistData 移动端招标信息搜索
|
|
-func GetWxsearchlistData(keywords, scope, city, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel, fileExists string, pageNum, pageSize int, selectTypeArr []string, field, notkey string) (list *[]map[string]interface{}, b_word, a_word, s_word string) {
|
|
|
|
|
|
+func GetWxsearchlistData(keywords, scope, city, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel, fileExists string, pageNum, pageSize int, selectTypeArr []string, field, notkey string, searchTypeSwitch bool) (list *[]map[string]interface{}, b_word, a_word, s_word string) {
|
|
var hightlightContent bool = false //是否高亮正文
|
|
var hightlightContent bool = false //是否高亮正文
|
|
for _, v := range selectTypeArr {
|
|
for _, v := range selectTypeArr {
|
|
if v == "detail" {
|
|
if v == "detail" {
|
|
@@ -53,7 +53,7 @@ func GetWxsearchlistData(keywords, scope, city, publishtime, subtype, industry,
|
|
} else {
|
|
} else {
|
|
findfields = fmt.Sprintf(`"%s"`, strings.Join(selectTypeArr, "\",\""))
|
|
findfields = fmt.Sprintf(`"%s"`, strings.Join(selectTypeArr, "\",\""))
|
|
}
|
|
}
|
|
- qstr := GetSearchQuery(s_word, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, fileExists, findfields, GetBidSearchQuery(scope, city, publishtime, subtype, winner, buyerclass), notkey)
|
|
|
|
|
|
+ qstr := GetSearchQuery(s_word, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, fileExists, findfields, GetBidSearchQuery(scope, city, publishtime, subtype, winner, buyerclass), notkey, searchTypeSwitch)
|
|
if hightlightContent { //全文搜索
|
|
if hightlightContent { //全文搜索
|
|
list = elastic.GetAllByNgram(INDEX, TYPE, qstr, `"detail"`, bidSearch_sort, field, (pageNum-1)*pageSize, pageSize, 100, true)
|
|
list = elastic.GetAllByNgram(INDEX, TYPE, qstr, `"detail"`, bidSearch_sort, field, (pageNum-1)*pageSize, pageSize, 100, true)
|
|
} else { //标题搜索
|
|
} else { //标题搜索
|
|
@@ -69,7 +69,7 @@ func GetWxsearchlistData(keywords, scope, city, publishtime, subtype, industry,
|
|
}
|
|
}
|
|
|
|
|
|
//GetPcBidSearchData pc端招标信息搜索
|
|
//GetPcBidSearchData pc端招标信息搜索
|
|
-func GetPcBidSearchData(searchvalue, area, city, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel, fileExists string, start, pageSize int, isGetCount bool, selectTypeArr []string, field, notkey string, ispayed bool) (count, totalPage int64, list *[]map[string]interface{}) {
|
|
|
|
|
|
+func GetPcBidSearchData(searchvalue, area, city, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel, fileExists string, start, pageSize int, isGetCount bool, selectTypeArr []string, field, notkey string, ispayed, searchTypeSwitch bool) (count, totalPage int64, list *[]map[string]interface{}) {
|
|
var findfields string
|
|
var findfields string
|
|
var hightlightContent bool = false //是否高亮正文
|
|
var hightlightContent bool = false //是否高亮正文
|
|
for _, v := range selectTypeArr {
|
|
for _, v := range selectTypeArr {
|
|
@@ -83,11 +83,10 @@ func GetPcBidSearchData(searchvalue, area, city, publishtime, subtype, industry,
|
|
} else {
|
|
} else {
|
|
findfields = fmt.Sprintf(`"%s"`, strings.Join(selectTypeArr, "\",\""))
|
|
findfields = fmt.Sprintf(`"%s"`, strings.Join(selectTypeArr, "\",\""))
|
|
}
|
|
}
|
|
- qstr := GetSearchQuery(searchvalue, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, fileExists, findfields, GetBidSearchQuery(area, city, publishtime, subtype, winner, buyerclass), notkey)
|
|
|
|
|
|
+ qstr := GetSearchQuery(searchvalue, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, fileExists, findfields, GetBidSearchQuery(area, city, publishtime, subtype, winner, buyerclass), notkey, searchTypeSwitch)
|
|
if isGetCount && qstr != "" && start == 0 {
|
|
if isGetCount && qstr != "" && start == 0 {
|
|
count = elastic.Count(INDEX, TYPE, qstr)
|
|
count = elastic.Count(INDEX, TYPE, qstr)
|
|
}
|
|
}
|
|
- log.Println("field:", field)
|
|
|
|
if !isGetCount || count > 0 || start > 0 {
|
|
if !isGetCount || count > 0 || start > 0 {
|
|
var repl *[]map[string]interface{}
|
|
var repl *[]map[string]interface{}
|
|
if hightlightContent {
|
|
if hightlightContent {
|
|
@@ -238,27 +237,55 @@ func GetBidSearchQuery(area, city, publishtime, subtype, winner, buyerclass stri
|
|
return query
|
|
return query
|
|
}
|
|
}
|
|
|
|
|
|
-func GetSearchQuery(keyword, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, fileExists, findfields, mustquery, notkey string) (qstr string) {
|
|
|
|
|
|
+//包含正文或 附件 不包含标题
|
|
|
|
+func DetailFileORTitle(findfields string) bool {
|
|
|
|
+ return (strings.Contains(findfields, `"detail"`) || strings.Contains(findfields, `"filetext"`)) && !strings.Contains(findfields, `"title"`)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//包含标题和正文
|
|
|
|
+func DetailTitle(findfields string) bool {
|
|
|
|
+ return strings.Contains(findfields, `"detail"`) && strings.Contains(findfields, `"title"`)
|
|
|
|
+}
|
|
|
|
+func GetSearchQuery(keyword, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, fileExists, findfields, mustquery, notkey string, searchTypeSwitch bool) (qstr string) {
|
|
multi_match := `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
|
|
multi_match := `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
|
|
query := `{"query":{"bool":{"must":[%s],"must_not":[%s]}}}`
|
|
query := `{"query":{"bool":{"must":[%s],"must_not":[%s]}}}`
|
|
query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
|
|
query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
|
|
query_bools_must := `{"bool":{"must":[{"range":{"bidamount":{%s}}}]}},{"bool":{"must":[{"range":{"budget":{%s}}}],"must_not":[{"range":{"bidamount":{"gte":-1}}}]}}`
|
|
query_bools_must := `{"bool":{"must":[{"range":{"bidamount":{%s}}}]}},{"bool":{"must":[{"range":{"budget":{%s}}}],"must_not":[{"range":{"bidamount":{"gte":-1}}}]}}`
|
|
query_bool_must := `{"bool":{"must":[{"terms":{"s_subscopeclass":[%s]}}]}}`
|
|
query_bool_must := `{"bool":{"must":[{"terms":{"s_subscopeclass":[%s]}}]}}`
|
|
query_missing := `{"constant_score":{"filter":{"missing":{"field":"%s"}}}}`
|
|
query_missing := `{"constant_score":{"filter":{"missing":{"field":"%s"}}}}`
|
|
|
|
+ query_bool_must_term := `{"bool": {"must": [{ "term": {"isValidFile": %d }}]}}`
|
|
gte := `"gte": %s`
|
|
gte := `"gte": %s`
|
|
lte := `"lte": %s`
|
|
lte := `"lte": %s`
|
|
musts, must_not := []string{}, []string{}
|
|
musts, must_not := []string{}, []string{}
|
|
if mustquery != "" {
|
|
if mustquery != "" {
|
|
musts = append(musts, mustquery)
|
|
musts = append(musts, mustquery)
|
|
}
|
|
}
|
|
-
|
|
|
|
//搜索范围是否只有附件
|
|
//搜索范围是否只有附件
|
|
//搜索范围只选择附件,是否有附件条件无效;
|
|
//搜索范围只选择附件,是否有附件条件无效;
|
|
- var isFileSearch bool = findfields == "filetext"
|
|
|
|
|
|
+ var isFileSearch bool = findfields == `"filetext"`
|
|
if keyword != "" {
|
|
if keyword != "" {
|
|
keyword_multi_match := fmt.Sprintf(multi_match, "%s", findfields)
|
|
keyword_multi_match := fmt.Sprintf(multi_match, "%s", findfields)
|
|
shoulds := []string{}
|
|
shoulds := []string{}
|
|
for _, v := range strings.Split(keyword, "+") {
|
|
for _, v := range strings.Split(keyword, "+") {
|
|
|
|
+ if elastic.ReplaceYH(v) == "" {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if len([]rune(elastic.ReplaceYH(v))) == 1 {
|
|
|
|
+ //单个字 搜索范围 有全文或者附件 无标题 例如:学 虚拟机 detail 搜索的时候加上标题
|
|
|
|
+ if DetailFileORTitle(findfields) {
|
|
|
|
+ keyword_multi_match = fmt.Sprintf(multi_match, "%s", findfields+`,"title"`)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //标题+全文搜索 搜索类型开关打开 默认搜索全文;(全文包含标题)(单字排除)
|
|
|
|
+ if searchTypeSwitch && DetailTitle(findfields) {
|
|
|
|
+ if strings.Contains(findfields, `"title",`) {
|
|
|
|
+ findfields = strings.Replace(findfields, `"title",`, ``, -1)
|
|
|
|
+ } else if strings.Contains(findfields, `,"title"`) {
|
|
|
|
+ findfields = strings.Replace(findfields, `,"title"`, ``, -1)
|
|
|
|
+ }
|
|
|
|
+ keyword_multi_match = fmt.Sprintf(multi_match, "%s", findfields)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
shoulds = append(shoulds, fmt.Sprintf(keyword_multi_match, elastic.ReplaceYH(v)))
|
|
shoulds = append(shoulds, fmt.Sprintf(keyword_multi_match, elastic.ReplaceYH(v)))
|
|
}
|
|
}
|
|
musts = append(musts, fmt.Sprintf(elastic.NgramMust, strings.Join(shoulds, ",")))
|
|
musts = append(musts, fmt.Sprintf(elastic.NgramMust, strings.Join(shoulds, ",")))
|
|
@@ -319,15 +346,22 @@ func GetSearchQuery(keyword, industry, minprice, maxprice, hasBuyerTel, hasWinne
|
|
if v == "" {
|
|
if v == "" {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
+ if len([]rune(elastic.ReplaceYH(v))) == 1 {
|
|
|
|
+ //单个字 搜索范围 有全文或者附件 无标题 例如:学 虚拟机 detail 搜索的时候加上标题
|
|
|
|
+ if DetailFileORTitle(findfields) {
|
|
|
|
+ notkey_multi_match = fmt.Sprintf(multi_match, "%s", findfields+`,"title"`)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
notkey_must_not = append(notkey_must_not, fmt.Sprintf(notkey_multi_match, elastic.ReplaceYH(v)))
|
|
notkey_must_not = append(notkey_must_not, fmt.Sprintf(notkey_multi_match, elastic.ReplaceYH(v)))
|
|
}
|
|
}
|
|
must_not = append(must_not, fmt.Sprintf(query_bool_should, strings.Join(notkey_must_not, ",")))
|
|
must_not = append(must_not, fmt.Sprintf(query_bool_should, strings.Join(notkey_must_not, ",")))
|
|
}
|
|
}
|
|
if !isFileSearch && fileExists != "" {
|
|
if !isFileSearch && fileExists != "" {
|
|
if fileExists == "1" { //有附件
|
|
if fileExists == "1" { //有附件
|
|
- must_not = append(must_not, fmt.Sprintf(query_missing, "filetext"))
|
|
|
|
|
|
+ must_not = append(must_not, fmt.Sprintf(query_missing, "isValidFile"))
|
|
|
|
+ musts = append(musts, fmt.Sprintf(query_bool_must_term, 1))
|
|
} else if fileExists == "-1" { //无附件
|
|
} else if fileExists == "-1" { //无附件
|
|
- musts = append(musts, fmt.Sprintf(query_missing, "filetext"))
|
|
|
|
|
|
+ musts = append(musts, fmt.Sprintf(query_missing, "isValidFile"))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
qstr = fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(must_not, ","))
|
|
qstr = fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(must_not, ","))
|
|
@@ -368,12 +402,12 @@ func PublicSearch(userId, selectType, publishtime string, bidSearchOldUserLimit
|
|
}
|
|
}
|
|
|
|
|
|
//所有的再次分词查询 只查标题
|
|
//所有的再次分词查询 只查标题
|
|
-func IntegratedData(platform string, s_word, secondKWS, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, fileExists, secondFlag, area, city, publishtime, subtype, buyerclass, notkey string, queryItems []string, list *[]map[string]interface{}, field string) (string, string, string, string, *[]map[string]interface{}) {
|
|
|
|
|
|
+func IntegratedData(platform string, s_word, secondKWS, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, fileExists, secondFlag, area, city, publishtime, subtype, buyerclass, notkey string, queryItems []string, list *[]map[string]interface{}, field string, searchTypeSwitch bool) (string, string, string, string, *[]map[string]interface{}) {
|
|
var pcAjaxFlag string
|
|
var pcAjaxFlag string
|
|
var secRel *[]map[string]interface{} = list
|
|
var secRel *[]map[string]interface{} = list
|
|
if secondKWS = jy.HttpEs(s_word, "ik_smart", public.DbConf.Elasticsearch.Main.Address); secondKWS != "" {
|
|
if secondKWS = jy.HttpEs(s_word, "ik_smart", public.DbConf.Elasticsearch.Main.Address); secondKWS != "" {
|
|
findfields := `"title"`
|
|
findfields := `"title"`
|
|
- qstr := GetSearchQuery(secondKWS, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, fileExists, findfields, GetBidSearchQuery(area, city, publishtime, subtype, "", buyerclass), notkey)
|
|
|
|
|
|
+ qstr := GetSearchQuery(secondKWS, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, fileExists, findfields, GetBidSearchQuery(area, city, publishtime, subtype, "", buyerclass), notkey, searchTypeSwitch)
|
|
secRel = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, field, 0, 2*SearchPageSize_PC, 0, false)
|
|
secRel = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, field, 0, 2*SearchPageSize_PC, 0, false)
|
|
if secRel != nil && len(*secRel) > 0 {
|
|
if secRel != nil && len(*secRel) > 0 {
|
|
public.BidListConvert(industry, secRel)
|
|
public.BidListConvert(industry, secRel)
|
|
@@ -457,7 +491,7 @@ func LisetData(stype, pageNum int, list *[]map[string]interface{}, secondFlag st
|
|
}
|
|
}
|
|
v["detail"] = detail
|
|
v["detail"] = detail
|
|
v["href"] = util.EncodeArticleId2ByCheck(util.GetRandom(20))
|
|
v["href"] = util.EncodeArticleId2ByCheck(util.GetRandom(20))
|
|
- if v["filetext"] != nil {
|
|
|
|
|
|
+ if isValidFile, _ := v["isValidFile"].(bool); isValidFile {
|
|
delete(v, "filetext")
|
|
delete(v, "filetext")
|
|
v["fileExists"] = true
|
|
v["fileExists"] = true
|
|
}
|
|
}
|
|
@@ -491,33 +525,20 @@ func LisetData(stype, pageNum int, list *[]map[string]interface{}, secondFlag st
|
|
func SearchData(platform string, request *http.Request, currentPage int, userId, secondKWS, s_word, area, city, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel, fileExists string, start, pageSize int, isGetCount bool, queryItems []string, field, notkey string, isPayedUser, searchTypeSwitch bool) (second, b_word, a_word, pcAjaxFlag, secondFlag string, count, totalPage int64, list *[]map[string]interface{}) {
|
|
func SearchData(platform string, request *http.Request, currentPage int, userId, secondKWS, s_word, area, city, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel, fileExists string, start, pageSize int, isGetCount bool, queryItems []string, field, notkey string, isPayedUser, searchTypeSwitch bool) (second, b_word, a_word, pcAjaxFlag, secondFlag string, count, totalPage int64, list *[]map[string]interface{}) {
|
|
//包含标题才能进行二次搜索
|
|
//包含标题才能进行二次搜索
|
|
var secondSearch = strings.Contains(strings.Join(queryItems, ","), "title")
|
|
var secondSearch = strings.Contains(strings.Join(queryItems, ","), "title")
|
|
- //标题 全文搜索 搜索类型开关打开 默认搜索全文;(全文包含标题)(单字排除)
|
|
|
|
- if searchTypeSwitch {
|
|
|
|
- findFields := strings.Join(queryItems, ",")
|
|
|
|
- var switchBool = strings.Contains(findFields, "detail") && strings.Contains(findFields, "title")
|
|
|
|
- if switchBool {
|
|
|
|
- if strings.Contains(findFields, "title,") {
|
|
|
|
- findFields = strings.Replace(findFields, "title,", "", -1)
|
|
|
|
- } else if strings.Contains(findFields, `,title`) {
|
|
|
|
- findFields = strings.Replace(findFields, ",title", "", -1)
|
|
|
|
- }
|
|
|
|
- queryItems = strings.Split(findFields, ",")
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
var searchvalue = s_word
|
|
var searchvalue = s_word
|
|
number := util.If(platform == "app" || platform == "wx", 1, 0)
|
|
number := util.If(platform == "app" || platform == "wx", 1, 0)
|
|
if platform == "app" || platform == "wx" {
|
|
if platform == "app" || platform == "wx" {
|
|
- list, b_word, a_word, s_word = GetWxsearchlistData(s_word, area, city, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel, fileExists, start, SearchPageSize_APP, queryItems, field, notkey)
|
|
|
|
|
|
+ list, b_word, a_word, s_word = GetWxsearchlistData(s_word, area, city, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel, fileExists, start, SearchPageSize_APP, queryItems, field, notkey, searchTypeSwitch)
|
|
if list != nil && len(*list) != 0 {
|
|
if list != nil && len(*list) != 0 {
|
|
count = int64(len(*list))
|
|
count = int64(len(*list))
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- count, totalPage, list = GetPcBidSearchData(s_word, area, city, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel, fileExists, start, pageSize, isGetCount, queryItems, field, notkey, isPayedUser)
|
|
|
|
|
|
+ count, totalPage, list = GetPcBidSearchData(s_word, area, city, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel, fileExists, start, pageSize, isGetCount, queryItems, field, notkey, isPayedUser, searchTypeSwitch)
|
|
}
|
|
}
|
|
|
|
|
|
if len([]rune(s_word)) > 3 && int(count) < SearchPageSize_PC && start == number && secondSearch {
|
|
if len([]rune(s_word)) > 3 && int(count) < SearchPageSize_PC && start == number && secondSearch {
|
|
var paramList = list
|
|
var paramList = list
|
|
- s_word, pcAjaxFlag, secondFlag, second, list = IntegratedData(platform, s_word, secondKWS, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, fileExists, secondFlag, area, city, publishtime, subtype, buyerclass, notkey, queryItems, paramList, field)
|
|
|
|
|
|
+ s_word, pcAjaxFlag, secondFlag, second, list = IntegratedData(platform, s_word, secondKWS, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, fileExists, secondFlag, area, city, publishtime, subtype, buyerclass, notkey, queryItems, paramList, field, searchTypeSwitch)
|
|
}
|
|
}
|
|
|
|
|
|
listSize := 0
|
|
listSize := 0
|