Changeset 2092 in ExiteCMS for trunk/includes/search/search.pm.php


Ignore:
Timestamp:
12/05/08 20:23:35 (3 years ago)
Author:
WanWizard
Message:

ticket #58: added "search entire site" to the search module
added missing svn properties to several files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/search/search.pm.php

    r2090 r2092  
    1818+---------------------------------------------------------------------*/ 
    1919if (eregi("search.forumposts.php", $_SERVER['PHP_SELF']) || !defined('INIT_CMS_OK')) die(); 
    20  
    21 // array to store variables we want to use in the search template 
    22 $reportvars = array(); 
    2320 
    2421// make sure we have an action variable 
     
    133130        } 
    134131 
    135         // check if we have a rowstart value 
    136         if (!isset($rowstart)) $rowstart = 0; 
    137  
    138132        // check how many rows this would output 
    139133        $rptresult = mysql_query($sql.($limit?" LIMIT $limit":"")); 
    140         $variables['rows'] = dbrows($rptresult); 
    141         if ($variables['rows']) { 
    142             $variables['rowstart'] = $rowstart; 
    143             $variables['items_per_page'] = $settings['numofthreads']; 
    144  
    145             // now add a query limit, make sure not to overshoot the limit requested 
    146             if ($variables['rows']-$rowstart > $settings['numofthreads']) { 
    147                 $sql .= " LIMIT ".$rowstart.",".$settings['numofthreads']; 
    148             } else { 
    149                 $sql .= " LIMIT ".$rowstart.",".($variables['rows']-$rowstart); 
    150             } 
    151             $rptresult = dbquery($sql); 
    152  
    153             // get the results if any 
    154             if ($variables['rows']) { 
    155                 $pmfolders = array($locale['src519'], $locale['src520'], $locale['src521']); 
    156                 $reportvars['output'] = array(); 
    157                 while ($rptdata = dbarray($rptresult)) { 
    158                     $rptdata['folder'] = $pmfolders[$rptdata['pmindex_folder']]; 
    159                     // get the information for the recipient(s) 
    160                     $rptdata['recipients'] = array(); 
    161                     if ($rptdata['pmindex_folder'] == 0 || ($rptdata['pmindex_folder'] == 2 && $rptdata['pmindex_user_id'] != $rptdata['pmindex_from_id'])) { 
    162                         // incomming, get the sender info 
    163                         $result2 = dbquery("SELECT 0 as is_group, user_name AS name FROM ".$db_prefix."users WHERE user_id = '".$rptdata['pmindex_from_id']."'"); 
    164                         if ($data2 = dbarray($result2)) { 
    165                             $rptdata['recipients'][] = $data2; 
    166                         } 
    167                     } elseif ($rptdata['pmindex_folder'] == 1 || ($rptdata['pmindex_folder'] == 2 && $rptdata['pmindex_user_id'] == $rptdata['pmindex_from_id'])) { 
    168                         // outgoing, get the recepient info 
    169                         $recipients = explode(",", $rptdata['pm_recipients']); 
    170                         foreach ($recipients as $recipient) { 
    171                             if ($recipient < 0) { 
    172                                 // recipient is a user group 
    173                                 $result2 = dbquery("SELECT 1 as is_group, group_id AS id, group_name AS name, group_visible AS visible FROM ".$db_prefix."user_groups WHERE group_id = '".abs($recipient)."'"); 
    174                                 if ($data2 = dbarray($result2)) { 
    175                                     $data2['visible'] = $data2['visible'] & pow(2, 0); 
    176                                     $rptdata['recipients'][] = $data2; 
    177                                 } 
    178                             } else { 
    179                                 // recipient is a single member 
    180                                 $result2 = dbquery("SELECT 0 as is_group, user_id AS id, user_name AS name FROM ".$db_prefix."users WHERE user_id = '".$recipient."'"); 
    181                                 if ($data2 = dbarray($result2)) { 
    182                                     $data2['visible'] = iMEMBER; 
    183                                     $rptdata['recipients'][] = $data2; 
     134        $rows = dbrows($rptresult); 
     135 
     136        // are there any results? 
     137        if ($rows) { 
     138 
     139            // are we interested in these results? 
     140            if ($lines < $settings['numofthreads'] && $rowstart < $variables['rows'] + $rows) { 
     141 
     142                // add a query limit, we might not need all records 
     143                $sql .= " LIMIT ".(max($rowstart-$variables['rows'],0)).",".min($rows,($settings['numofthreads']-$lines)); 
     144 
     145                // launch the query 
     146                $rptresult = dbquery($sql); 
     147 
     148                // get the results if any 
     149                if ($rptresult) { 
     150                    $pmfolders = array($locale['src519'], $locale['src520'], $locale['src521']); 
     151                    while ($rptdata = dbarray($rptresult)) { 
     152                        $rptdata['folder'] = $pmfolders[$rptdata['pmindex_folder']]; 
     153                        // get the information for the recipient(s) 
     154                        $rptdata['recipients'] = array(); 
     155                        if ($rptdata['pmindex_folder'] == 0 || ($rptdata['pmindex_folder'] == 2 && $rptdata['pmindex_user_id'] != $rptdata['pmindex_from_id'])) { 
     156                            // incomming, get the sender info 
     157                            $result2 = dbquery("SELECT 0 as is_group, user_name AS name FROM ".$db_prefix."users WHERE user_id = '".$rptdata['pmindex_from_id']."'"); 
     158                            if ($data2 = dbarray($result2)) { 
     159                                $rptdata['recipients'][] = $data2; 
     160                            } 
     161                        } elseif ($rptdata['pmindex_folder'] == 1 || ($rptdata['pmindex_folder'] == 2 && $rptdata['pmindex_user_id'] == $rptdata['pmindex_from_id'])) { 
     162                            // outgoing, get the recepient info 
     163                            $recipients = explode(",", $rptdata['pm_recipients']); 
     164                            foreach ($recipients as $recipient) { 
     165                                if ($recipient < 0) { 
     166                                    // recipient is a user group 
     167                                    $result2 = dbquery("SELECT 1 as is_group, group_id AS id, group_name AS name, group_visible AS visible FROM ".$db_prefix."user_groups WHERE group_id = '".abs($recipient)."'"); 
     168                                    if ($data2 = dbarray($result2)) { 
     169                                        $data2['visible'] = $data2['visible'] & pow(2, 0); 
     170                                        $rptdata['recipients'][] = $data2; 
     171                                    } 
     172                                } else { 
     173                                    // recipient is a single member 
     174                                    $result2 = dbquery("SELECT 0 as is_group, user_id AS id, user_name AS name FROM ".$db_prefix."users WHERE user_id = '".$recipient."'"); 
     175                                    if ($data2 = dbarray($result2)) { 
     176                                        $data2['visible'] = iMEMBER; 
     177                                        $rptdata['recipients'][] = $data2; 
     178                                    } 
    184179                                } 
    185180                            } 
    186181                        } 
     182                        $rptdata['_template'] = $data['template']; 
     183                        $reportvars['output'][] = $rptdata; 
    187184                    } 
    188                     $reportvars['output'][] = $rptdata; 
     185 
     186                    // get the score divider for this result set 
     187                    $divider = 0; 
     188                    foreach($reportvars['output'] as $key => $value) { 
     189                        $divider = max($divider, $value['score']); 
     190                    } 
     191 
     192                    // calculate the relevance for this result set 
     193                    foreach($reportvars['output'] as $key => $value) { 
     194                        $reportvars['output'][$key]['relevance'] = $value['score'] / $divider * 100; 
     195                    } 
    189196                } 
    190197 
    191                 // get the score divider for this result set 
    192                 $divider = 0; 
    193                 foreach($reportvars['output'] as $key => $value) { 
    194                     $divider = max($divider, $value['score']); 
    195                 } 
    196  
    197                 // calculate the relevance for this result set 
    198                 foreach($reportvars['output'] as $key => $value) { 
    199                     $reportvars['output'][$key]['relevance'] = $value['score'] / $divider * 100; 
    200                 } 
    201             } 
    202 //          _debug($reportvars, true); 
    203         } 
     198            } 
     199 
     200            // add the amount of rows found to the total rows counter 
     201            $variables['rows'] += $rows; 
     202 
     203        } 
     204 
    204205    } 
    205206} 
Note: See TracChangeset for help on using the changeset viewer.