mirror of https://github.com/mindoc-org/mindoc.git
fix:优化搜索
parent
329b87c685
commit
d735ea27ca
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/lifei6671/mindoc/utils/sqltil"
|
||||
"html/template"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -957,7 +958,7 @@ func (c *BookController) TeamSearch() {
|
|||
if err != nil {
|
||||
c.JsonResult(500, err.Error())
|
||||
}
|
||||
|
||||
keyword = sqltil.EscapeLike(keyword)
|
||||
searchResult, err := models.NewTeamRelationship().FindNotJoinBookByBookIdentify(book.BookId, keyword, 10)
|
||||
|
||||
if err != nil {
|
||||
|
@ -972,6 +973,7 @@ func (c *BookController) ItemsetsSearch() {
|
|||
c.Prepare()
|
||||
|
||||
keyword := strings.TrimSpace(c.GetString("q"))
|
||||
keyword = sqltil.EscapeLike(keyword)
|
||||
|
||||
searchResult, err := models.NewItemsets().FindItemsetsByName(keyword, 10)
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/lifei6671/mindoc/models"
|
||||
"github.com/lifei6671/mindoc/utils"
|
||||
"github.com/lifei6671/mindoc/utils/pagination"
|
||||
"github.com/lifei6671/mindoc/utils/sqltil"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
@ -36,7 +37,7 @@ func (c *SearchController) Index() {
|
|||
if c.Member != nil {
|
||||
memberId = c.Member.MemberId
|
||||
}
|
||||
searchResult, totalCount, err := models.NewDocumentSearchResult().FindToPager(keyword, pageIndex, conf.PageSize, memberId)
|
||||
searchResult, totalCount, err := models.NewDocumentSearchResult().FindToPager(sqltil.EscapeLike(keyword), pageIndex, conf.PageSize, memberId)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -86,6 +87,7 @@ func (c *SearchController) User() {
|
|||
if key == "" || keyword == "" {
|
||||
c.JsonResult(404, "参数错误")
|
||||
}
|
||||
keyword = sqltil.EscapeLike(keyword)
|
||||
|
||||
book, err := models.NewBookResult().FindByIdentify(key, c.Member.MemberId)
|
||||
if err != nil {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package sqltil
|
||||
|
||||
import "strings"
|
||||
|
||||
//转义like语法的%_符号
|
||||
func EscapeLike(keyword string) string {
|
||||
return strings.Replace(strings.Replace(keyword,"_","\\_",-1),"%","\\%",-1)
|
||||
}
|
Loading…
Reference in New Issue