|
@@ -16,7 +16,7 @@ import (
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
-func SearchProjectFullScoring(client *elastic.Client, target InputData, projectName, areacode, publish string) ([]map[string]interface{}, error) {
|
|
|
|
|
|
+func SearchProjectFullScoring(client *elastic.Client, target InputData, projectName, areacode, publish string, targetScore float64) ([]map[string]interface{}, error) {
|
|
seenIDs := make(map[string]*elastic.SearchHit)
|
|
seenIDs := make(map[string]*elastic.SearchHit)
|
|
|
|
|
|
province, city := "", ""
|
|
province, city := "", ""
|
|
@@ -105,9 +105,15 @@ func SearchProjectFullScoring(client *elastic.Client, target InputData, projectN
|
|
}
|
|
}
|
|
|
|
|
|
score := calculateConfidenceScore(target, candidate)
|
|
score := calculateConfidenceScore(target, candidate)
|
|
- //candidate.Score = score
|
|
|
|
- candidate.Score, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", score), 64)
|
|
|
|
- allCandidates = append(allCandidates, candidate)
|
|
|
|
|
|
+ if targetScore > 0 {
|
|
|
|
+ if score >= targetScore {
|
|
|
|
+ candidate.Score, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", score), 64)
|
|
|
|
+ allCandidates = append(allCandidates, candidate)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ candidate.Score, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", score), 64)
|
|
|
|
+ allCandidates = append(allCandidates, candidate)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// 排序(降序)
|
|
// 排序(降序)
|
|
@@ -211,16 +217,16 @@ func searchPrecise(client *elastic.Client, projectName, province, city, publish
|
|
queries = append(queries, query2)
|
|
queries = append(queries, query2)
|
|
}
|
|
}
|
|
|
|
|
|
- // 3. 不限制省市
|
|
|
|
- if province != "" {
|
|
|
|
- query3 := elastic.NewBoolQuery()
|
|
|
|
- query3 = query3.Must(elastic.NewMultiMatchQuery(projectName, field).Type("phrase"))
|
|
|
|
- query3 = query3.Filter(filters...)
|
|
|
|
- if !t.IsZero() {
|
|
|
|
- query3 = query3.Must(elastic.NewRangeQuery("publishtime").Gte(dateRangeStart).Lt(dateRangeEnd))
|
|
|
|
- }
|
|
|
|
- queries = append(queries, query3)
|
|
|
|
- }
|
|
|
|
|
|
+ //// 3. 不限制省市
|
|
|
|
+ //if province != "" {
|
|
|
|
+ // query3 := elastic.NewBoolQuery()
|
|
|
|
+ // query3 = query3.Must(elastic.NewMultiMatchQuery(projectName, field).Type("phrase"))
|
|
|
|
+ // query3 = query3.Filter(filters...)
|
|
|
|
+ // if !t.IsZero() {
|
|
|
|
+ // query3 = query3.Must(elastic.NewRangeQuery("publishtime").Gte(dateRangeStart).Lt(dateRangeEnd))
|
|
|
|
+ // }
|
|
|
|
+ // queries = append(queries, query3)
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
|
|
|
|
for _, query := range queries {
|
|
for _, query := range queries {
|
|
@@ -348,14 +354,14 @@ func searchByToken(client *elastic.Client, projectName, province, city, publish
|
|
}
|
|
}
|
|
queries = append(queries, q)
|
|
queries = append(queries, q)
|
|
}
|
|
}
|
|
- // 无省市
|
|
|
|
- q := elastic.NewBoolQuery().
|
|
|
|
- Must(elastic.NewMatchQuery(field, queryText)).
|
|
|
|
- Filter(filters...)
|
|
|
|
- if !t.IsZero() {
|
|
|
|
- q = q.Must(elastic.NewRangeQuery("publishtime").Gte(dateRangeStart).Lt(dateRangeEnd))
|
|
|
|
- }
|
|
|
|
- queries = append(queries, q)
|
|
|
|
|
|
+ //// 无省市
|
|
|
|
+ //q := elastic.NewBoolQuery().
|
|
|
|
+ // Must(elastic.NewMatchQuery(field, queryText)).
|
|
|
|
+ // Filter(filters...)
|
|
|
|
+ //if !t.IsZero() {
|
|
|
|
+ // q = q.Must(elastic.NewRangeQuery("publishtime").Gte(dateRangeStart).Lt(dateRangeEnd))
|
|
|
|
+ //}
|
|
|
|
+ //queries = append(queries, q)
|
|
}
|
|
}
|
|
|
|
|
|
for _, query := range queries {
|
|
for _, query := range queries {
|
|
@@ -508,27 +514,27 @@ func searchCommon(client *elastic.Client, projectName, province, city, publish s
|
|
queries = append(queries, q)
|
|
queries = append(queries, q)
|
|
}
|
|
}
|
|
|
|
|
|
- // 3. 不加省市
|
|
|
|
- q := map[string]interface{}{
|
|
|
|
- "bool": map[string]interface{}{
|
|
|
|
- "must": []interface{}{
|
|
|
|
- commonQuery(field, 0.2),
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
- if !t.IsZero() {
|
|
|
|
- q["bool"].(map[string]interface{})["filter"] = []interface{}{
|
|
|
|
- map[string]interface{}{
|
|
|
|
- "range": map[string]interface{}{
|
|
|
|
- "publishtime": map[string]interface{}{
|
|
|
|
- "gte": dateRangeStart,
|
|
|
|
- "lt": dateRangeEnd,
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- queries = append(queries, q)
|
|
|
|
|
|
+ //// 3. 不加省市
|
|
|
|
+ //q := map[string]interface{}{
|
|
|
|
+ // "bool": map[string]interface{}{
|
|
|
|
+ // "must": []interface{}{
|
|
|
|
+ // commonQuery(field, 0.2),
|
|
|
|
+ // },
|
|
|
|
+ // },
|
|
|
|
+ //}
|
|
|
|
+ //if !t.IsZero() {
|
|
|
|
+ // q["bool"].(map[string]interface{})["filter"] = []interface{}{
|
|
|
|
+ // map[string]interface{}{
|
|
|
|
+ // "range": map[string]interface{}{
|
|
|
|
+ // "publishtime": map[string]interface{}{
|
|
|
|
+ // "gte": dateRangeStart,
|
|
|
|
+ // "lt": dateRangeEnd,
|
|
|
|
+ // },
|
|
|
|
+ // },
|
|
|
|
+ // },
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ //queries = append(queries, q)
|
|
}
|
|
}
|
|
|
|
|
|
for _, q := range queries {
|
|
for _, q := range queries {
|