title: PHP MySQL Search And Order By Relevancy
body: <p>I know how to do a regular php mysql search and display the results. However, because of the nature of what I'm trying to accomplish I need to be able to sort by relevancy. Let me explain this better:</p>
  
  <p>Normal Query "apple iphone applications" will search the database using %apple iphone application%, but if there aren't records which display that phrase in that exact order the search will produce nothing.</p>
  
  <p>What I basically need to do is search for 'apple', 'iphone' and 'applications' all separately and then merge the results into one, and then I need to grade the relevancy by how many instances of the word are found in the records. For example if I did what I wanted to do and it returned them following:</p>
  
  <pre><code>Iphone Applications From Apple
  Apple Make The Best Apple Iphone Applications
  Iphone Applications
  </code></pre>
  
  <p>They would rank as follows:</p>
  
  <pre><code>Apple Make The Best Apple Iphone Applications
  Iphone Applications From Apple
  Iphone Applications
  </code></pre>
  
  <p>Because of how many instances of the search terms are found. See highlighted:</p>
  
  <pre><code>[Apple] Make The Best [Apple] [Iphone] [Applications]
  [Iphone] [Applications] From [Apple]
  [Iphone] [Applications]
  </code></pre>
  
  <p>I hope I have explained this well enough and I would be extremely grateful if anyone could give me any pointers.</p>