linq - How to get the expected correct matching search results? -
code:
public list<searchresult> getrecordsbyterm(string term) { return _datareadservice.getrecords() .where(x => x.firstname.contains(term) || term.contains(x.firstname) || x.lastname.contains(term) || term.contains(x.lastname) || x.emailaddress.contains(term) || term.contains(x.emailaddress)) .select(x => new searchresult() { detailedname = (x.firstname ?? string.empty) + " " + (x.lastname ?? string.empty) + (x.title != null && x.title != string.empty ? ", " : string.empty) + (x.title ?? string.empty) + " (" + (x.office ?? string.empty) + ")", email = x.emailaddress }) .orderby(x => x.detailedname) .tolist(); }
in above code, if passing term "baske
", getting 2 search results follows:
1, "bas ge" 2, "basket"
"bas ge
" should not in search results, getting result. how redefine above code, need exact matching words?
well if "bas" first name, term.contains(x.firstname) true. seems odd thing do.
Comments
Post a Comment