Hi,
Can someone help me implement sort using textScore and fuzzy on my C# code using regex please??
Currently i have this Search Index:
{
"mappings": {
"fields": {
"Name": {
"analyzer": "lucene.keyword",
"type": "string"
}
}
}
}
And this is how my code looks like:
public class UserEntity
{
[BsonElement("Id")]
public string Id{ get; set; }
[BsonElement("Age")]
public string Age { get; set; }
[BsonElement("Name")]
public string Name { get; set; }
[BsonElement("NickName")]
public string NickName { get; set; }
}
public async Task<List<UserEntity>> SearchUser(string name)
{
try
{
List<UserEntity> result = Collection.Aggregate()
.Search(
SearchBuilders<UserEntity>.Search.Regex($"({name})", x => x.Name, true))
.Sort("{ score: { $meta: \"textScore\" } } ")
.Project(x => new UserEntity { Id = x.Id, Age = x.Age, Name = x.Name, NickName = x.NickName})
.ToList();
return result;
}
catch (Exception ex)
{
throw ex;
}
}