Reputation: 51
i want to Implement FullText search on My Entity ... i have multiple Condition and now I want to know which of the conditions has been established ... In the final result, I will show the user what fields the search value was.
for Example keyword=Jack , was in FirstName Or LastName Or FatherName ?
my code like this :
Users.Where(x => x.FullName.Contains(keywords) || x.LastName.Contains(keywords) || x.FatherName.Contains(keywords)).ToList();
Upvotes: 1
Views: 140
Reputation: 301
You can create a custom class:
public class SearchUser
{
public string FullName { get; set; }
public string LastName { get; set; }
public string FatherName { get; set; }
public bool searchFullName { get; set; }
public bool searchLastName { get; set; }
public bool searchFatherName { get; set; }
}
and
Users.Where(x => x.FullName.Contains(keywords) ||
x.LastName.Contains(keywords) ||
x.FatherName.Contains(keywords))
.Select(x => new SearchUser()
{
FatherName = x.FatherName,
FullName = x.FullName,
LastName = x.LastName,
searchFatherName = x.FatherName.Contains(keywords),
searchFullName = x.FullName.Contains(keywords),
searchLastName = x.LastName.Contains(keywords)
}).ToList();
this way you can know where the keywords was found.
Upvotes: 1