Browse Source

es搜索

layui
mail_yanpeng@163.com 5 years ago
parent
commit
b726e27326
  1. 4
      conf/app.conf
  2. 2
      controllers/BlogController.go
  3. 32
      static/css/common.css
  4. 2
      static/css/common.min.css
  5. 2
      utils/EsUtil.go
  6. 4
      views/T.header.tpl
  7. 3
      views/T.nav.tpl
  8. 1
      views/blogs.html
  9. 4
      views/index.html
  10. 28
      views/search.html

4
conf/app.conf

@ -1,6 +1,6 @@
appname = beeblog
runmode = dev
runmode = prod
sessionon = true
sessiongcmaxlifetime = 36000
@ -13,7 +13,7 @@ host = aiprose.com
httpport = 8082
uploadDir = "static/upload/"
imgUrlPrefix = "http://localhost:8082/static/upload/"
dburl = "booszy@tcp(localhost:3306)"
dburl = "booszy@tcp(47.98.109.5:3306)"
[prod]
httpport = 8082

2
controllers/BlogController.go

@ -131,7 +131,7 @@ func (this *BlogController) Get() {
this.Data["Top"] = blogs
}
//utils.Index()
//utils.ESSave(blog)
utils.ESSave(blog)
this.Data["Blog"] = blog
this.Data["UserId"] = this.GetSession("userid")
this.Data["HeadImg"] = this.GetSession("headimg")

32
static/css/common.css

@ -295,7 +295,6 @@ img {
.home-content-title{
display: inline-block;
font-size: 16px;
/*width: 65%;*/
flex: 1;
}
@ -658,4 +657,35 @@ img {
border: 1px solid #3385ff;
border-left: none;
cursor: pointer;
}
.search-result{
margin: 35px 15%;
}
.search-item{
padding: 7px 15px;
}
.search-result a{
display: block;
cursor: pointer;
height: 25px;
line-height: 25px;
font-size: 16px;
text-decoration: #00c6ff;
flex: 1;
}
.search-result .search-title{
display: flex;
}
.search-result span{
cursor: pointer;
font-size: 12px;
height: 25px;
line-height: 25px;
}
.search-content{
font-size: 12px;
}

2
static/css/common.min.css

File diff suppressed because one or more lines are too long

2
utils/EsUtil.go

@ -12,7 +12,7 @@ import (
"time"
)
var client *elastic.Client
var host = "http://47.98.109.5:8209"
var host = "http://106.12.3.97:8209/"
const mapping = `
{
"settings":{

4
views/T.header.tpl

@ -13,6 +13,6 @@
<script type="text/javascript" src="/static/js/layer.js"></script>
<link rel="stylesheet" href="/static/layui/css/layui.css">
<script type="text/javascript" src="/static/layui/layui.js"></script>
<!-- <link type="text/css" rel="styleSheet" href="/static/css/common.min.css"/>-->
<link type="text/css" rel="styleSheet" href="/static/css/common.css"/>
<link type="text/css" rel="styleSheet" href="/static/css/common.min.css"/>
{{/* <link type="text/css" rel="styleSheet" href="/static/css/common.css"/>*/}}
{{end}}

3
views/T.nav.tpl

@ -3,6 +3,9 @@
<nav>
<ul class="layui-nav layui-bg-molv" lay-filter="">
<p>码农随笔</p>
<li class="layui-nav-item">
<a href="/search"><i class="layui-icon">&#xe615;</i><span style="padding-left:8px">搜索</span></a>
</li>
<li class="layui-nav-item">
<a href="/blog/new"><i class="layui-icon">&#xe642;</i>写文章</a>
</li>

1
views/blogs.html

@ -58,7 +58,6 @@
</div>
</div>
</div>
<hr style="border:none;"/>
</div>
{{end}}

4
views/index.html

@ -14,12 +14,14 @@
{{range .TimeBlog}}
<p><a href="/blog/{{.Id}}" target="_blank">{{.Title}}</a></p>
{{end}}
<p><a href="https://www.aiprose.com/blogs">查看更多...</a></p>
</div>
<div style="flex: 1">
<h5>流量王者</h5>
{{range .BrowsBlog}}
<p><a href="/blog/{{.Id}}" target="_blank">{{.Title}}</a></p>
{{end}}
<p><a href="https://www.aiprose.com/blogs">查看更多...</a></p>
</div>
</div>
<div style="display: flex">
@ -28,12 +30,14 @@
{{range .LikeBlog}}
<p><a href="/blog/{{.Id}}" target="_blank">{{.Title}}</a></p>
{{end}}
<p><a href="https://www.aiprose.com/blogs">查看更多...</a></p>
</div>
<div style="flex: 1">
<h5>人气最旺</h5>
{{range .CommBlog}}
<p><a href="/blog/{{.Id}}" target="_blank">{{.Title}}</a></p>
{{end}}
<p><a href="https://www.aiprose.com/blogs">查看更多...</a></p>
</div>
</div>
</div>

28
views/search.html

@ -1,6 +1,7 @@
{{template "header" .}}
<meta name="keywords" content="码农随笔,个人随笔,博客,个人博客,个人笔记,技术博客,免费云笔记,云笔记,随笔,IT博客,谷歌地图,码农笔录,aiprose">
<title>搜索 - 码农随笔</title>
<script src="https://unpkg.com/dayjs@1.8.15/dayjs.min.js"></script>
</head>
<body>
<div class="root-container">
@ -15,34 +16,41 @@
</div>
</div>
</div>
<div>
<div class="search-result">
</div>
</div>
</div>
</body>
<script>
var pageNo = 1;
var pageSize = 30;
// var pageNo = page;
var searchParms = {
from: 0,
size: 20,
query: {
multi_match: {
query: "linux",
query: "",
// type: "best_fields",
fields: ["Title", "BlogHtml"]
}
}
}
$(function () {
$("#searchBtn").click(function () {
var searchVal = $("#searchVal").val()
if (!searchVal || searchVal.trim().length == 0) {
layer.msg("请输入查询内容")
return
}
searchParms.query.multi_match.query = searchVal;
var stringify = JSON.stringify(searchParms);
$.ajax({
url: "https://www.aiprose.com/beeblog/beeblog/_search",    //请求的url地址
headers:{'Content-Type':'application/json;charset=utf8'},
url: "http://106.12.3.97:8209/beeblog/beeblog/_search",    //请求的url地址
headers: {'Content-Type': 'application/json;charset=utf8'},
dataType: "json",   //返回格式为json
async: true,//请求是否异步,默认为异步,这也是ajax重要特性
data: stringify,    //参数值
@ -51,7 +59,17 @@
//请求前的处理
},
success: function (resp) {
debugger
if (resp.hits.total != 0) {
$(".search-result").children().remove();
resp.hits.hits.forEach(function (el, index) {
console.log(el._source)
var htmlStr = '<div class=\"search-item\">\n' +
' <div class=\"search-title\"><a href=\"https://www.aiprose.com/blog/' + el._source.Id + '\" target=\"_blank\">' + el._source.Title + '</a><span>' + dayjs(el._source.Ctime).format("YYYY-MM-DD") + '</span></div>\n' +
' <p class=\"search-content\">' + el._source.BlogDesc + '</p>\n' +
' </div>'
$(".search-result").append(htmlStr)
})
}
//请求成功时处理
},
complete: function () {

Loading…
Cancel
Save