title: How to Order by relevance in a SQL query in Rails?
body: <p>I am using a SQL query for a specified and faster search in my Rails app, currently I have the following query that works wonderfully for gathering the data from the initial search:</p>
  
  <p><code>SELECT * FROM selected_tables 
      WHERE field1 LIKE '%#{present_param}'
      AND field2 LIKE '%#{present_param2}'
  </code></p>
  
  <p>And so on like that, with each LIKE line only appearing if the relevant parameter is present from the form.</p>
  
  <p>So I am now able to get back a large amount of results from this query, but they're not ordered in any helpful way. I need some way of ordering the results based on their relevance to the original user input from the form, but I can't seem to find anything on google about it. Is there a way in SQL (specifically postgresql) that I can order the results based on this?</p>
  
  <p>To be clear, when I say relevance I mean that a given search keyword should be in the title or company name for the result, not just present somewhere in the content.</p>
  
  <p>For example: if you search "Sony" you get Sony Electronics first, not another listing containing Sony somewhere in the middle of its name.</p>