I am writing a simple search page for our intranet application. When a user searches for n words, I create n hit lists and then want to return only those results that are common to all lists.
I have something working with help List<int>like this:
var list1 = new List<int> {1,2,3,4,5,8,10};
var list2 = new List<int> {3,5,6,9,10,11};
var list3 = new List<int> {3,4,5,10};
var listOfLists = new List<List<int>>{list1,list2,list3};
var results = listOfLists.Aggregate((prevList, nextList) => prevList
.Intersect(nextList)
.ToList());
results.Dump();
However, if I try this with my SearchResults class, I get no results. Here is the code:
List<SearchResult> list1 = new List<SearchResult>();
list1.Add(new SearchResult ("a.html","howard kent"));
list1.Add(new SearchResult ("b.html","howard shaw"));
list1.Add(new SearchResult ("c.html","howard smith"));
list1.Add(new SearchResult ("d.html","howard moore"));
List<SearchResult> list2 = new List<SearchResult>();
list2.Add(new SearchResult ("e.html","jon shaw"));
list2.Add(new SearchResult ("b.html","howard shaw"));
list2.Add(new SearchResult ("f.html","chris shaw"));
List<List<SearchResult>> searchLists = new List<List<SearchResult>>();
searchLists.Add(list1);
searchLists.Add(list2);
var results = searchLists
.Aggregate((prevList, nextList) => prevList
.Intersect(nextList)
.ToList());
results.Dump();
}
class SearchResult
{
public string Url{get;set;}
public string SearchText { get; set; }
public SearchResult(string url,string searchText)
{
Url = url;
SearchText = searchText;
}
How do I modify a query to return the result I want?