I want to get some text analysis. As a result I want to get count of some key words in all records like this:
answer id: 1, text: 'some good text'
answer id: 2, text: 'some really bad text, angry angry angry text'
and result should be like this:
good: 1, bad: 1, angry: 3
I don't want to select all records and then map them count this key words on ruby etc because of big amount of data. Also I find some solution:
Answer.pluck('regexp_matches(text, \'\mMyKeyword\M\', \'gi\')').flatten.count
Works fine for 1 keyword. This causes problem that I used to do database request per keyword. I'm using rails 4 and potgres. Any help appreciated