|
@@ -31,6 +31,9 @@ func SearchProjectFullScoring(client *elastic.Client, target InputData, projectN
|
|
|
city = util.ObjToString((*res)["city"])
|
|
|
}
|
|
|
|
|
|
+ target.Area = province
|
|
|
+ target.City = city
|
|
|
+ fmt.Println(province, city)
|
|
|
// 1. 精准查询
|
|
|
preciseHits, err := searchPrecise(client, projectName, province, city, publish, 20)
|
|
|
if err != nil {
|
|
@@ -185,6 +188,9 @@ func searchPrecise(client *elastic.Client, projectName, province, city, publish
|
|
|
if field == "detail" {
|
|
|
// detail 只加时间 + filter
|
|
|
query := elastic.NewBoolQuery()
|
|
|
+ if province != "" {
|
|
|
+ query = query.Must(elastic.NewTermQuery("area", province))
|
|
|
+ }
|
|
|
query = query.Must(elastic.NewMultiMatchQuery(projectName, field).Type("phrase"))
|
|
|
query = query.Filter(filters...)
|
|
|
if !t.IsZero() {
|
|
@@ -197,7 +203,7 @@ func searchPrecise(client *elastic.Client, projectName, province, city, publish
|
|
|
if province != "" && city != "" {
|
|
|
query1 := elastic.NewBoolQuery()
|
|
|
query1 = query1.Must(elastic.NewMultiMatchQuery(projectName, field).Type("phrase"))
|
|
|
- query1 = query1.Must(elastic.NewTermQuery("province", province))
|
|
|
+ query1 = query1.Must(elastic.NewTermQuery("area", province))
|
|
|
query1 = query1.Must(elastic.NewTermQuery("city", city))
|
|
|
query1 = query1.Filter(filters...)
|
|
|
if !t.IsZero() {
|
|
@@ -209,7 +215,7 @@ func searchPrecise(client *elastic.Client, projectName, province, city, publish
|
|
|
if province != "" {
|
|
|
query2 := elastic.NewBoolQuery()
|
|
|
query2 = query2.Must(elastic.NewMultiMatchQuery(projectName, field).Type("phrase"))
|
|
|
- query2 = query2.Must(elastic.NewTermQuery("province", province))
|
|
|
+ query2 = query2.Must(elastic.NewTermQuery("area", province))
|
|
|
query2 = query2.Filter(filters...)
|
|
|
if !t.IsZero() {
|
|
|
query2 = query2.Must(elastic.NewRangeQuery("publishtime").Gte(dateRangeStart).Lt(dateRangeEnd))
|
|
@@ -218,7 +224,7 @@ func searchPrecise(client *elastic.Client, projectName, province, city, publish
|
|
|
}
|
|
|
|
|
|
//// 3. 不限制省市
|
|
|
- //if province != "" {
|
|
|
+ //if province == "" {
|
|
|
// query3 := elastic.NewBoolQuery()
|
|
|
// query3 = query3.Must(elastic.NewMultiMatchQuery(projectName, field).Type("phrase"))
|
|
|
// query3 = query3.Filter(filters...)
|
|
@@ -323,8 +329,11 @@ func searchByToken(client *elastic.Client, projectName, province, city, publish
|
|
|
var queries []*elastic.BoolQuery
|
|
|
|
|
|
if field == "detail" {
|
|
|
- query := elastic.NewBoolQuery().
|
|
|
- Must(elastic.NewMatchQuery(field, queryText)).
|
|
|
+ query := elastic.NewBoolQuery()
|
|
|
+ if province != "" {
|
|
|
+ query = query.Must(elastic.NewTermQuery("area", province))
|
|
|
+ }
|
|
|
+ query = query.Must(elastic.NewMatchQuery(field, queryText)).
|
|
|
Filter(filters...)
|
|
|
if !t.IsZero() {
|
|
|
query = query.Must(elastic.NewRangeQuery("publishtime").Gte(dateRangeStart).Lt(dateRangeEnd))
|
|
@@ -335,7 +344,7 @@ func searchByToken(client *elastic.Client, projectName, province, city, publish
|
|
|
if province != "" && city != "" {
|
|
|
q := elastic.NewBoolQuery().
|
|
|
Must(elastic.NewMatchQuery(field, queryText)).
|
|
|
- Must(elastic.NewTermQuery("province", province)).
|
|
|
+ Must(elastic.NewTermQuery("area", province)).
|
|
|
Must(elastic.NewTermQuery("city", city)).
|
|
|
Filter(filters...)
|
|
|
if !t.IsZero() {
|
|
@@ -347,7 +356,7 @@ func searchByToken(client *elastic.Client, projectName, province, city, publish
|
|
|
if province != "" {
|
|
|
q := elastic.NewBoolQuery().
|
|
|
Must(elastic.NewMatchQuery(field, queryText)).
|
|
|
- Must(elastic.NewTermQuery("province", province)).
|
|
|
+ Must(elastic.NewTermQuery("area", province)).
|
|
|
Filter(filters...)
|
|
|
if !t.IsZero() {
|
|
|
q = q.Must(elastic.NewRangeQuery("publishtime").Gte(dateRangeStart).Lt(dateRangeEnd))
|
|
@@ -441,13 +450,26 @@ func searchCommon(client *elastic.Client, projectName, province, city, publish s
|
|
|
|
|
|
if field == "detail" {
|
|
|
// 只做普通匹配 + 时间
|
|
|
- boolQuery := map[string]interface{}{
|
|
|
- "bool": map[string]interface{}{
|
|
|
- "must": []interface{}{
|
|
|
- commonQuery(field, 0.1),
|
|
|
+ boolQuery := map[string]interface{}{}
|
|
|
+ if province != "" {
|
|
|
+ boolQuery = map[string]interface{}{
|
|
|
+ "bool": map[string]interface{}{
|
|
|
+ "must": []interface{}{
|
|
|
+ commonQuery(field, 0.1),
|
|
|
+ map[string]interface{}{"term": map[string]interface{}{"area": province}},
|
|
|
+ },
|
|
|
},
|
|
|
- },
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ boolQuery = map[string]interface{}{
|
|
|
+ "bool": map[string]interface{}{
|
|
|
+ "must": []interface{}{
|
|
|
+ commonQuery(field, 0.1),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
if !t.IsZero() {
|
|
|
boolQuery["bool"].(map[string]interface{})["filter"] = []interface{}{
|
|
|
map[string]interface{}{
|
|
@@ -469,7 +491,7 @@ func searchCommon(client *elastic.Client, projectName, province, city, publish s
|
|
|
"bool": map[string]interface{}{
|
|
|
"must": []interface{}{
|
|
|
commonQuery(field, 0.2),
|
|
|
- map[string]interface{}{"term": map[string]interface{}{"province": province}},
|
|
|
+ map[string]interface{}{"term": map[string]interface{}{"area": province}},
|
|
|
map[string]interface{}{"term": map[string]interface{}{"city": city}},
|
|
|
},
|
|
|
},
|
|
@@ -495,7 +517,7 @@ func searchCommon(client *elastic.Client, projectName, province, city, publish s
|
|
|
"bool": map[string]interface{}{
|
|
|
"must": []interface{}{
|
|
|
commonQuery(field, 0.2),
|
|
|
- map[string]interface{}{"term": map[string]interface{}{"province": province}},
|
|
|
+ map[string]interface{}{"term": map[string]interface{}{"area": province}},
|
|
|
},
|
|
|
},
|
|
|
}
|