mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-02 18:34:29 +08:00
more powerful PageFindUserWithKeyword
This commit is contained in:
parent
92097e6382
commit
d79a313000
@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/protocol/user"
|
||||
"github.com/OpenIMSDK/tools/errs"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"time"
|
||||
|
||||
"github.com/OpenIMSDK/tools/mgoutil"
|
||||
@ -100,10 +101,14 @@ func (u *UserMgo) PageFindUserWithKeyword(ctx context.Context, level1 int64, lev
|
||||
if userID != "" || userName != "" {
|
||||
userConditions := []bson.M{}
|
||||
if userID != "" {
|
||||
userConditions = append(userConditions, bson.M{"user_id": userID})
|
||||
// Use regex for userID
|
||||
regexPattern := primitive.Regex{Pattern: userID, Options: "i"} // 'i' for case-insensitive matching
|
||||
userConditions = append(userConditions, bson.M{"user_id": regexPattern})
|
||||
}
|
||||
if userName != "" {
|
||||
userConditions = append(userConditions, bson.M{"nickname": userName})
|
||||
// Use regex for userName
|
||||
regexPattern := primitive.Regex{Pattern: userName, Options: "i"} // 'i' for case-insensitive matching
|
||||
userConditions = append(userConditions, bson.M{"nickname": regexPattern})
|
||||
}
|
||||
query["$and"] = append(query["$and"].([]bson.M), bson.M{"$or": userConditions})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user