mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-04-05 20:17:53 +08:00
feat:搜索支持文章
This commit is contained in:
parent
437b11614e
commit
8681d8fa3e
@ -39,7 +39,6 @@ func (c *SearchController) Index() {
|
||||
searchResult, totalCount, err := models.NewDocumentSearchResult().FindToPager(keyword, pageIndex, conf.PageSize, memberId)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询搜索结果失败 => ",err)
|
||||
return
|
||||
}
|
||||
if totalCount > 0 {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
type DocumentSearchResult struct {
|
||||
@ -18,6 +19,7 @@ type DocumentSearchResult struct {
|
||||
BookId int `json:"book_id"`
|
||||
BookName string `json:"book_name"`
|
||||
BookIdentify string `json:"book_identify"`
|
||||
SearchType string `json:"search_type"`
|
||||
}
|
||||
|
||||
func NewDocumentSearchResult() *DocumentSearchResult {
|
||||
@ -36,19 +38,67 @@ func (m *DocumentSearchResult) FindToPager(keyword string, pageIndex, pageSize,
|
||||
LEFT JOIN md_books as book ON doc.book_id = book.book_id
|
||||
WHERE book.privately_owned = 0 AND (doc.document_name LIKE ? OR doc.release LIKE ?) `
|
||||
|
||||
sql2 := `SELECT doc.document_id,doc.modify_time,doc.create_time,doc.document_name,doc.identify,doc.release as description,doc.modify_time,book.identify as book_identify,book.book_name,rel.member_id,member.account AS author FROM md_documents AS doc
|
||||
LEFT JOIN md_books as book ON doc.book_id = book.book_id
|
||||
LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND rel.role_id = 0
|
||||
LEFT JOIN md_members as member ON rel.member_id = member.member_id
|
||||
WHERE book.privately_owned = 0 AND (doc.document_name LIKE ? OR doc.release LIKE ?)
|
||||
ORDER BY doc.document_id DESC LIMIT ?,? `
|
||||
sql2 := `SELECT *
|
||||
FROM (
|
||||
SELECT
|
||||
doc.document_id,
|
||||
doc.modify_time,
|
||||
doc.create_time,
|
||||
doc.document_name,
|
||||
doc.identify,
|
||||
doc.release AS description,
|
||||
book.identify AS book_identify,
|
||||
book.book_name,
|
||||
rel.member_id,
|
||||
member.account AS author,
|
||||
'document' AS search_type
|
||||
FROM md_documents AS doc
|
||||
LEFT JOIN md_books AS book ON doc.book_id = book.book_id
|
||||
LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND rel.role_id = 0
|
||||
LEFT JOIN md_members AS member ON rel.member_id = member.member_id
|
||||
WHERE book.privately_owned = 0 AND (doc.document_name LIKE ? OR doc.release LIKE ?)
|
||||
UNION ALL
|
||||
SELECT
|
||||
blog.blog_id,
|
||||
blog.modify_time,
|
||||
blog.create_time,
|
||||
blog.blog_title,
|
||||
blog.blog_identify,
|
||||
blog.blog_release,
|
||||
blog.blog_identify,
|
||||
blog.blog_title,
|
||||
blog.member_id,
|
||||
member.account,
|
||||
'blog' AS search_type
|
||||
FROM md_blogs AS blog
|
||||
LEFT JOIN md_members AS member ON blog.member_id = member.member_id
|
||||
WHERE blog.blog_status = 'public' AND (blog.blog_release LIKE ? OR blog.blog_title LIKE ?)
|
||||
) AS union_table
|
||||
ORDER BY create_time DESC
|
||||
LIMIT ?, ?;`
|
||||
|
||||
err = o.Raw(sql1, keyword, keyword).QueryRow(&totalCount)
|
||||
if err != nil {
|
||||
beego.Error("查询搜索结果失败 -> ",err)
|
||||
return
|
||||
}
|
||||
_, err = o.Raw(sql2, keyword, keyword, offset, pageSize).QueryRows(&searchResult)
|
||||
sql3 := ` SELECT
|
||||
count(*)
|
||||
FROM md_blogs AS blog
|
||||
WHERE blog.blog_status = 'public' AND (blog.blog_release LIKE ? OR blog.blog_title LIKE ?);`
|
||||
|
||||
c := 0
|
||||
err = o.Raw(sql3, keyword, keyword).QueryRow(&c)
|
||||
if err != nil {
|
||||
beego.Error("查询搜索结果失败 -> ",err)
|
||||
return
|
||||
}
|
||||
|
||||
totalCount += c
|
||||
|
||||
_, err = o.Raw(sql2, keyword, keyword,keyword,keyword, offset, pageSize).QueryRows(&searchResult)
|
||||
if err != nil {
|
||||
beego.Error("查询搜索结果失败 -> ",err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
@ -62,23 +112,78 @@ WHERE book.privately_owned = 0 AND (doc.document_name LIKE ? OR doc.release LIKE
|
||||
on team.book_id = book.book_id
|
||||
WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0 or team.team_member_id > 0) AND (doc.document_name LIKE ? OR doc.release LIKE ?) `
|
||||
|
||||
sql2 := `SELECT doc.document_id,doc.modify_time,doc.create_time,doc.document_name,doc.identify,doc.release as description,doc.modify_time,book.identify as book_identify,book.book_name,rel.member_id,member.account AS author FROM md_documents AS doc
|
||||
LEFT JOIN md_books as book ON doc.book_id = book.book_id
|
||||
LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND rel.role_id = 0
|
||||
LEFT JOIN md_members as member ON rel.member_id = member.member_id
|
||||
LEFT JOIN md_relationship AS rel1 ON doc.book_id = rel1.book_id AND rel1.member_id = ?
|
||||
left join (select * from (select book_id,team_member_id,role_id
|
||||
from md_team_relationship as mtr
|
||||
left join md_team_member as mtm on mtm.team_id=mtr.team_id and mtm.member_id=? order by role_id desc )as t group by t.role_id,t.team_member_id,t.book_id) as team
|
||||
on team.book_id = book.book_id
|
||||
WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0 or team.team_member_id > 0) AND (doc.document_name LIKE ? OR doc.release LIKE ?)
|
||||
ORDER BY doc.document_id DESC LIMIT ?,? `
|
||||
sql2 := `SELECT *
|
||||
FROM (
|
||||
SELECT
|
||||
doc.document_id,
|
||||
doc.modify_time,
|
||||
doc.create_time,
|
||||
doc.document_name,
|
||||
doc.identify,
|
||||
doc.release AS description,
|
||||
book.identify AS book_identify,
|
||||
book.book_name,
|
||||
rel.member_id,
|
||||
member.account AS author,
|
||||
'document' AS search_type
|
||||
FROM md_documents AS doc
|
||||
LEFT JOIN md_books AS book ON doc.book_id = book.book_id
|
||||
LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND rel.role_id = 0
|
||||
LEFT JOIN md_members AS member ON rel.member_id = member.member_id
|
||||
LEFT JOIN md_relationship AS rel1 ON doc.book_id = rel1.book_id AND rel1.member_id = ?
|
||||
LEFT JOIN (SELECT *
|
||||
FROM (SELECT
|
||||
book_id,
|
||||
team_member_id,
|
||||
role_id
|
||||
FROM md_team_relationship AS mtr
|
||||
LEFT JOIN md_team_member AS mtm ON mtm.team_id = mtr.team_id AND mtm.member_id = ?
|
||||
ORDER BY role_id DESC) AS t
|
||||
GROUP BY t.role_id, t.team_member_id, t.book_id) AS team
|
||||
ON team.book_id = book.book_id
|
||||
WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0 OR team.team_member_id > 0) AND
|
||||
(doc.document_name LIKE ? OR doc.release LIKE ?)
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
blog.blog_id,
|
||||
blog.modify_time,
|
||||
blog.create_time,
|
||||
blog.blog_title,
|
||||
blog.blog_identify,
|
||||
blog.blog_release,
|
||||
blog.blog_identify,
|
||||
blog.blog_title,
|
||||
blog.member_id,
|
||||
member.account,
|
||||
'blog' AS search_type
|
||||
FROM md_blogs AS blog
|
||||
LEFT JOIN md_members AS member ON blog.member_id = member.member_id
|
||||
WHERE (blog.blog_status = 'public' OR blog.member_id = ?) AND blog.blog_type = 0 AND
|
||||
(blog.blog_release LIKE ? OR blog.blog_title LIKE ?)
|
||||
) AS union_table
|
||||
ORDER BY create_time DESC
|
||||
LIMIT ?, ?;`
|
||||
|
||||
err = o.Raw(sql1, memberId, memberId, keyword, keyword).QueryRow(&totalCount)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = o.Raw(sql2, memberId, memberId, keyword, keyword, offset, pageSize).QueryRows(&searchResult)
|
||||
sql3 := ` SELECT
|
||||
count(*)
|
||||
FROM md_blogs AS blog
|
||||
WHERE (blog.blog_status = 'public' OR blog.member_id = ?) AND blog.blog_type = 0 AND
|
||||
(blog.blog_release LIKE ? OR blog.blog_title LIKE ?);`
|
||||
|
||||
c := 0
|
||||
err = o.Raw(sql3,memberId, keyword, keyword).QueryRow(&c)
|
||||
if err != nil {
|
||||
beego.Error("查询搜索结果失败 -> ",err)
|
||||
return
|
||||
}
|
||||
|
||||
totalCount += c
|
||||
_, err = o.Raw(sql2, memberId, memberId, keyword, keyword,memberId,keyword, keyword, offset, pageSize).QueryRows(&searchResult)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -25,12 +25,22 @@
|
||||
<div class="manual-list">
|
||||
{{range $index,$item := .Lists}}
|
||||
<div class="search-item">
|
||||
<div class="title"><a href="{{urlfor "DocumentController.Read" ":key" $item.BookIdentify ":id" $item.Identify}}" title="{{$item.DocumentName}}" target="_blank">{{str2html $item.DocumentName}}</a> </div>
|
||||
<div class="title">
|
||||
{{if eq $item.SearchType "document"}}
|
||||
<a href="{{urlfor "DocumentController.Read" ":key" $item.BookIdentify ":id" $item.Identify}}" title="{{$item.DocumentName}}" target="_blank">{{str2html $item.DocumentName}}</a>
|
||||
{{else}}
|
||||
<a href="{{urlfor "BlogController.Index" ":id" $item.DocumentId}}" title="{{$item.DocumentName}}" target="_blank">{{str2html $item.DocumentName}}</a>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="description">
|
||||
{{str2html $item.Description}}
|
||||
</div>
|
||||
<div class="source">
|
||||
<span class="item">来自:<a href="{{urlfor "DocumentController.Index" ":key" $item.BookIdentify}}" target="_blank">{{$item.BookName}}</a></span>
|
||||
{{if eq $item.SearchType "document"}}
|
||||
<span class="item">来自项目:<a href="{{urlfor "DocumentController.Index" ":key" $item.BookIdentify}}" target="_blank">{{$item.BookName}}</a></span>
|
||||
{{else}}
|
||||
<span class="item">来自文章:<a href="{{urlfor "BlogController.Index" ":id" $item.DocumentId}}" target="_blank">{{$item.BookName}}</a></span>
|
||||
{{end}}
|
||||
<span class="item">作者:{{$item.Author}}</span>
|
||||
<span class="item">更新时间:{{date_format $item.ModifyTime "2006-01-02 15:04:05"}}</span>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user