Answers for "how to create more accurate searching c#"

C#
0

how to create more accurate searching c#

var keywords = new [] {"Sergey", "Berezovskiy"};

var users = from u in context.Users
            let match = (keywords.Contains(u.FirstName) ? 1 : 0) +
                        (keywords.Contains(u.LastName) ? 1 : 0) +
                        (keywords.Contains(u.MiddleName) ? 1 : 0)
            where match > 0
            orderby match descending, 
                    u.LastName, u.FirstName
            select u;

var methodChain = context.Users
                .Select(u => new
                {
                    u,
                    match = (keywords.Contains(u.FirstName) ? 1 : 0) +
                        	(keywords.Contains(u.LastName) ? 1 : 0) +
                        	(keywords.Contains(u.MiddleName) ? 1 : 0)
                })
                .Where(t => t.match > 0)
                .OrderByDescending(t => t.match)
  				.ThenBy(t.u.LastName)
  				.ThenBy(t.u.FirstName)
                .Select(t => t.p);
Posted by: Guest on January-29-2020

Code answers related to "how to create more accurate searching c#"

C# Answers by Framework

Browse Popular Code Answers by Language