Optimize LINQ search with custom fixed ranking
Distinct

Take a look at the documentation for Distinct.

A couple things from the remarks should stand out for you:


  The Distinct(IEnumerable) method returns an unordered sequence that contains no duplicate values.


I know that the order of the sequence is preserved when using Distinct but that's an implementation detail - there's no gaurantee.


  The default equality comparer, Default, is used to compare values of the types that implement the IEquatable generic interface. To compare a custom data type, you must implement this interface and provide your own GetHashCode and Equals methods for the type.


Your custom type Counterpart does not do this. It should implement IEquatable&lt;Counterpart&gt; and additionally override both GetHashCode and Equals.

public class CounterPart : IEquatable&lt;Counterpart&gt;
{
    // ...
    public bool Equals(Counterpart other)
    {
        // left for you.
    } 

    public override bool Equals(object other)
    {
        return Equals(other as Counterpart);
    }

    public override bool GetHashCode()
    {
         // http://stackoverflow.com/a/263416/1402923
    }
}


Now you have a type that is safe for use with Distinct!

AddRange

As far as I know, AddRange only throws when the collection is null. You don't need to check for items before you call it. That elminates a whole heap of code:

rankedItems.AddRange(items1.Select(x =&gt; new CounterPartRanking { Rank = 1, CounterPart = x }));
rankedItems.AddRange(items2.Select(x =&gt; new CounterPartRanking { Rank = 2, CounterPart = x }));
rankedItems.AddRange(items3.Select(x =&gt; new CounterPartRanking { Rank = 3, CounterPart = x }));
rankedItems.AddRange(items4.Select(x =&gt; new CounterPartRanking { Rank = 4, CounterPart = x }));
rankedItems.AddRange(items5.Select(x =&gt; new CounterPartRanking { Rank = 5, CounterPart = x }));
rankedItems.AddRange(items6.Select(x =&gt; new CounterPartRanking { Rank = 6, CounterPart = x }));
rankedItems.AddRange(items7.Select(x =&gt; new CounterPartRanking { Rank = 7, CounterPart = x }));


Other comments

As I mentioned previously, this isn't gauranteed to be correct (but is in every instance I know of):

var items = rankedItems.OrderBy(x =&gt; x.Rank).Select(x =&gt; x.CounterPart);
var distinct = items.Distinct();