Skip to content

Commit

Permalink
fix: Improve notes search functionality and summary display
Browse files Browse the repository at this point in the history
  • Loading branch information
Laisky committed Sep 2, 2024
1 parent 1c21b10 commit 3bb98b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion internal/web/telegram/dao/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/Laisky/errors/v2"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
mongoLib "go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"

Expand Down Expand Up @@ -34,7 +35,10 @@ func (d *Telegram) GetNotesCol() *mongoLib.Collection {
// Search search notes by keyword
func (d *Telegram) Search(ctx context.Context, keyword string) (notes []*model.TelegramNote, err error) {
cur, err := d.GetNotesCol().Find(ctx,
bson.M{"content": bson.M{"$regex": keyword}},
bson.M{"content": bson.M{"$regex": primitive.Regex{
Pattern: keyword,
Options: "i",
}}},
options.Find().SetSort(bson.M{"_id": -1}).SetLimit(10),
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/web/telegram/service/notes_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *Type) notesSearchDispatcher(ctx context.Context, us *userStat, msg *tb.
}
}

const noteSummaryLen = 120
const noteSummaryLen = 140

func (s *Type) notesSearchByKeyword(ctx context.Context, us *userStat, msg string) error {
keyword := strings.TrimSpace(msg)
Expand Down

0 comments on commit 3bb98b7

Please sign in to comment.