浏览代码

elasticutil

张金坤 8 年之前
父节点
当前提交
a11900ebcc
共有 1 个文件被更改,包括 6 次插入2 次删除
  1. 6 2
      common/src/qfw/util/elastic/elasticutil.go

+ 6 - 2
common/src/qfw/util/elastic/elasticutil.go

@@ -918,7 +918,9 @@ const (
 func GetNgramQuery(query interface{}, mustquery, findfields string) (qstr string) {
 	var words []string
 	if q, ok := query.(string); ok {
-		words = strings.Split(q, ",")
+		if q != "" {
+			words = strings.Split(q, ",")
+		}
 	} else if q, ok := query.([]string); ok {
 		words = q
 	} else if q, ok := query.([]interface{}); ok {
@@ -937,6 +939,8 @@ func GetNgramQuery(query interface{}, mustquery, findfields string) (qstr string
 		}
 		qstr = fmt.Sprintf(NgramStr, mustquery, strings.Join(musts, ","))
 		//log.Println("ngram-query", qstr)
+	} else {
+		qstr = fmt.Sprintf(NgramStr, mustquery, "")
 	}
 	return
 }
@@ -983,7 +987,7 @@ func GetByNgramOther(index, itype string, query interface{}, mustquery, findfiel
 func GetByNgramAll(index, itype string, query interface{}, mustquery, findfields, order, fields string, start, limit int, highlight bool, filtermode bool) *[]map[string]interface{} {
 	defer util.Catch()
 	qstr := ""
-	if mustquery != "" && filtermode {
+	if mustquery != "" {
 		qstr = GetNgramQuery(query, "", findfields)
 		qstr = fmt.Sprintf(FilterQuery, mustquery, qstr[1:])
 	} else {