Sort the web search by no of appearance

I need you’re an urgent help… I am doing web search in one of my application using “$$SearchTemplate for ”. Its working fine and returning the correct result. The problem here is, I need to sort the result in ascending order by the no. of appearance of the search query in the document.

For example:

My Search Query is say “John”. Its returning all the documents which have a word called John. But I need to sort all the documents which have “John” more times and show it in ascending order.

In the document, I am keeping a field called “searchQuery”, where I have storing the search query text against which “$$SearchTemplate” searching and showing the documents.

Any kind of suggestion is welcome. Let me know, if you need any further clarification.

Thanks n’ regards,

Piyush