Changeset 2092 in ExiteCMS for trunk/includes/search/search.news.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.news.php

    r2090 r2092  
    1818+---------------------------------------------------------------------*/ 
    1919if (eregi("search.news.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 
     
    152149        } 
    153150 
    154         // check if we have a rowstart value 
    155         if (!isset($rowstart)) $rowstart = 0; 
    156      
    157151        // check how many rows this would output 
    158152        $rptresult = mysql_query($sql.($limit?" LIMIT $limit":"")); 
    159         $variables['rows'] = dbrows($rptresult); 
    160         if ($variables['rows']) { 
    161             $variables['rowstart'] = $rowstart; 
    162             $variables['items_per_page'] = $settings['numofthreads']; 
     153        $rows = dbrows($rptresult); 
    163154 
    164             // now add a query limit, make sure not to overshoot the limit requested 
    165             if ($variables['rows']-$rowstart > $settings['numofthreads']) { 
    166                 $sql .= " LIMIT ".$rowstart.",".$settings['numofthreads']; 
    167             } else { 
    168                 $sql .= " LIMIT ".$rowstart.",".($variables['rows']-$rowstart); 
    169             } 
    170             $rptresult = dbquery($sql); 
     155        // are there any results? 
     156        if ($rows) { 
    171157 
    172             // get the results if any 
    173             if ($variables['rows']) { 
    174                 $reportvars['output'] = array(); 
    175                 while ($rptdata = dbarray($rptresult)) { 
    176                     $reportvars['output'][] = $rptdata; 
     158            // are we interested in these results? 
     159            if ($lines < $settings['numofthreads'] && $rowstart < $variables['rows'] + $rows) { 
     160 
     161                // add a query limit, we might not need all records 
     162                $sql .= " LIMIT ".(max($rowstart-$variables['rows'],0)).",".min($rows,($settings['numofthreads']-$lines)); 
     163 
     164                // launch the query 
     165                $rptresult = dbquery($sql); 
     166 
     167                // get the results if any 
     168                if ($rptresult) { 
     169                    while ($rptdata = dbarray($rptresult)) { 
     170                        $rptdata['_template'] = $data['template']; 
     171                        $reportvars['output'][] = $rptdata; 
     172                    } 
     173 
     174                    // get the score divider for this result set 
     175                    $divider = 0; 
     176                    foreach($reportvars['output'] as $key => $value) { 
     177                        $divider = max($divider, $value['score']); 
     178                    } 
     179 
     180                    // calculate the relevance for this result set 
     181                    foreach($reportvars['output'] as $key => $value) { 
     182                        $reportvars['output'][$key]['relevance'] = $value['score'] / $divider * 100; 
     183                    } 
    177184                } 
    178185 
    179                 // get the score divider for this result set 
    180                 $divider = 0; 
    181                 foreach($reportvars['output'] as $key => $value) { 
    182                     $divider = max($divider, $value['score']); 
    183                 } 
     186            } 
    184187 
    185                 // calculate the relevance for this result set 
    186                 foreach($reportvars['output'] as $key => $value) { 
    187                     $reportvars['output'][$key]['relevance'] = $value['score'] / $divider * 100; 
    188                 } 
    189             } 
     188            // add the amount of rows found to the total rows counter 
     189            $variables['rows'] += $rows; 
     190 
    190191        } 
     192 
    191193    } 
    192194} 
Note: See TracChangeset for help on using the changeset viewer.