|
@@ -1,15 +1,9 @@
|
|
|
package front
|
|
|
|
|
|
import (
|
|
|
- util "app.yhyue.com/moapp/jybase/common"
|
|
|
- "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
- elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
- "app.yhyue.com/moapp/jybase/redis"
|
|
|
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/bidsearch"
|
|
|
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
- pc "app.yhyue.com/moapp/jypkg/public"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ "github.com/gogf/gf/v2/util/gconv"
|
|
|
"jy/src/jfw/config"
|
|
|
"jy/src/jfw/jyutil"
|
|
|
"log"
|
|
@@ -17,6 +11,14 @@ import (
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
+
|
|
|
+ util "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
+ "app.yhyue.com/moapp/jypkg/common/src/qfw/util/bidsearch"
|
|
|
+ "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
+ pc "app.yhyue.com/moapp/jypkg/public"
|
|
|
)
|
|
|
|
|
|
const (
|
|
@@ -303,13 +305,22 @@ func (so *SearchOptimize) GetBidSearchList(isCache bool) (count, total int64, li
|
|
|
fields := util.If(so.IsPay, BidSearchFieldOfVip, BidSearchFieldBase).(string)
|
|
|
esIndex := util.If(so.UserId == "", INDEXOther, INDEX).(string)
|
|
|
esType := util.If(so.UserId == "", TYPEOther, TYPE).(string)
|
|
|
+ Fields := ""
|
|
|
+ switch so.BidField {
|
|
|
+ case "BIProperty":
|
|
|
+ Fields = BidSearchFieldProperty
|
|
|
+ case "":
|
|
|
+ Fields = fields
|
|
|
+ default:
|
|
|
+ Fields = BidSearchDomainField
|
|
|
+ }
|
|
|
biddingSearch := SearchByES{
|
|
|
Index: esIndex,
|
|
|
IType: esType,
|
|
|
Query: so.GetSearchQuery(so.GetBidSearchQuery()),
|
|
|
FindFields: util.If(isCache, "title", "detail").(string),
|
|
|
Order: BidSearchSort,
|
|
|
- Fields: util.If(so.BidField != "", BidSearchDomainField, fields).(string), //BidField ===医疗领域化数据
|
|
|
+ Fields: Fields, //BidField ===医疗领域化数据
|
|
|
Start: util.If(isCache, 0, start).(int),
|
|
|
Limit: util.If(isCache, util.If(so.IsPay, bidsearch.SearchMaxPageCount_PAYED, bidsearch.SearchMaxPageCount_PC).(int), so.PageSize).(int), //缓存数据: 付费或未登录用户一次性5000条,100页数据;免费用户一次性500条,10页数据;实时数据:每页50条数据请求
|
|
|
Count: util.If(strings.Contains(so.SelectType, "detail"), 115, 0).(int), //高亮正文数量
|
|
@@ -406,6 +417,7 @@ func (so *SearchOptimize) GetSearchQuery(mustQuery string) (qstr string) {
|
|
|
findFields = fmt.Sprintf(`"%s"`, strings.Join(selectTypeArr, "\",\""))
|
|
|
}
|
|
|
switchBool := strings.Contains(findFields, "detail") && strings.Contains(findFields, "title") && so.SearchTypeSwitch
|
|
|
+
|
|
|
//此时关键词中间有+进行隔离
|
|
|
if so.KeyWords != "" {
|
|
|
var (
|
|
@@ -417,13 +429,13 @@ func (so *SearchOptimize) GetSearchQuery(mustQuery string) (qstr string) {
|
|
|
}
|
|
|
//单个字 搜索范围 有全文或者附件 无标题 例如:学 虚拟机 detail 搜索的时候加上标题
|
|
|
if len([]rune(elastic.ReplaceYH(v))) == 1 && bidsearch.DetailFileORTitle(findFields) {
|
|
|
- findFields += `, "title"`
|
|
|
+ findFields += `,"title"`
|
|
|
} else if switchBool && len([]rune(elastic.ReplaceYH(v))) > 1 {
|
|
|
//标题 全文搜索 搜索类型开关打开 默认搜索全文;(全文包含标题)(单字排除)
|
|
|
- if strings.Contains(findFields, `"title", `) {
|
|
|
- findFields = strings.Replace(findFields, `"title", `, ``, -1)
|
|
|
- } else if strings.Contains(findFields, `, "title"`) {
|
|
|
- findFields = strings.Replace(findFields, `, "title"`, ``, -1)
|
|
|
+ if strings.Contains(findFields, `"title",`) {
|
|
|
+ findFields = strings.Replace(findFields, `"title",`, ``, -1)
|
|
|
+ } else if strings.Contains(findFields, `,"title"`) {
|
|
|
+ findFields = strings.Replace(findFields, `,"title"`, ``, -1)
|
|
|
}
|
|
|
}
|
|
|
keyWordsMusts = append(keyWordsMusts, fmt.Sprintf(fmt.Sprintf(multiMatch, "%s", findFields), elastic.ReplaceYH(v)))
|
|
@@ -452,13 +464,13 @@ func (so *SearchOptimize) GetSearchQuery(mustQuery string) (qstr string) {
|
|
|
//单个字 搜索范围 有全文或者附件 无标题 例如:学 虚拟机 detail 搜索的时候加上标题
|
|
|
//detail 正文不支持单字查询
|
|
|
if len([]rune(elastic.ReplaceYH(v))) == 1 && bidsearch.DetailFileORTitle(findFields) {
|
|
|
- findFields += `, "title"`
|
|
|
+ findFields += `,"title"`
|
|
|
} else if switchBool && len([]rune(elastic.ReplaceYH(v))) > 1 {
|
|
|
//标题 全文搜索 搜索类型开关打开 默认搜索全文;(全文包含标题)(单字排除)
|
|
|
- if strings.Contains(findFields, `"title", `) {
|
|
|
- findFields = strings.Replace(findFields, `"title", `, ``, -1)
|
|
|
- } else if strings.Contains(findFields, `, "title"`) {
|
|
|
- findFields = strings.Replace(findFields, `, "title"`, ``, -1)
|
|
|
+ if strings.Contains(findFields, `"title",`) {
|
|
|
+ findFields = strings.Replace(findFields, `"title",`, ``, -1)
|
|
|
+ } else if strings.Contains(findFields, `,"title"`) {
|
|
|
+ findFields = strings.Replace(findFields, `,"title"`, ``, -1)
|
|
|
}
|
|
|
}
|
|
|
addWordsMust = append(addWordsMust, fmt.Sprintf(fmt.Sprintf(multiMatch, "%s", findFields), elastic.ReplaceYH(v)))
|
|
@@ -497,7 +509,7 @@ func (so *SearchOptimize) GetSearchQuery(mustQuery string) (qstr string) {
|
|
|
if len([]rune(elastic.ReplaceYH(v))) == 1 {
|
|
|
//单个字 搜索范围 有全文或者附件 无标题 例如:学 虚拟机 detail 搜索的时候加上标题
|
|
|
if bidsearch.DetailFileORTitle(findFields) {
|
|
|
- notKeyMultiMatch = fmt.Sprintf(multiMatch, "%s", findFields+`, "title"`)
|
|
|
+ notKeyMultiMatch = fmt.Sprintf(multiMatch, "%s", findFields+`,"title"`)
|
|
|
}
|
|
|
}
|
|
|
notKeyMustNot = append(notKeyMustNot, fmt.Sprintf(notKeyMultiMatch, elastic.ReplaceYH(v)))
|
|
@@ -507,31 +519,31 @@ func (so *SearchOptimize) GetSearchQuery(mustQuery string) (qstr string) {
|
|
|
}
|
|
|
//行业
|
|
|
if so.Industry != "" && isLogin {
|
|
|
- musts = append(musts, fmt.Sprintf(queryBoolMust, `"`+strings.ReplaceAll(so.Industry, ", ", `", "`)+`"`))
|
|
|
+ musts = append(musts, fmt.Sprintf(queryBoolMust, `"`+strings.ReplaceAll(so.Industry, ",", `","`)+`"`))
|
|
|
+ }
|
|
|
+ if so.BidField == "BIProperty" {
|
|
|
+ musts = append(musts, fmt.Sprintf(queryBoolMustA, "tag_topinformation", `"情报_物业"`))
|
|
|
+ }
|
|
|
+ //物业业态
|
|
|
+ if so.PropertyForm != "" && isLogin {
|
|
|
+ musts = append(musts, fmt.Sprintf(queryBoolMustA, "property form", `"`+strings.ReplaceAll(so.PropertyForm, ", ", `", "`)+`"`))
|
|
|
+ }
|
|
|
+ //业务类型
|
|
|
+ if so.Subinformation != "" && isLogin {
|
|
|
+ musts = append(musts, fmt.Sprintf(queryBoolMustA, "tag_subinformation", `"`+strings.ReplaceAll(so.Subinformation, ", ", `", "`)+`"`))
|
|
|
+ }
|
|
|
+ //价格区间
|
|
|
+ if so.Scale != 0 && isLogin {
|
|
|
+ musts = append(musts, fmt.Sprintf(queryBoolMustA, "tag_set.wuye.scale", `"`+gconv.String(so.Scale)+`"`))
|
|
|
+ }
|
|
|
+ //合同周期
|
|
|
+ if so.Period != 0 && isLogin {
|
|
|
+ musts = append(musts, fmt.Sprintf(queryBoolMustA, "tag_set.wuye.period", `"`+gconv.String(so.Period)+`"`))
|
|
|
+ }
|
|
|
+ //换手率
|
|
|
+ if so.Changehand != 0 && isLogin {
|
|
|
+ musts = append(musts, fmt.Sprintf(queryBoolMustA, "tag_set.wuye.changehand", `"`+gconv.String(so.Changehand)+`"`))
|
|
|
}
|
|
|
- /*if so.BidField == "BIProperty" {
|
|
|
- musts = append(musts, fmt.Sprintf(queryBoolMustA, "tag_topinformation", `"情报_物业"`))
|
|
|
- }
|
|
|
- //物业业态
|
|
|
- if so.PropertyForm != "" && isLogin {
|
|
|
- musts = append(musts, fmt.Sprintf(queryBoolMustA, "property form", `"`+strings.ReplaceAll(so.PropertyForm, ", ", `", "`)+`"`))
|
|
|
- }
|
|
|
- //业务类型
|
|
|
- if so.Subinformation != "" && isLogin {
|
|
|
- musts = append(musts, fmt.Sprintf(queryBoolMustA, "tag_subinformation", `"`+strings.ReplaceAll(so.Subinformation, ", ", `", "`)+`"`))
|
|
|
- }
|
|
|
- //价格区间
|
|
|
- if so.Scale != 0 && isLogin {
|
|
|
- musts = append(musts, fmt.Sprintf(queryBoolMustA, "tag_set.wuye.scale", `"`+gconv.String(so.Scale)+`"`))
|
|
|
- }
|
|
|
- //合同周期
|
|
|
- if so.Period != 0 && isLogin {
|
|
|
- musts = append(musts, fmt.Sprintf(queryBoolMustA, "tag_set.wuye.period", `"`+gconv.String(so.Period)+`"`))
|
|
|
- }
|
|
|
- //换手率
|
|
|
- if so.Changehand != 0 && isLogin {
|
|
|
- musts = append(musts, fmt.Sprintf(queryBoolMustA, "tag_set.wuye.changehand", `"`+gconv.String(so.Changehand)+`"`))
|
|
|
- }*/
|
|
|
//价格
|
|
|
if so.Price != "" && len(strings.Split(so.Price, "-")) > 1 && isLogin {
|
|
|
minPrice, maxPrice := strings.Split(so.Price, "-")[0], strings.Split(so.Price, "-")[1]
|
|
@@ -555,7 +567,7 @@ func (so *SearchOptimize) GetSearchQuery(mustQuery string) (qstr string) {
|
|
|
sq += fmt.Sprintf(gte, minPrice)
|
|
|
}
|
|
|
if minPrice != "" && maxPrice != "" {
|
|
|
- sq += `, `
|
|
|
+ sq += `,`
|
|
|
}
|
|
|
if maxPrice != "" {
|
|
|
sq += fmt.Sprintf(lte, maxPrice)
|
|
@@ -608,18 +620,14 @@ func (so *SearchOptimize) GetBidSearchQuery() string {
|
|
|
area := so.Province
|
|
|
isLogin := so.UserId != ""
|
|
|
if area != "" && isLogin {
|
|
|
- query += `{
|
|
|
- "terms":{
|
|
|
- "area":[`
|
|
|
+ query += `{"terms":{"area":[`
|
|
|
for k, v := range strings.Split(area, ",") {
|
|
|
if k > 0 {
|
|
|
- query += `, `
|
|
|
+ query += `,`
|
|
|
}
|
|
|
query += `"` + v + `"`
|
|
|
}
|
|
|
- query += `]
|
|
|
-}
|
|
|
-}`
|
|
|
+ query += `]}}`
|
|
|
}
|
|
|
//市
|
|
|
city := so.City
|
|
@@ -627,18 +635,14 @@ func (so *SearchOptimize) GetBidSearchQuery() string {
|
|
|
if len(query) > 0 {
|
|
|
query += ","
|
|
|
}
|
|
|
- query += `{
|
|
|
- "terms":{
|
|
|
- "city":[`
|
|
|
+ query += `{"terms":{"city":[`
|
|
|
for k, v := range strings.Split(city, ",") {
|
|
|
if k > 0 {
|
|
|
- query += `, `
|
|
|
+ query += `,`
|
|
|
}
|
|
|
query += `"` + v + `"`
|
|
|
}
|
|
|
- query += `]
|
|
|
-}
|
|
|
-}`
|
|
|
+ query += `]}}`
|
|
|
}
|
|
|
//区域处理
|
|
|
district := so.District
|
|
@@ -648,23 +652,11 @@ func (so *SearchOptimize) GetBidSearchQuery() string {
|
|
|
}
|
|
|
for k, v := range strings.Split(district, ",") {
|
|
|
if k > 0 {
|
|
|
- query += `, `
|
|
|
+ query += `,`
|
|
|
}
|
|
|
cityName := strings.Split(v, "_")[0]
|
|
|
districtName := strings.Split(v, "_")[1]
|
|
|
- query_bool_must_and_district := `{
|
|
|
- "bool":{
|
|
|
- "must":[{
|
|
|
- "terms":{
|
|
|
- "city":["%s"]
|
|
|
- }
|
|
|
- }, {
|
|
|
- "terms":{
|
|
|
- "district":["%s"]
|
|
|
- }
|
|
|
- }]
|
|
|
- }
|
|
|
- }`
|
|
|
+ query_bool_must_and_district := `{"bool":{"must":[{"terms":{"city":["%s"]}},{"terms":{"district":["%s"]}}]}}`
|
|
|
query += fmt.Sprintf(query_bool_must_and_district, cityName, districtName)
|
|
|
}
|
|
|
|
|
@@ -703,23 +695,17 @@ func (so *SearchOptimize) GetBidSearchQuery() string {
|
|
|
}
|
|
|
endTime = fmt.Sprint(time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local).Unix())
|
|
|
}
|
|
|
- query += `{
|
|
|
- "range":{
|
|
|
- "publishtime":{
|
|
|
-`
|
|
|
+ query += `{"range":{"publishtime":{`
|
|
|
if startTime != "" {
|
|
|
query += `"gte":` + startTime
|
|
|
}
|
|
|
if startTime != "" && endTime != "" {
|
|
|
- query += `, `
|
|
|
+ query += `,`
|
|
|
}
|
|
|
if endTime != "" {
|
|
|
query += `"lt":` + endTime
|
|
|
}
|
|
|
- query += `
|
|
|
-}
|
|
|
-}
|
|
|
-}`
|
|
|
+ query += `}}}`
|
|
|
}
|
|
|
//信息类型-二级
|
|
|
subtype := so.Subtype
|
|
@@ -728,9 +714,7 @@ func (so *SearchOptimize) GetBidSearchQuery() string {
|
|
|
//二级分类
|
|
|
if subtype != "" {
|
|
|
var typeInt = 0
|
|
|
- allType += `{
|
|
|
- "terms":{
|
|
|
- "subtype":[`
|
|
|
+ allType += `{"terms":{"subtype":[`
|
|
|
for k, v := range strings.Split(subtype, ",") {
|
|
|
if tType := util.If(topTypeMap[v] != "" && so.TopType == "", topTypeMap[v], "").(string); tType != "" {
|
|
|
topType = append(topType, tType)
|
|
@@ -738,13 +722,11 @@ func (so *SearchOptimize) GetBidSearchQuery() string {
|
|
|
continue
|
|
|
}
|
|
|
if k > typeInt {
|
|
|
- allType += `, `
|
|
|
+ allType += `,`
|
|
|
}
|
|
|
allType += `"` + v + `"`
|
|
|
}
|
|
|
- allType += `]
|
|
|
-}
|
|
|
-}`
|
|
|
+ allType += `]}}`
|
|
|
//subtype里都是一级信息类型
|
|
|
if typeInt == len(strings.Split(subtype, ",")) {
|
|
|
allType = ``
|
|
@@ -756,18 +738,14 @@ func (so *SearchOptimize) GetBidSearchQuery() string {
|
|
|
if allType != "" {
|
|
|
allType += ","
|
|
|
}
|
|
|
- allType += `{
|
|
|
- "terms":{
|
|
|
- "toptype":[`
|
|
|
+ allType += `{"terms":{"toptype":[`
|
|
|
for k, v := range topType {
|
|
|
if k > 0 {
|
|
|
- allType += `, `
|
|
|
+ allType += `,`
|
|
|
}
|
|
|
allType += `"` + v + `"`
|
|
|
}
|
|
|
- allType += `]
|
|
|
-}
|
|
|
-}`
|
|
|
+ allType += `]}}`
|
|
|
}
|
|
|
|
|
|
if allType != "" {
|
|
@@ -781,18 +759,14 @@ func (so *SearchOptimize) GetBidSearchQuery() string {
|
|
|
if len(query) > 0 {
|
|
|
query += ","
|
|
|
}
|
|
|
- query += `{
|
|
|
- "terms":{
|
|
|
- "buyerclass":[`
|
|
|
+ query += `{"terms":{"buyerclass":[`
|
|
|
for k, v := range strings.Split(so.BuyerClass, ",") {
|
|
|
if k > 0 {
|
|
|
- query += `, `
|
|
|
+ query += `,`
|
|
|
}
|
|
|
query += `"` + v + `"`
|
|
|
}
|
|
|
- query += `]
|
|
|
-}
|
|
|
-}`
|
|
|
+ query += `]}}`
|
|
|
}
|
|
|
return query
|
|
|
}
|
|
@@ -890,23 +864,16 @@ func (e *SearchByES) GetAllByNgramWithCount() (int64, *[]map[string]interface{})
|
|
|
for _, w := range strings.Split(e.FindFields, ",") {
|
|
|
ws = append(ws, fmt.Sprintf(HighlightStr, w, e.Count))
|
|
|
}
|
|
|
- queryStr = queryStr[:len(queryStr)-1] + `, ` + fmt.Sprintf(HL, strings.Join(ws, ",")) + `
|
|
|
-}
|
|
|
-`
|
|
|
+ queryStr = queryStr[:len(queryStr)-1] + `,` + fmt.Sprintf(HL, strings.Join(ws, ",")) + `}`
|
|
|
}
|
|
|
- log.Println(len(queryStr))
|
|
|
- log.Println(111, queryStr)
|
|
|
- log.Println(11333)
|
|
|
- log.Println(222, queryStr[:len(queryStr)-1])
|
|
|
- log.Println(11333222)
|
|
|
if len(e.Fields) > 0 {
|
|
|
- queryStr = queryStr[:len(queryStr)-1] + `, "_source":[` + e.Fields + "]}"
|
|
|
+ queryStr = queryStr[:len(queryStr)-1] + `,"_source":[` + e.Fields + "]}"
|
|
|
}
|
|
|
if len(e.Order) > 0 {
|
|
|
- queryStr = queryStr[:len(queryStr)-1] + `, "sort":[` + SR(SR(SR(SR(e.Order, ",", "},{", -1), " ", "", -1), ":-1", `:"desc"`, -1), ":1", `:"asc"`, -1) + `]}`
|
|
|
+ queryStr = queryStr[:len(queryStr)-1] + `,"sort":[` + SR(SR(SR(SR(e.Order, ",", "},{", -1), " ", "", -1), ":-1", `:"desc"`, -1), ":1", `:"asc"`, -1) + `]}`
|
|
|
}
|
|
|
if e.Start > -1 {
|
|
|
- queryStr = queryStr[:len(queryStr)-1] + `,"from":` + strconv.Itoa(e.Start) + `, "size":` + strconv.Itoa(e.Limit) + "}"
|
|
|
+ queryStr = queryStr[:len(queryStr)-1] + `,"from":` + strconv.Itoa(e.Start) + `,"size":` + strconv.Itoa(e.Limit) + "}"
|
|
|
}
|
|
|
log.Println(e.Index, e.IType, "--queryStr:", queryStr)
|
|
|
//if e.IsLogin {
|