title: How-to: Ranking Search Results
body: <p>I have a webapp development problem that I've developed one solution for, but am trying to find other ideas that might get around some performance issues I'm seeing.</p>
  
  <p>problem statement: </p>
  
  <ul>
  <li>a user enters several keywords/tokens</li>
  <li>the application searches for matches to the tokens</li>
  <li>need one result for each token
  
  <ul>
  <li>ie, if an entry has 3 tokens, i need the entry id 3 times</li>
  </ul></li>
  <li>rank the results
  
  <ul>
  <li>assign X points for token match</li>
  <li>sort the entry ids based on points</li>
  <li>if point values are the same, use date to sort results</li>
  </ul></li>
  </ul>
  
  <p>What I want to be able to do, but have not figured out, is to send 1 query that returns something akin to the results of an in(), but returns a duplicate entry id for each token matches for each entry id checked.</p>
  
  <p>Is there a better way to do this than what I'm doing, of using multiple, individual queries running one query per token? If so, what's the easiest way to implement those?</p>
  
  <p><strong>edit</strong><br>
  I've already tokenized the entries, so, for example, "see spot run" has an entry id of 1, and three tokens, 'see', 'spot', 'run', and those are in a separate token table, with entry ids relevant to them so the table might look like this:</p>
  
  <pre><code>'see', 1 
  'spot', 1 
  'run', 1 
  'run', 2 
  'spot', 3 
  </code></pre>