title: PostgreSQL Full Text Search - Ranking search results based on their position in the search value
body: <p>Considering keywords like <code>tablet</code> and <code>phone</code> are to be searched for within a specific sentence like <code>Looking for tablets and phones</code>.</p>
  <p>Even though when we do</p>
  <pre class="lang-sql prettyprint-override"><code>select to_tsvector('english', 'Looking for tablets and phones')
  </code></pre>
  <p>it returns the lexemes along with their positions</p>
  <pre><code>'look':1 'phone':5 'tablet':3
  </code></pre>
  <p>When I try to rank them, it gives the same rank value for both keywords.</p>
  <pre class="lang-sql prettyprint-override"><code>select keyword, ts_rank(tsv, tsq, 1) as rank
  from 
      to_tsvector('english', 'Looking for tablets and phones') tsv,
      (values
          ('phone' , to_tsquery('english', 'phone')),
          ('tablet', to_tsquery('english', 'tablet'))
      ) as d (keyword, tsq)
  order by rank desc
  </code></pre>
  <p>Output:</p>
  <pre><code> keyword |    rank
  ---------+-------------
   phone   | 0.030396355
   tablet  | 0.030396355
  </code></pre>
  <p>How can I rank the keywords according to their occurrence position?</p>