includes/search.php
changeset 1194 70169f572190
parent 1081 745200a9cc2a
child 1201 9593e62929d1
equal deleted inserted replaced
1193:e3b94bd055dc 1194:70169f572190
   373       $where_req[] = "( $text_col LIKE '%$term%' OR $name_col LIKE '%$term%' )";
   373       $where_req[] = "( $text_col LIKE '%$term%' OR $name_col LIKE '%$term%' )";
   374     }
   374     }
   375     $and_clause = ( $where_any != '' ) ? 'AND ' : '';
   375     $and_clause = ( $where_any != '' ) ? 'AND ' : '';
   376     $where_req = ( count($where_req) > 0 ) ? "{$and_clause}" . implode(" AND\n  ", $where_req) : '';
   376     $where_req = ( count($where_req) > 0 ) ? "{$and_clause}" . implode(" AND\n  ", $where_req) : '';
   377 
   377 
   378     $sql = 'SELECT ' . $concat_column . ' AS id, p.name FROM ' . table_prefix . "page_text AS t\n"
   378     $sql = 'SELECT ' . $concat_column . ' AS id, p.name, t.page_text FROM ' . table_prefix . "page_text AS t\n"
   379             . "  LEFT JOIN " . table_prefix . "pages AS p\n"
   379             . "  LEFT JOIN " . table_prefix . "pages AS p\n"
   380             . "    ON ( p.urlname = t.page_id AND p.namespace = t.namespace )\n"
   380             . "    ON ( p.urlname = t.page_id AND p.namespace = t.namespace )\n"
   381             . "  WHERE p.visible = 1 AND (\n    $where_any\n    $where_req\n  );";
   381             . "  WHERE p.visible = 1 AND (\n    $where_any\n    $where_req\n  );";
   382     if ( !($q = $db->sql_unbuffered_query($sql)) )
   382     if ( !($q = $db->sql_query($sql)) )
   383       $db->_die('Error is in perform_search(), includes/search.php, query 2. Parsed query dump follows:<pre>(indexable) ' . htmlspecialchars(print_r($query, true)) . '(non-indexable) ' . htmlspecialchars(print_r($query_phrase, true)) . '</pre>');
   383       $db->_die('Error is in perform_search(), includes/search.php, query 2. Parsed query dump follows:<pre>(indexable) ' . htmlspecialchars(print_r($query, true)) . '(non-indexable) ' . htmlspecialchars(print_r($query_phrase, true)) . '</pre>');
   384 
   384 
   385     if ( $row = $db->fetchrow() )
   385     if ( $row = $db->fetchrow() )
   386     {
   386     {
   387       do
   387       do
   388       {
   388       {
   389         $id =& $row['id'];
   389         $id =& $row['id'];
   390         $inc = 1;
   390         $inc = 0.0;
   391 
   391 
       
   392         $title = $row['name'];
       
   393         $test_func = ( $case_sensitive ) ? 'strstr' : 'stristr';
       
   394         
   392         // Is this search term present in the page's title? If so, give extra points
   395         // Is this search term present in the page's title? If so, give extra points
   393         preg_match("/^ns=$ns_list;pid=(.+)$/", $pages, $piecesparts);
   396         $word_list = array_merge($query_phrase['any'], $query_phrase['req']);
   394         $title = get_page_title_ns($piecesparts[2], $piecesparts[1]);
   397         foreach ( $word_list as $word )
   395         
   398         {
   396         $test_func = ( $case_sensitive ) ? 'strstr' : 'stristr';
   399           if ( $test_func($title, $word) )
   397         if ( $test_func($title, $row['word']) || $test_func($piecesparts[2], $row['word']) )
   400             $inc += 1.5;
   398         {
   401           else if ( $test_func($row['page_text'], $word) )
   399           $inc = 1.5;
   402             $inc += 1.0;
   400         }
   403         }
   401         
   404         
   402         if ( isset($scores[$id]) )
   405         if ( isset($scores[$id]) )
   403         {
   406         {
   404           $scores[$id] = $scores[$id] + $inc;
   407           $scores[$id] = $scores[$id] + $inc;
   792     if(!empty($words[$i]))
   795     if(!empty($words[$i]))
   793       $words2[] = preg_quote($words[$i]);
   796       $words2[] = preg_quote($words[$i]);
   794   }
   797   }
   795 
   798 
   796   $flag = ( $case_sensitive ) ? '' : 'i';
   799   $flag = ( $case_sensitive ) ? '' : 'i';
   797   $regex = '/(' . implode('|', $words2) . ')/' . $flag;
   800   $regex = '/(' . implode('|', str_replace('/', '\\/', $words2)) . ')/' . $flag;
   798   $pt = preg_replace($regex, '<highlight>\\1</highlight>', $pt);
   801   $pt = preg_replace($regex, '<highlight>\\1</highlight>', $pt);
   799 
   802 
   800   return $pt;
   803   return $pt;
   801 }
   804 }
   802 
   805