Calculate occurences of phrase in Text Field Django

How can I filter my model MyModel on the basis of the number of occurences of a certain phrase in a text field in MyModel

I guess it can't be done with django orm, perhaps an SQL query can help?

Something like:

MyModal.objects.extra(count="SQL query that finds occurence count of a certain phrase in certain model field")

A complete raw query is fine too.

Answers


try this:

set @str='a b a c';
select length(@str)-length(replace(@str,'a','')) as 'number of occuarence'

Need Your Help

Passing a dynamic array in to functions in C

c arrays function realloc

I'm trying to create a function which takes an array as an argument, adds values to it (increasing its size if necessary) and returns the count of items.

node.js mongodb how to connect to replicaset of mongo servers

node.js mongodb node-mongodb-native

I am using mongo and node.js in an application. The mongo database consists of two servers.