mirror of
https://github.com/usememos/memos.git
synced 2024-12-20 09:41:58 +03:00
feat: add support for content search (#1728)
* Change MemoFind.ContentSearch to slice * Add support for content search * Change for go-simple sugguest --------- Co-authored-by: Athurg Feng <athurg@gooth.org>
This commit is contained in:
parent
1282fe732e
commit
4ea5426e18
@ -84,7 +84,7 @@ type FindMemoRequest struct {
|
|||||||
|
|
||||||
// Domain specific fields
|
// Domain specific fields
|
||||||
Pinned *bool
|
Pinned *bool
|
||||||
ContentSearch *string
|
ContentSearch []string
|
||||||
VisibilityList []Visibility
|
VisibilityList []Visibility
|
||||||
|
|
||||||
// Pagination
|
// Pagination
|
||||||
|
@ -272,11 +272,18 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|||||||
pinned := pinnedStr == "true"
|
pinned := pinnedStr == "true"
|
||||||
findMemoMessage.Pinned = &pinned
|
findMemoMessage.Pinned = &pinned
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contentSearch := []string{}
|
||||||
tag := c.QueryParam("tag")
|
tag := c.QueryParam("tag")
|
||||||
if tag != "" {
|
if tag != "" {
|
||||||
contentSearch := "#" + tag
|
contentSearch = append(contentSearch, "#"+tag)
|
||||||
findMemoMessage.ContentSearch = &contentSearch
|
|
||||||
}
|
}
|
||||||
|
contentSlice := c.QueryParams()["content"]
|
||||||
|
if len(contentSlice) > 0 {
|
||||||
|
contentSearch = append(contentSearch, contentSlice...)
|
||||||
|
}
|
||||||
|
findMemoMessage.ContentSearch = contentSearch
|
||||||
|
|
||||||
visibilityListStr := c.QueryParam("visibility")
|
visibilityListStr := c.QueryParam("visibility")
|
||||||
if visibilityListStr != "" {
|
if visibilityListStr != "" {
|
||||||
visibilityList := []store.Visibility{}
|
visibilityList := []store.Visibility{}
|
||||||
@ -431,11 +438,18 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|||||||
pinned := pinnedStr == "true"
|
pinned := pinnedStr == "true"
|
||||||
findMemoMessage.Pinned = &pinned
|
findMemoMessage.Pinned = &pinned
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contentSearch := []string{}
|
||||||
tag := c.QueryParam("tag")
|
tag := c.QueryParam("tag")
|
||||||
if tag != "" {
|
if tag != "" {
|
||||||
contentSearch := "#" + tag + " "
|
contentSearch = append(contentSearch, "#"+tag+" ")
|
||||||
findMemoMessage.ContentSearch = &contentSearch
|
|
||||||
}
|
}
|
||||||
|
contentSlice := c.QueryParams()["content"]
|
||||||
|
if len(contentSlice) > 0 {
|
||||||
|
contentSearch = append(contentSearch, contentSlice...)
|
||||||
|
}
|
||||||
|
findMemoMessage.ContentSearch = contentSearch
|
||||||
|
|
||||||
visibilityListStr := c.QueryParam("visibility")
|
visibilityListStr := c.QueryParam("visibility")
|
||||||
if visibilityListStr != "" {
|
if visibilityListStr != "" {
|
||||||
visibilityList := []store.Visibility{}
|
visibilityList := []store.Visibility{}
|
||||||
|
@ -71,11 +71,10 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Missing user session")
|
return echo.NewHTTPError(http.StatusBadRequest, "Missing user session")
|
||||||
}
|
}
|
||||||
contentSearch := "#"
|
|
||||||
normalRowStatus := store.Normal
|
normalRowStatus := store.Normal
|
||||||
memoFind := &store.FindMemoMessage{
|
memoFind := &store.FindMemoMessage{
|
||||||
CreatorID: &userID,
|
CreatorID: &userID,
|
||||||
ContentSearch: &contentSearch,
|
ContentSearch: []string{"#"},
|
||||||
RowStatus: &normalRowStatus,
|
RowStatus: &normalRowStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ type FindMemoMessage struct {
|
|||||||
|
|
||||||
// Domain specific fields
|
// Domain specific fields
|
||||||
Pinned *bool
|
Pinned *bool
|
||||||
ContentSearch *string
|
ContentSearch []string
|
||||||
VisibilityList []Visibility
|
VisibilityList []Visibility
|
||||||
|
|
||||||
// Pagination
|
// Pagination
|
||||||
@ -233,8 +233,10 @@ func listMemos(ctx context.Context, tx *sql.Tx, find *FindMemoMessage) ([]*MemoM
|
|||||||
if v := find.Pinned; v != nil {
|
if v := find.Pinned; v != nil {
|
||||||
where = append(where, "memo_organizer.pinned = 1")
|
where = append(where, "memo_organizer.pinned = 1")
|
||||||
}
|
}
|
||||||
if v := find.ContentSearch; v != nil {
|
if v := find.ContentSearch; len(v) != 0 {
|
||||||
where, args = append(where, "memo.content LIKE ?"), append(args, "%"+*v+"%")
|
for _, s := range v {
|
||||||
|
where, args = append(where, "memo.content LIKE ?"), append(args, "%"+s+"%")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if v := find.VisibilityList; len(v) != 0 {
|
if v := find.VisibilityList; len(v) != 0 {
|
||||||
list := []string{}
|
list := []string{}
|
||||||
|
Loading…
Reference in New Issue
Block a user