LINQ to Entities search multiple columns, order by total weight of the matches columns
<p>I am implementing a search algorithm and I need to way to search the database over multiple columns. The algorithm will then return a "best match". For example, let's say I have an entity:</p>

<pre><code>public class Person{
    public string Name { get; set; }
    public int Age { get; set; }
    public string Title { get; set; }
}
</code></pre>

<p>My search method needs to accept searching over name, age, and title, <em>with all being optional</em> where any combination is possible. All fields have a weight that I will fine-tune in my code for better results. Results should be ordered by a <code>score</code> where <code>score</code> is:</p>

<p><code>matchedColumn1Weight + matchedColumn2Weight + ... + matchedColumnNWeight</code></p>

<p>Let's just assume I have this table called people:</p>

<pre><code>Name     Age    Title
-------------------------
Alice    20     Manager
Bob      21     Friend
James    20     Friend
Will     22     Manager
</code></pre>

<p>Let's assume <code>Name</code> has a weight of <code>1</code>, <code>Age</code> a weight of <code>1</code> and <code>Title</code> a weight of <code>1.1</code>. If I search with fields <code>name = null, age = 20, title = Friend</code>, it should first return James and then Bob, then Alice, and then Will.</p>

<p>How do I implement such functionality in LINQ-to-Entities? In other words, I need <em>a LINQ where I query over multiple optional fields, map each item in my database to a total score of columns have matched (where columns have a fixed, preset weight), then order by that score.</em> How do make it?</p>