this way i am trying to order data
List<SearchResult> list = new List<SearchResult>() {
new SearchResult(){ID=1,Title="Geo Prism 1995 GEO GEO- ABS #16213899"},
new SearchResult(){ID=2,Title="Geo Prism 1995 GEO - ABS #16213899"},
new SearchResult(){ID=3,Title="Geo Prism 1995 - ABS #16213899"},
new SearchResult(){ID=3,Title="Geo Prism 1995 - ABS #16213899"},
new SearchResult(){ID=4,Title="Wie man BBA reman erreicht"},
new SearchResult(){ID=5,Title="Ersatz Airbags, Gurtstrammer und Auto Körper Teile "},
new SearchResult(){ID=6,Title="JCB Excavator - ECU P/N: 728/35700"},
};
var to_search = new[] { "Geo", "JCB" };
var result = from searchResult in list
let title = searchResult.Title.ToLower()
let key_string = to_search.FirstOrDefault(ts => title.Contains(ts))
orderby key_string == null ? -1 : title.Split(new[] { key_string }, StringSplitOptions.None).Length descending
group searchResult by key_string into Group
orderby Group.Count() descending
select Group;
var matched = result.SelectMany(m => m);
var completeList = matched.Concat(list.Except(matched));
dataGridView2.DataSource = completeList.ToList();//.SelectMany(x => x).ToList();
data is showing in grid but the way i am expecting data that is not coming.
output is coming now
ID Title
1 Geo Prism 1995 - ABS #16213899
2 Geo Prism 1995 - ABS #16213899
3 Geo Prism 1995 - ABS #16213899
3 Geo Prism 1995 - ABS #16213899
4 Wie man BBA reman erreicht
5 Ersatz Airbags, Gurtstrammer und Auto Körper Teile
6 JCB Excavator - ECU P/N: 728/35700
but i want to show data this below way
output should be like
ID Title
1 Geo Prism 1995 GEO GEO - ABS #16213899
2 Geo Prism 1995 GEO - ABS #16213899
3 Geo Prism 1995 - ABS #16213899
3 Geo Prism 1995 - ABS #16213899
6 JCB Excavator - ECU P/N: 728/35700
4 Wie man BBA reman erreicht
5 Ersatz Airbags, Gurtstrammer und Auto Körper Teile
JCB should come after all the GEO because i am sorting data with the search word like
“geo jcb” . geo found in title of most of the rows. so those rows come first which has occurance of my search word. so geo is one of my search word and it present maximum time in all rows title. next jcb should come because jcb is in my search term but in output jcb related rows coming at last. so tell me how to change my linq query. thanks
Output: