wangchuanjin 7 年之前
父节点
当前提交
8d36b7b39a

+ 7 - 7
src/jfw/front/supsearch.go

@@ -4,7 +4,6 @@ import (
 	"fmt"
 	"jfw/config"
 	"jfw/jylabutil"
-	"log"
 	"math/rand"
 	"qfw/util"
 	"qfw/util/redis"
@@ -48,7 +47,7 @@ func (p *Pcsearch) ProposedProject() error {
 	if len(shareid) == 0 {
 		shareid = fmt.Sprintf("%s%d", config.Seoconfig["jynjxmy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
 	}
-	b_word, _, s_word := InterceptSearchKW(p.GetString("keywords"), false)
+	b_word, _, s_word := InterceptSearchKW(p.GetString("keywords"), false, true)
 	area := p.GetString("area")               //地区
 	publishtime := p.GetString("publishtime") //发布时间
 	subtype := p.GetString("subtype")         //信息类型
@@ -169,7 +168,7 @@ func (p *Pcsearch) PcSearchIndex() error {
 	//if selectType == "" {
 	selectType = "title"
 	//}
-	b_word, _, s_word := InterceptSearchKW(p.GetString("keywords"), false)
+	b_word, _, s_word := InterceptSearchKW(p.GetString("keywords"), false, true)
 	var list *[]map[string]interface{}
 	var status = 1
 	var count, totalPage int64
@@ -353,11 +352,13 @@ func (p *Pcsearch) Qr(t string) error {
 
 //超过20个字,截断
 //返回截取后的字符串和截取掉中的前3个字
-func InterceptSearchKW(word string, flag bool) (b_word, a_word, s_word string) {
-	word = FilteKey(word)
+func InterceptSearchKW(word string, isIntercept, isFilter bool) (b_word, a_word, s_word string) {
+	if isFilter {
+		word = FilteKey(word)
+	}
 	word = matchSpace.ReplaceAllString(strings.TrimSpace(word), " ")
 	words := []rune(word)
-	if len(words) > 20 && flag {
+	if len(words) > 20 && isIntercept {
 		b_word = string(words[:20])
 		b_word = strings.TrimSpace(b_word)
 		if len(words) > 23 {
@@ -370,6 +371,5 @@ func InterceptSearchKW(word string, flag bool) (b_word, a_word, s_word string) {
 	}
 	a_word = strings.TrimSpace(a_word)
 	s_word = matchSpace.ReplaceAllString(b_word, "+")
-	log.Println(b_word, "==", a_word, "==", s_word)
 	return
 }

+ 22 - 27
src/jfw/front/swordfish.go

@@ -501,7 +501,7 @@ func (m *Front) PcAjaxReq() {
 	if selectType == "" {
 		selectType = "all"
 	}
-	_, a_word, s_word := InterceptSearchKW(m.GetString("searchvalue"), selectType == "all")
+	_, a_word, s_word := InterceptSearchKW(m.GetString("searchvalue"), selectType == "all", true)
 	var list *[]map[string]interface{}
 	var count, totalPage int64
 	status, _ := m.GetInteger("status")
@@ -845,8 +845,7 @@ func (m *Front) Wxsearch() error {
 //剑鱼微信查询结果页面
 func (m *Front) Wxsearchlist() error {
 	defer util.Catch()
-	keywords := m.GetString("searchname")
-	searchvalue := m.GetString("searchvalue")
+	keywords := strings.TrimSpace(m.GetString("searchname"))
 	toptype := m.GetString("toptype")
 	subtype := m.GetString("subtype")
 	industry := strings.TrimSpace(m.GetString("industry"))
@@ -864,13 +863,13 @@ func (m *Front) Wxsearchlist() error {
 	m.SetSession("scope", scope)
 	m.SetSession("publishtime", publishtime)
 	var list *[]map[string]interface{}
+	var s_word string
 	if userid := m.GetSession("userId"); userid != nil {
 		if len(keywords) > 0 {
 			if selectType == "" { //默认设置为全文搜索
 				selectType = "all"
 			}
-			list = getWxsearchlistData(keywords, searchvalue, scope, publishtime, subtype, industry, minprice, maxprice, 1, selectType, bidSearch_field)
-
+			list, _, _, s_word = getWxsearchlistData(keywords, scope, publishtime, subtype, industry, minprice, maxprice, 1, selectType, bidSearch_field)
 			r := redis.GetStr("other", "s_"+userid.(string))
 			arrs := strings.Split(r, ",")
 			if r == "" {
@@ -896,7 +895,7 @@ func (m *Front) Wxsearchlist() error {
 	m.T["list"] = list
 	m.T["pageSize"] = wx_pageSize
 	m.T["keywords"] = keywords
-	m.T["searchvalue"] = searchvalue
+	m.T["searchvalue"] = s_word
 	m.T["toptype"] = toptype
 	m.T["subtype"] = subtype
 	m.T["scope"] = scope
@@ -925,21 +924,21 @@ func (m *Front) WxsearchlistPaging() {
 		one, _ := mongodb.FindOneByField("user", bson.M{"_id": bson.ObjectIdHex(userid.(string))}, `{"o_jy":1}`)
 		history := redis.GetStr("other", "s_"+userid.(string))
 		arrs := strings.Split(history, ",")
-		searchvalue := strings.Trim(m.GetString("searchvalue"), " ")
+		searchvalue := strings.TrimSpace(m.GetString("searchvalue"))
+		var b_word, a_word string
 		if searchvalue != "" {
-			searchname := strings.Replace(strings.Replace(searchvalue, " ", "+", -1), "++", "+", -1)
+			selectType := m.GetString("selectType")
 			subtype := m.GetString("subtype")
 			scope := m.GetString("scope")
 			publishtime := m.GetString("publishtime")
-			selectType := m.GetString("selectType")
 			industry := strings.TrimSpace(m.GetString("industry"))
 			m.SetSession("industry", industry)
 			minprice := m.GetString("minprice")
 			maxprice := m.GetString("maxprice")
 			if open_supersearch {
-				list = getWxsearchlistData(searchvalue, searchname, scope, publishtime, subtype, industry, minprice, maxprice, pageNum, selectType, bidSearch_field)
+				list, b_word, a_word, _ = getWxsearchlistData(searchvalue, scope, publishtime, subtype, industry, minprice, maxprice, pageNum, selectType, bidSearch_field)
 			} else {
-				list = getWxsearchlistData(searchvalue, searchname, scope, publishtime, subtype, "", "", "", pageNum, selectType, bidSearch_field)
+				list, b_word, a_word, _ = getWxsearchlistData(searchvalue, scope, publishtime, subtype, "", "", "", pageNum, selectType, bidSearch_field)
 			}
 			//新增历史记录
 			if history == "" {
@@ -972,10 +971,12 @@ func (m *Front) WxsearchlistPaging() {
 			m.T["msgset"] = keys
 		}
 		m.ServeJson(map[string]interface{}{
-			"list":        list,
-			"hasNextPage": list != nil && len(*list) == wx_pageSize && pageNum < wx_maxPageNum,
-			"history":     m.T["history"],
-			"msgset":      m.T["msgset"],
+			"list":          list,
+			"hasNextPage":   list != nil && len(*list) == wx_pageSize && pageNum < wx_maxPageNum,
+			"history":       m.T["history"],
+			"msgset":        m.T["msgset"],
+			"interceptWord": a_word,
+			"keyWord":       b_word,
 		})
 	}
 }
@@ -996,22 +997,16 @@ func (m *Front) DelWxHistorySearch() {
 }
 
 //微信端搜索
-func getWxsearchlistData(keywords, searchvalue, scope, publishtime, subtype, industry, minprice, maxprice string, pageNum int, selectType, field string) (list *[]map[string]interface{}) {
-	//scope是地区对应传进的areas, stype是类型对应scope
-	if len(industry) > 0 {
-		keywords = strings.TrimSpace(keywords)
-	} else {
-		keywords = FilteKey(keywords)
-	}
-	if len(keywords) == 0 {
-		return list
+func getWxsearchlistData(keywords, scope, publishtime, subtype, industry, minprice, maxprice string, pageNum int, selectType, field string) (list *[]map[string]interface{}, b_word, a_word, s_word string) {
+	b_word, a_word, s_word = InterceptSearchKW(keywords, selectType == "all", len(industry) == 0)
+	if len(b_word) == 0 {
+		return list, b_word, a_word, s_word
 	}
-	fmt.Print("keywords>>>", keywords, "searchvalue>>", searchvalue)
 	findfields := `"title"`
 	if selectType == "all" {
 		findfields = `"title","detail"`
 	}
-	qstr := getSearchQuery(searchvalue, industry, minprice, maxprice, findfields, getBidSearchQuery(scope, publishtime, subtype))
+	qstr := getSearchQuery(s_word, industry, minprice, maxprice, findfields, getBidSearchQuery(scope, publishtime, subtype))
 	if selectType == "all" { //全文搜索
 		list = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, field, (pageNum-1)*wx_pageSize, wx_pageSize, 100, true)
 	} else { //标题搜索
@@ -1024,7 +1019,7 @@ func getWxsearchlistData(keywords, searchvalue, scope, publishtime, subtype, ind
 			v["_id"] = util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]))
 		}
 	}
-	return list
+	return list, b_word, a_word, s_word
 }
 
 //查看原文跳转

+ 16 - 0
src/web/staticres/css/wxsearch.css

@@ -2175,4 +2175,20 @@ body{
     left: 0px;
 	top: 24px;
     font-size: 14px;
+}
+#supersearchPage #intercept{
+	padding: 17px 20px 0px 20px;
+	font-size: 14px;
+}
+#supersearchPage #intercept>span{
+	color: #2CB7CA;
+	font-size: 18px;
+	vertical-align: middle;
+}
+#supersearchPage #intercept>font{
+	margin: 0px 5px;
+}
+#supersearchPage .nullcontent{
+	position: relative;
+    top: 20px;
 }

+ 26 - 1
src/web/staticres/js/wxSupersearch.js

@@ -13,6 +13,7 @@ var SuperSearch = {
 	showNull: null,//null true false
 	advert: null,
 	advertIsClose: false,
+	interceptWord: "",
 	industry: "",
 	sortArray: "",
 	reqParam: {
@@ -61,7 +62,7 @@ var SuperSearch = {
 		//	if(localStorage.selectType=="allSearch"){
 		//		$("#supersearchPage #search_all").addClass("on").siblings().removeClass("on");
 		//	}else if(localStorage.selectType=="titleSearch"){
-				$("#supersearchPage #search_title").addClass("on").siblings().removeClass("on");
+				//$("#supersearchPage #search_title").addClass("on").siblings().removeClass("on");
 		//	}
 		//}
 		//筛选菜单展示or隐藏
@@ -72,6 +73,9 @@ var SuperSearch = {
 			$("#supersearchPage .point").addClass("hidden");
 			$("#supersearchPage #super_search").toggleClass("hidden");
 			if($("#supersearchPage #super_search").hasClass("hidden")){
+				if(SuperSearch.interceptWord != ""){
+					$("#supersearchPage #intercept").removeClass("hidden");
+				}
 				if(SuperSearch.showNull){
 					$("#supersearchPage #selLable").removeClass("hidden");
 					$("#supersearchPage .nullcontent").removeClass("hidden");	
@@ -84,6 +88,7 @@ var SuperSearch = {
 					$("#supersearchPage #wrapper").removeClass("hidden");
 				}
 			}else{
+				$("#supersearchPage #intercept").addClass("hidden");
 				$("#supersearchPage #selLable").addClass("hidden");
 				$("#supersearchPage .nullcontent").addClass("hidden");
 				$("#supersearchPage #wrapper").addClass("hidden");
@@ -584,6 +589,9 @@ var SuperSearch = {
 		sessionStorage.removeItem("superSearch_advertIsClose");
 		sessionStorage.removeItem("superSearch_shaxuan");
 		sessionStorage.removeItem("superSearch_showType");
+		sessionStorage.removeItem("superSearch_shaxuanFlag");
+		sessionStorage.removeItem("superSearch_searchType");
+		sessionStorage.removeItem("superSearch_interceptWord");
 	},
 	//js 方法
 	resetSx: function (){         //清除筛选
@@ -762,6 +770,7 @@ var SuperSearch = {
 		if(!SuperSearch.beforeSubmit()){
 			return;
 		}
+		$("#supersearchPage #intercept").addClass("hidden");
 		$("#supersearchPage #table").addClass("hidden");
 		$("#supersearchPage #list").addClass("hidden");
 		if(SuperSearch.showNull){
@@ -790,6 +799,8 @@ var SuperSearch = {
 			data: SuperSearch.reqParam,
 			dataType: "json",
 			success: function(data){
+				SuperSearch.appendInterceptWord(data.interceptWord);
+				SuperSearch.s_words = data.keyWord;
 				SuperSearch.requesting = false;
 				//历史记录和我的订阅
 				SuperSearch.htmlTipMsg(data["history"],data["msgset"]);
@@ -1256,6 +1267,8 @@ var SuperSearch = {
 				sessionStorage.superSearch_shaxuan=shaxuanclass;
 			}
 			sessionStorage.superSearch_shaxuanFlag=!$("#supersearchPage #super_search").hasClass("hidden");
+			sessionStorage.superSearch_searchType=$("#supersearchPage #selLable>.com-title>span.on").attr("id");
+			sessionStorage.superSearch_interceptWord=SuperSearch.interceptWord;
 	    }
 	},
 	setUpLastPage: function () {
@@ -1289,6 +1302,7 @@ var SuperSearch = {
 			});
 			$("#supersearchPage #table .data .content").html(TableContent);
 	    }
+		SuperSearch.appendInterceptWord(sessionStorage.superSearch_interceptWord);
 		if(sessionStorage.superSearch_advertIsClose == "false"){
 			SuperSearch.advertIsClose = false;
 		}else{
@@ -1415,6 +1429,8 @@ var SuperSearch = {
 				$("#supersearchPage .jytype-dialog").removeClass("hidden");
 			}
 		}
+		$("#supersearchPage #selLable>.com-title>span.on").removeClass("on");
+		$("#supersearchPage #selLable>.com-title>#"+sessionStorage.superSearch_searchType).addClass("on");
 		if(sessionStorage.superSearch_showType=="showList"){
 			$("#supersearchPage .showlist").addClass("on").siblings().removeClass("on");
 			$("#supersearchPage #wrapper #table").addClass("hidden");
@@ -1649,5 +1665,14 @@ var SuperSearch = {
 		if(SuperSearch.dropload != null){
 			SuperSearch.dropload.resetload();
 		}
+	},
+	appendInterceptWord: function(word){
+		SuperSearch.interceptWord = word;
+		if(word == ""){
+			$("#supersearchPage #intercept").addClass("hidden");
+			return;
+		}
+		$("#supersearchPage #intercept").removeClass("hidden");
+		$("#supersearchPage #intercept>font").text("“"+word+"”");
 	}
 };

+ 3 - 2
src/web/templates/weixin/search/mainSearch.html

@@ -92,7 +92,7 @@
 	<div>
 		<div class="selLable hidden" id="selLable">
 			<div class="com-title"><!--height:30px; margin-top:20px;-->
-				<span onclick="SuperSearch.allSearch()" id="search_all" class="on" >全文搜索</span><span id="search_title" onclick="SuperSearch.titleSearch()">标题搜索</span>
+				<span onclick="SuperSearch.allSearch()" id="search_all">全文搜索</span><span id="search_title" onclick="SuperSearch.titleSearch()" class="on">标题搜索</span>
 			</div>
 			<div class="line-vertical">
 			</div>
@@ -100,7 +100,8 @@
 				<div class="showlist on" onclick="SuperSearch.showlist();">列表</div>
 				<div class="showtable" onclick="SuperSearch.showTable()">表格</div>
 			</div>
-		</div>
+		</div>		
+		<div id="intercept" class="hidden"><span class="bootstrap-glyphicon glyphicon-info-sign"></span><font>“的方式”</font>及其后面的字词均被忽略,因为剑鱼的查询限制在20个汉字以内。</div>
 		<div class="wxsearch hidden" id="super_search">
 			<div class="jysstj">
 				<div class="jyshaxuan">