Count word occurrences in a text field with LINQ

Posted by Yoann. B on Stack Overflow See other posts from Stack Overflow or by Yoann. B
Published on 2009-10-17T16:18:12Z Indexed on 2010/05/20 15:10 UTC
Read the original article Hit count: 274

Filed under:
|
|

How can i get the occurrences count of a Word in a database text field With LINQ ?

Keyword token sample : ASP.NET

EDIT 4 :

Database Records :

Record 1 : [TextField] = "Blah blah blah ASP.NET bli bli bli ASP.NET blu ASP.NET yop yop ASP.NET"

Record 2 : [TextField] = "Blah blah blah bli bli bli blu ASP.NET yop yop ASP.NET"

Record 3 : [TextField] = "Blah ASP.NET blah ASP.NET blah ASP.NET bli ASP.NET bli bli ASP.NET blu ASP.NET yop yop ASP.NET"

So

Record 1 Contains 4 occurrence of "ASP.NET" keyword

Record 2 Contains 2 occurrence of "ASP.NET" keyword

Record 3 Contains 7 occurrence of "ASP.NET" keyword

Collection Extraction IList < RecordModel > (ordered by word count descending)

  • Record 3
  • Record 1
  • Record 2

LinqToSQL should be the best, but LinqToObject too :)

NB : No issue about the "." of ASP.NET keyword (this is not the goal if this question)

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about pattern-matching