|
@@ -5,42 +5,73 @@ import (
|
|
|
"sfbase/core"
|
|
|
"sfbase/elastic"
|
|
|
"sfbase/global"
|
|
|
+ "sfis/db"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
- INDEX = core.GetStringConf("es.project.index")
|
|
|
- TYPE = core.GetStringConf("es.project.itype")
|
|
|
pjt_count = 100
|
|
|
- pjt_field = `"area","bidamount","bidstatus","budget","firsttime","projectname","s_winner","buyer","city"`
|
|
|
+ pjt_field = `"_id","area","city","bidamount","firsttime","projectname","s_winner","buyer","buyerclass"`
|
|
|
pjt_sort = `{"firsttime":-1}`
|
|
|
- query = `{"query": {"bool": {"should": [%s]}}}`
|
|
|
+ query = `{"query": {"bool": {"must":[%s],"should":[%s],"minimum_should_match": 1}}}`
|
|
|
query_string = `{"constant_score": {"boost": 2,"query": {"match_phrase": {"projectname.pname": {"analyzer": "my_ngram","query": "%s","slop": 6}}}}},{"multi_match": {"query": "%s","fields": ["projectname.pname"],"analyzer": "ik","minimum_should_match": "100%%"}}`
|
|
|
+ query_winner = `{"term": {"s_winner": "%s"}}`
|
|
|
+ SR = strings.Replace
|
|
|
+ HL = `"highlight": {"pre_tags": [""],"post_tags": [""],"fields": {%s}}`
|
|
|
+ highlightStr = `%s: {"fragment_size": %d,"number_of_fragments": 1}`
|
|
|
)
|
|
|
|
|
|
-func ProjectListData(projectName, winner, time string) *map[string]interface{} {
|
|
|
+func ProjectListData(projectName, winner, time string) (data *map[string]interface{}) {
|
|
|
global.Logger.Info("projectName " + projectName)
|
|
|
global.Logger.Info("winner " + winner)
|
|
|
global.Logger.Info("time " + time)
|
|
|
pjt_name := strings.TrimSpace(projectName)
|
|
|
pjt_len := len([]rune(pjt_name))
|
|
|
- data := &map[string]interface{}{}
|
|
|
+ data = &map[string]interface{}{}
|
|
|
qstr := ""
|
|
|
- if pjt_len >= 4 {
|
|
|
- qstr = fmt.Sprintf(query, fmt.Sprintf(query_string, pjt_name, pjt_name))
|
|
|
- global.Logger.Debug("qstr " + qstr)
|
|
|
+ if pjt_len >= 4 && winner == "" {
|
|
|
+ qstr = fmt.Sprintf(query, "", fmt.Sprintf(query_string, pjt_name, pjt_name))
|
|
|
+ } else if pjt_len >= 4 && winner != "" {
|
|
|
+ qstr = fmt.Sprintf(query, fmt.Sprintf(query_winner, winner), fmt.Sprintf(query_string, pjt_name, pjt_name))
|
|
|
+ } else if winner != "" {
|
|
|
+ qstr = fmt.Sprintf(query, fmt.Sprintf(query_winner, winner), "")
|
|
|
} else {
|
|
|
- return data
|
|
|
+ return
|
|
|
}
|
|
|
- repl := elastic.GetAllByNgram(INDEX, TYPE, qstr, "", pjt_sort, pjt_field, 0, pjt_count, 0, false)
|
|
|
+ INDEX := core.GetStringConf("es.project.index")
|
|
|
+ TYPE := core.GetStringConf("es.project.itype")
|
|
|
+ Es := db.GetEs()
|
|
|
+ global.Logger.Info("INDEX " + INDEX)
|
|
|
+ global.Logger.Info("TYPE " + TYPE)
|
|
|
+ repl := GetAllByNgram(Es, INDEX, TYPE, qstr, "", pjt_sort, pjt_field, 0, pjt_count, 0, false)
|
|
|
if repl != nil && len(*repl) > 0 {
|
|
|
(*data)["data"] = repl
|
|
|
}
|
|
|
- return data
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
-func WinnerProjectListData(winner string) *map[string]interface{} {
|
|
|
- global.Logger.Info("winner " + winner)
|
|
|
- data := &map[string]interface{}{}
|
|
|
- return data
|
|
|
+func GetAllByNgram(Es *elastic.Elastic, index, itype, qstr, findfields, order, fields string, start, limit, count int, highlight bool) *[]map[string]interface{} {
|
|
|
+ if qstr != "" {
|
|
|
+ if highlight {
|
|
|
+ ws := []string{}
|
|
|
+ for _, w := range strings.Split(findfields, ",") {
|
|
|
+ ws = append(ws, fmt.Sprintf(highlightStr, w, count))
|
|
|
+ }
|
|
|
+ qstr = qstr[:len(qstr)-1] + `,` + fmt.Sprintf(HL, strings.Join(ws, ",")) + `}`
|
|
|
+ }
|
|
|
+ if len(fields) > 0 {
|
|
|
+ qstr = qstr[:len(qstr)-1] + `,"_source":[` + fields + "]}"
|
|
|
+ }
|
|
|
+ if len(order) > 0 {
|
|
|
+ qstr = qstr[:len(qstr)-1] + `,"sort":[` + SR(SR(SR(SR(order, ",", "},{", -1), " ", "", -1), ":-1", `:"desc"`, -1), ":1", `:"asc"`, -1) + `]}`
|
|
|
+ }
|
|
|
+ if start > -1 {
|
|
|
+ qstr = qstr[:len(qstr)-1] + `,"from":` + strconv.Itoa(start) + `,"size":` + strconv.Itoa(limit) + "}"
|
|
|
+ }
|
|
|
+ global.Logger.Info("GetAllByNgram:" + qstr)
|
|
|
+ return Es.Get(index, itype, qstr)
|
|
|
+ } else {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
}
|