search is not searchin
This commit is contained in:
parent
beeac40a10
commit
3e72510d53
@ -241,13 +241,12 @@ func (m *MongoDB) Search(search string, filter []string, collection_name string)
|
||||
opts.SetLimit(100)
|
||||
if strings.TrimSpace(search) == "*" {
|
||||
search = ""
|
||||
} else {
|
||||
search = `(?i).*` + strings.TrimSpace(search) + `.*`
|
||||
}
|
||||
search = ".*" + strings.TrimSpace(search) + ".*"
|
||||
targetDBCollection := CollectionMap[collection_name]
|
||||
list := []bson.M{}
|
||||
for _, k := range filter {
|
||||
list = append(list, bson.M{k: bson.M{"$regex": search}})
|
||||
list = append(list, bson.M{k: bson.M{"$regex": search, "$options": 'i'}})
|
||||
}
|
||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
@ -255,8 +254,8 @@ func (m *MongoDB) Search(search string, filter []string, collection_name string)
|
||||
if cursor, err := targetDBCollection.Find(
|
||||
MngoCtx,
|
||||
bson.M{"$or": []bson.M{
|
||||
{"name": bson.M{"$regex": search}},
|
||||
{"description": bson.M{"$regex": search}},
|
||||
{"name": bson.M{"$regex": search, "$options": 'i'}},
|
||||
{"description": bson.M{"$regex": search, "$options": 'i'}},
|
||||
}},
|
||||
opts,
|
||||
); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user