1

在我下面的脚本中,用户输入一个表单,如果行与用户输入的行相似,则从 MYSQL 表中返回行。我正在建立一个搜索引擎,一切都基于排名。但我希望能够调整下面的代码,以查看例如“iPad”一词出现了多少次行字段,即“标题”、“描述”、“关键字”和“链接”。如果是这样,我希望该行返回比具有更高 id 的行更高的返回值,但在所有合并的字段中只提到一次 iPad。我的代码如下:           

  条款一起查询:         

     $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 .= "title LIKE '%{$each}%' OR link LIKE '%{$each}%' OR  keywords LIKE '%{$each}%' OR description LIKE '%{$each}%' ";
}   $query = mysql_query($query) or die('MySQL Query Error: ' . mysql_error( $connect ));
echo '<p class="time">Qlick showed your results in ' . number_format($secs,2) . ' seconds.</p>';     

 $numrows = mysql_num_rows($query);
if ($numrows > 0) {
      
      while ($row = mysql_fetch_assoc($query)) {
            $id = $row['id'];
            $title = $row['title'];
            $description = $row['description'];
            $keywords = $row['keywords'];
            $link = $row['link'];
            $rank = $row['rank'];

                         分词查询

               

          $query = " SELECT * FROM scan WHERE "; 
    $terms = array_map('mysql_real_escape_string', $terms);
    $i = 0; 
    foreach ($terms as $each) {
          if ($i++ !== 0){
                $query .= " OR "; 
          }
          $query .= "title LIKE '%{$each}%' OR link LIKE '%{$each}%' OR  keywords LIKE '%{$each}%' OR description LIKE '%{$each}%' ";
      }
    // Don't append the ORDER BY until after the loop
            $query = mysql_query($query) or die('MySQL Query Error: ' . mysql_error( $connect ));
    $numrows = mysql_num_rows($query);
    if ($numrows > 0) {
            
          while ($row = mysql_fetch_assoc($query)) {
                $id = $row['id'];
                $title = $row['title'];
                $description = $row['description'];
                $keywords = $row['keywords'];
                $link = $row['link'];
                $rank = $row['rank'];

        

4

1 回答 1

0

保持简单愚蠢

为什么没有字段“等级”。

计算包含该术语的字段数并将其保存在排名字段中

于 2012-09-27T19:33:36.290 回答