c# - Sort by Count Occurrences of a Word in list rows linq -


My question was to sort the list from the event of the word in every line of linq data .... Reply to me Here is the code that is giving the right product to anyone here.

  Zero main () {list & lt; SearchResult & gt; List = new list & lt; SearchResult & gt; () {New SearchResult () {id = 1, title = "Geo Prizm Geo 1995 Geo * - ABS # 16213899"}, new SearchResult () {id = 2, title = "digging JCB - ECU P / N 728 / 35700 "}, new SearchResult () {id = 3, title =" Geo Prism Live 1995 - ABS # 16213899 "}, new SearchResult () {id = 4, title =" JCB excavator JCB- ECU P / N 728 / 35700 "}, new search result () {id = 5, title =" Geo prism geo, geo 1995 - abs # 16213899 geo "}, new search result () {id = 6, title =" dog "},}; Var to_search = new [] {"ground", "jcb"}; Var results go searchResult in = list key_string = to_search.FirstOrDefault (TS = & gt; searchResult.Title.ToLower () include (ts.ToLower ()).) (Group selected key_string) in orderby Group.Count group descending Group searchResult by; Result.ToList () dump () .; } // Here define other methods and classes Public class SearchResult {public int id {get; Set; } Public string title {get; Set; }}   

I get the ID title like the output

  getting the ID title - ------ 1 GO Prism Geo195GO * - ABS # 16213899 3 Geo Prism Live 1995 - ABS # 16213899 5 Geo Prizm Geo, Geo 1995 - ABS # 16213899 Live 2 excavator JCB - ECU P / N: 728/35700 4 JCB excavator JCB- ECU P / N: 728/35700 6 dog   

The above output is OK. All the lines with the normal Geo comes first because the maximum time in most lines means GEO means the word found in 3 rows and the JCB is found in two rows, so the JCB related rows come forward.

I need another type after getting the above output on the whole data .... it is that the Geo rows come first, in which the Geo word is the maximum time in the line ... then my output will appear below

  id title - - ------ 5 Geo Prizm Geo, Geo 1995 - ABS # 16213899 Geo 1 Geo Prizm Geo 1995 Geo * - ABS # 16213899 3 Geo Prism Live 1995 - ABS # 16,213,899 4 JCB Excavator JCB-ECU P / N: 728/35700 2 Excavator JCB - ECU P / N: 728/35700 6 dogs   

I found a Linux query that calculates the count of words in the string

here is the code < Pre> string text = @ "Historically, the world of data and data, the world of objects data"; String search term = "data"; Convert // string to an array of words [] Source = Text. Sample (new letter [] {'.', '?', '!', '', ';', ':', ','}, Stringingsplit option. RemoveEmptyEntries); Var matchQuery = words where word is in the source ToLowerInvariant () == searchTerm.ToLowerInvariant () Select the word; Int wordCount = matchQuery. Count ();

I got this URL from

so let me know how can I change my headline? How to use the second type to count the occurrences of a word in the title field, as a result my output looks like

  id title - ------ 5 Geochemist Geo, GEO 1995 - ABS # 16213899 Geo 1 Geo Prizm Geo 1995 Geo * - ABS # 16213899 3 Geo Prism Live 1995 - ABS # 16213899 4 JCB excavator JCB- ECU P / N: 728/35700 2 excavator JCB - ECU P / N: 728 / 35700 6 dogs    

after this line:

 < Code> var Results = Search to go to the key_string = to_search.firstOrDefault (ts = & gt; searchResult.Title.ToLower ()). This includes (ts.ToLower ()) group search. Sort by group by key_string group in order   

You want something like this:

  foreach (different groups in result) {foreach (var item (theItem = & gt in group.OrderByDescending) ; WordCount (TheItem.Title, group.Key))) {console.WrightLine (item.Title);}}   

with an additional method that looks: < Pre> public static int WordCount (string thunder, c Tring needle) {if (needle == NULL) {return 0; } String [] source = haystack.Split (new char [] {'.', '?', '!', '', ';', ':', ','}, String split option. RemoveEmptyEntries); Var matchQuery = words where word is in the source ToLowerInvariant () == Needle ToLowerInvariant () Select the word; Return matchQuery.Count (); }

Comments