full text ranking
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/12679751/how-to-have-ranking-based-on-how-many-words-match-user-input">how to have ranking based on how many words match user input</a>  </p>
</blockquote>



<p>How can I have a search engine ranked by amount of words that are typed in and ranked by the amount of types they crop up in the fields title, description, keywords, link. </p>

<p>So the higher results are ordered by having more of the words that the user submitted. Say if the user typed in iPhone, iPhone key word crops up in the link, description and title field, so that would be ranked higher than say Apple which mentions it only in the description and Apple Store which mentions it in the title and the description. </p>

<p>My code is below:</p>

<pre><code> $query = " SELECT * FROM scan WHERE "; 

 $terms = array_map('mysql_real_escape_string', $terms);
 $i = 0; 
 foreach ($terms as $each) {
  if ($i++ !== 0){
        $query .= " AND "; 
  }
  $query .= "Match(title, description, keywords, link) Against ('".implode(' ',$terms)." IN BOOLEAN MODE') ";
  } 
  $secs = microtime();  



$query = mysql_query($query) or die('MySQL Query Error: ' . mysql_error( $connect ));

echo '&lt;p class="time"&gt;Qlick showed your results in ' . number_format($secs,2) . ' seconds.&lt;/p&gt;';     

 $numrows = mysql_num_rows($query);
if ($numrows &gt; 0) {

      while ($row = mysql_fetch_assoc($query)) {
            $id = $row['id'];
            $title1 = $row['title'];
            $description = $row['description'];
            $keywords = $row['keywords'];
            $link = $row['link'];
            $rank = $row['rank'];
          $title = substr($title1,0,60);

        echo '&lt;h2&gt;&lt;a class="ok" href="' . $link . '"&gt;' . $title . '&lt;/a&gt;&lt;/h2&gt;' . PHP_EOL;
                    echo '&lt;p class="kk"&gt;' . $description . '&lt;br&gt;&lt;br&gt;&lt;span class="keywords"&gt;' . PHP_EOL;            
                    echo '&lt;p&gt;&lt;a class="okay" href="' . $link . '"&gt;' . $link . '&lt;br&gt;&lt;br&gt;&lt;span class="keywords"&gt;' . PHP_EOL;
                      }
</code></pre>
