Order by most matched records first : <p>Given the following query:</p>

<pre><code>select * from users 
where first_name ilike '%foo%' 
OR last_name ilike '%bar%' 
OR nickname ilike '%foobar%'
</code></pre>

<p>Returns:</p>

<pre><code> first_name| last_name   |  nickname
----------------------------------------
  Foo      | ABC         |   abcd
  Foo      | DEF         |   efgh
  Foo      | BAR         |   ijkl
  AMD      | Bar         |   foobar
  Foo      | Bar         |   foobar2
</code></pre>

<p><strong>Question:</strong></p>

<p>How to sort most relevant (matched) values first?
I mean by most matched that matches more than one pattern inside <code>Where .. OR</code> </p>

<p><strong>Expected Result:</strong></p>

<pre><code> first_name| last_name   |  nickname
----------------------------------------
  Foo      | Bar         |   foobar2
  Foo      | BAR         |   ijkl
  AMD      | Bar         |   foobar
  Foo      | ABC         |   abcd
  Foo      | DEF         |   efgh
</code></pre>
