|
@@ -1,6 +1,13 @@
|
|
|
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"
|
|
|
"jy/src/jfw/config"
|
|
@@ -10,14 +17,6 @@ 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 (
|
|
@@ -26,6 +25,7 @@ const (
|
|
|
queryBoolShould = `{"bool":{"should":[%s],"minimum_should_match": 1}}`
|
|
|
queryBoolMustBoolShould = `{"bool":{"must":[{"range":{"bidamount":{%s}}}]}},{"bool":{"must":[{"range":{"budget":{%s}}}],"must_not":[{"range":{"bidamount":{"gte":-1}}}]}}`
|
|
|
queryBoolMust = `{"bool":{"must":[{"terms":{"s_subscopeclass":[%s]}}]}}`
|
|
|
+ queryBoolMustA = `{"bool":{"must":[{"terms":{"%s":[%s]}}]}}`
|
|
|
queryBoolMustTerm = `{"bool": {"must": [{ "term": {"isValidFile": %t }}]}}`
|
|
|
queryExists = `{"constant_score":{"filter":{"exists":{"field":"%s"}}}}`
|
|
|
gte = `"gte": %s`
|
|
@@ -85,13 +85,21 @@ type SearchOptimize struct {
|
|
|
VipStatus int `json:"vipStatus"`
|
|
|
BigMemberStatus int `json:"bigMemberStatus"`
|
|
|
EntStatus int `json:"entStatus"`
|
|
|
- HeightKeys string `json:"heightKeys"` //需要高亮的关键词
|
|
|
- R *http.Request `json:"r"` //http.request
|
|
|
- District string `json:"district"` //需要高亮的关键词
|
|
|
+ HeightKeys string `json:"heightKeys"` //需要高亮的关键词
|
|
|
+ R *http.Request `json:"r"` //http.request
|
|
|
+ District string `json:"district"` //需要高亮的关键词
|
|
|
+ PropertyForm string `json:"propertyForm"` //物业业态
|
|
|
+ ExpireTime string `json:"expireTime"` //到期时间
|
|
|
+ Subinformation string `json:"subinformation"` //业务类型
|
|
|
+ Period int `json:"period"` //合同周期
|
|
|
+ Changehand int `json:"changehand"` //价格区间
|
|
|
+ Scale int `json:"scale"` //换手率
|
|
|
}
|
|
|
|
|
|
// NewSearchOptimize 初始化
|
|
|
-func NewSearchOptimize(userId, phone, province, city, district, subtype, topType, publishTime, selectType, price, industry, buyerClass, buyerTel, winnerTel, fileExists, keyWords, additionalWords, exclusionWords, platform, territorialization string, pageNum, pageSize, searchGroup, searchMode, wordsMode int, userInfo jy.VipState, searchTypeSwitch bool, r *http.Request) *SearchOptimize {
|
|
|
+func NewSearchOptimize(userId, phone, province, city, district, subtype, topType, publishTime, selectType, price, industry, buyerClass, buyerTel, winnerTel, fileExists, keyWords, additionalWords, exclusionWords, platform, territorialization, expireTime, propertyForm, subinformation string,
|
|
|
+ pageNum, pageSize, searchGroup, searchMode, wordsMode, period, scale, changehand int,
|
|
|
+ userInfo jy.VipState, searchTypeSwitch bool, r *http.Request) *SearchOptimize {
|
|
|
var so = &SearchOptimize{
|
|
|
AppId: "10000",
|
|
|
UserId: userId,
|
|
@@ -126,6 +134,12 @@ func NewSearchOptimize(userId, phone, province, city, district, subtype, topType
|
|
|
EntStatus: userInfo.EntMember,
|
|
|
R: r,
|
|
|
District: district,
|
|
|
+ PropertyForm: propertyForm,
|
|
|
+ ExpireTime: expireTime,
|
|
|
+ Subinformation: subinformation,
|
|
|
+ Period: period,
|
|
|
+ Changehand: changehand,
|
|
|
+ Scale: scale,
|
|
|
}
|
|
|
so.SearchParamsHandle()
|
|
|
return so
|
|
@@ -392,7 +406,6 @@ 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 (
|
|
@@ -404,13 +417,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)))
|
|
@@ -439,13 +452,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)))
|
|
@@ -484,7 +497,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)))
|
|
@@ -494,8 +507,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.Price != "" && len(strings.Split(so.Price, "-")) > 1 && isLogin {
|
|
|
minPrice, maxPrice := strings.Split(so.Price, "-")[0], strings.Split(so.Price, "-")[1]
|
|
@@ -519,7 +555,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)
|
|
@@ -557,7 +593,7 @@ func (so *SearchOptimize) GetSearchQuery(mustQuery string) (qstr string) {
|
|
|
}
|
|
|
}
|
|
|
// 如果是领域化数据则需要加标签
|
|
|
- if so.BidField != "" {
|
|
|
+ if so.BidField != "" && so.BidField != "BIProperty" {
|
|
|
musts = append(musts, fmt.Sprintf(queryBoolMustTermDomain, so.BidField))
|
|
|
}
|
|
|
qstr = fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(mustNot, ","))
|
|
@@ -572,14 +608,18 @@ 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
|
|
@@ -587,14 +627,18 @@ 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
|
|
@@ -604,11 +648,23 @@ 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)
|
|
|
}
|
|
|
|
|
@@ -647,17 +703,23 @@ 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
|
|
@@ -666,7 +728,9 @@ 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)
|
|
@@ -674,11 +738,13 @@ func (so *SearchOptimize) GetBidSearchQuery() string {
|
|
|
continue
|
|
|
}
|
|
|
if k > typeInt {
|
|
|
- allType += `,`
|
|
|
+ allType += `, `
|
|
|
}
|
|
|
allType += `"` + v + `"`
|
|
|
}
|
|
|
- allType += `]}}`
|
|
|
+ allType += `]
|
|
|
+}
|
|
|
+}`
|
|
|
//subtype里都是一级信息类型
|
|
|
if typeInt == len(strings.Split(subtype, ",")) {
|
|
|
allType = ``
|
|
@@ -690,14 +756,18 @@ 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 != "" {
|
|
@@ -711,14 +781,18 @@ 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
|
|
|
}
|
|
@@ -816,16 +890,23 @@ 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 {
|