实现项目内搜索功能

pull/39/head
Minho 2017-05-15 14:59:23 +08:00
parent 08c4d52116
commit eba2fdc4ac
5 changed files with 150 additions and 27 deletions

View File

@ -832,10 +832,40 @@ func (c *DocumentController) QrCode() {
}
}
//项目内搜索.
func (c *DocumentController) Search() {
c.Prepare()
c.JsonResult(0,"ok")
identify := c.Ctx.Input.Param(":key")
token := c.GetString("token")
keyword := strings.TrimSpace(c.GetString("keyword"))
if identify == ""{
c.JsonResult(6001,"参数错误")
}
if !c.EnableAnonymous && c.Member == nil {
c.Redirect(beego.URLFor("AccountController.Login"), 302)
return
}
bookResult := isReadable(identify,token,c)
docs,err := models.NewDocumentSearchResult().SearchDocument(keyword,bookResult.BookId)
if err != nil {
beego.Error(err)
c.JsonResult(6002,"搜索结果错误")
}
if len(docs) < 0 {
c.JsonResult(404,"没有数据库")
}
for _,doc := range docs {
doc.BookId = bookResult.BookId
doc.BookName = bookResult.BookName
doc.Description = bookResult.Description
doc.BookIdentify = bookResult.Identify
}
c.JsonResult(0,"ok",docs)
}
//递归生成文档序列数组.

View File

@ -23,6 +23,7 @@ func main() {
commands.RegisterCommand()
commands.RegisterFunction()
beego.SetStaticPath("uploads", "uploads")
beego.ErrorController(&controllers.ErrorController{})

View File

@ -53,6 +53,7 @@ func NewDocument() *Document {
}
}
//根据文档ID查询指定文档.
func (m *Document) Find(id int) (*Document,error) {
if id <= 0 {
return m,ErrInvalidParameter
@ -150,6 +151,7 @@ func (m *Document) ReleaseContent(book_id int) {
}
}
//根据项目ID查询文档列表.
func (m *Document) FindListByBookId(book_id int) (docs []*Document,err error) {
o := orm.NewOrm()
@ -162,3 +164,6 @@ func (m *Document) FindListByBookId(book_id int) (docs []*Document,err error) {

View File

@ -18,13 +18,13 @@ type DocumentSearchResult struct {
BookId int `json:"book_id"`
BookName string `json:"book_name"`
BookIdentify string `json:"book_identify"`
}
func NewDocumentSearchResult() *DocumentSearchResult {
return &DocumentSearchResult{}
}
//分页全局搜索.
func (m *DocumentSearchResult) FindToPager(keyword string, page_index, page_size, member_id int) (search_result []*DocumentSearchResult, total_count int, err error) {
o := orm.NewOrm()
@ -66,7 +66,6 @@ WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0) AND (doc.document_
WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0) AND (doc.document_name LIKE ? OR doc.release LIKE ?)
ORDER BY doc.document_id DESC LIMIT ?,? `
err = o.Raw(sql1, member_id, keyword, keyword).QueryRow(&total_count)
if err != nil {
return
@ -79,3 +78,14 @@ WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0) AND (doc.document_
return
}
//项目内搜索.
func (m *DocumentSearchResult) SearchDocument(keyword string, book_id int) (docs []*DocumentSearchResult, err error) {
o := orm.NewOrm()
sql := "SELECT * FROM md_documents WHERE book_id = ? AND (document_name LIKE ? OR `release` LIKE ?) "
keyword = "%" + keyword + "%"
_, err = o.Raw(sql, book_id, keyword, keyword).QueryRows(&docs)
return
}

View File

@ -271,10 +271,18 @@ h6 {
.m-manual.manual-mode-view .manual-catalog {
display: block
}
.m-manual.manual-mode-search .manual-search .search-container{
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.m-manual .manual-search .search-form{
margin: 5px ;
margin: 5px 5px 10px 5px;
position: relative;
}
.m-manual .manual-search .btn-search{
background-color: #ffffff;
border: 0;
@ -283,6 +291,75 @@ h6 {
top: 2px;
right: 5px;
}
.m-manual .manual-search .btn-search .fa{
width: 16px;
height: 16px;
vertical-align: middle;
}
.m-manual .manual-search .btn-search .loading{
background-image: url("../images/loading.gif");
}
.m-manual .manual-search .search-result{
position: absolute;
top: 45px;
left: 0;
right: 0;
bottom: 0;
width: 275px;
overflow-y: auto;
border-top: 1px solid #eee;
}
.m-manual .manual-search .search-result .search-empty{
position: absolute;
top: 45%;
left: 0;
right: 0;
text-align: center;
}
.m-manual .manual-search .search-result .search-empty i{
font-size: 50px;
display: block;
color: #999;
font-weight: 200;
}
.m-manual .manual-search .search-result .search-empty .text{
font-size: 16px;
font-weight: 200;
color: #999;
line-height: 40px;
}
.m-manual .manual-search .search-list{
position: absolute;
top: 0;
bottom: 0;
min-width: 100%;
}
.m-manual .manual-search .search-list a{
display: block;
border-bottom: 0;
height: 30px;
line-height: 24px;
padding: 3px 10px 3px 20px;
color: #666;
text-decoration: none;
white-space:nowrap;
overflow: hidden;
}
.m-manual .manual-search .search-list a:hover{
text-shadow: none;
background: #116cd6;
box-shadow: none;
color: #fff;
text-decoration: none;
white-space:nowrap;
}
.m-manual .manual-search .search-list a.active{
background: #10af88;
background: -webkit-linear-gradient(top, #beebff 0%, #a8e4ff 100%);
background: linear-gradient(to bottom, #10af88 0%, #10af88 100%);
color: #ffffff;
}
.m-manual .manual-left .m-copyright {
border-top: 0;
background: #fafafa;