Ignore:
Timestamp:
12/07/08 01:25:48 (3 years ago)
Author:
WanWizard
Message:

updated the module search plugin to work with the new 'search entire site' option

File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/common/wiki/php-files/modules/wiki/search.wiki.php

    r2091 r2097  
    3434$headerparms = '    <link rel="stylesheet" type="text/css" href="'.$wakka->GetConfigValue("stylesheet").'" />'; 
    3535 
    36 // array to store variables we want to use in the search template 
    37 $reportvars = array(); 
    38  
    3936// set the page title 
    40 $title = $locale['424']; 
     37if ($search_id != 99999) $title = $locale['424']; 
    4138 
    4239// make sure we have an action variable 
     
    148145        } 
    149146 
    150         // check if we have a rowstart value 
    151         if (!isset($rowstart)) $rowstart = 0; 
    152  
    153147        // check how many rows this would output 
    154148        $rptresult = mysql_query($sql.($limit?" LIMIT $limit":"")); 
    155         $variables['rows'] = dbrows($rptresult); 
    156         if ($variables['rows']) { 
    157             // store some row counter for the pager 
    158             $variables['rowstart'] = $rowstart; 
    159             $variables['items_per_page'] = $settings['numofthreads']; 
    160  
    161             // now add a query limit, make sure not to overshoot the limit requested 
    162             if ($variables['rows']-$rowstart > $settings['numofthreads']) { 
    163                 $sql .= " LIMIT ".$rowstart.",".$settings['numofthreads']; 
    164             } else { 
    165                 $sql .= " LIMIT ".$rowstart.",".($variables['rows']-$rowstart); 
    166             } 
    167             $rptresult = dbquery($sql); 
    168  
    169             // get the results if any 
    170             if ($variables['rows']) { 
    171                 $reportvars['output'] = array(); 
    172                 $i=0; 
    173                 while ($rptdata = dbarray($rptresult)) { 
    174                     if ($wakka->HasAccess("read",$rptdata["tag"])) { 
    175                         $rptdata['access'] = true; 
    176                         // display portion of the matching body and highlight the search term */  
    177                         preg_match_all("/(.{0,120})($stext)(.{0,120})/is",$rptdata['body'],$matchString); 
    178                         if (count($matchString[0]) > 3) 
    179                         { 
    180                             $matchString[0] = array_splice($matchString[0], 3, count($matchString)); 
     149        $rows = dbrows($rptresult); 
     150 
     151        // are there any results? 
     152        if ($rows) { 
     153 
     154            // are we interested in these results? 
     155            if ($lines < $settings['numofthreads'] && $rowstart < $variables['rows'] + $rows) { 
     156 
     157                // add a query limit, we might not need all records 
     158                $sql .= " LIMIT ".(max($rowstart-$variables['rows'],0)).",".min($rows,($settings['numofthreads']-$lines)); 
     159 
     160                // launch the query 
     161                $rptresult = dbquery($sql); 
     162 
     163                // get the results if any 
     164                if ($rptresult) { 
     165                    while ($rptdata = dbarray($rptresult)) { 
     166                        if ($wakka->HasAccess("read",$rptdata["tag"])) { 
     167                            $rptdata['access'] = true; 
     168                            // display portion of the matching body and highlight the search term */  
     169                            preg_match_all("/(.{0,120})($stext)(.{0,120})/is",$rptdata['body'],$matchString); 
     170                            if (count($matchString[0]) > 3) 
     171                            { 
     172                                $matchString[0] = array_splice($matchString[0], 3, count($matchString)); 
     173                            } 
     174                            $text = $wakka->htmlspecialchars_ent(implode('<br />', $matchString[0])); 
     175                            $text = str_replace('&lt;br /&gt;', '&hellip;<br />&hellip;', $text); 
     176                            // CSS-driven highlighting, tse stands for textsearchexpanded. We highlight $text in 2 steps,  
     177                            // We do not use <span>..</span> with preg_replace to ensure that the tag `span' won't be replaced if 
     178                            // $phrase contains `span'. 
     179                            $highlightMatch = preg_replace('/('.$wakka->htmlspecialchars_ent($stext).')/i','<<$1>>',$text,-1); // -1 = no limit (default!) 
     180                            $rptdata['snippet'] = "&hellip;".str_replace(array('<<', '>>'), array('<span class="tse_keywords">', '</span>'), $highlightMatch)."&hellip;"; 
     181                        } else { 
     182                            $rptdata['access'] = false; 
     183                            $rptdata['snippet'] = $locale['427']; 
    181184                        } 
    182                         $text = $wakka->htmlspecialchars_ent(implode('<br />', $matchString[0])); 
    183                         $text = str_replace('&lt;br /&gt;', '&hellip;<br />&hellip;', $text); 
    184                         // CSS-driven highlighting, tse stands for textsearchexpanded. We highlight $text in 2 steps,  
    185                         // We do not use <span>..</span> with preg_replace to ensure that the tag `span' won't be replaced if 
    186                         // $phrase contains `span'. 
    187                         $highlightMatch = preg_replace('/('.$wakka->htmlspecialchars_ent($stext).')/i','<<$1>>',$text,-1); // -1 = no limit (default!) 
    188                         $rptdata['snippet'] = "&hellip;".str_replace(array('<<', '>>'), array('<span class="tse_keywords">', '</span>'), $highlightMatch)."&hellip;"; 
    189                     } else { 
    190                         $rptdata['access'] = false; 
    191                         $rptdata['snippet'] = $locale['427']; 
     185                        $rptdata['_template'] = $data['template']; 
     186                        $reportvars['output'][] = $rptdata; 
    192187                    } 
    193                     $reportvars['output'][] = $rptdata; 
     188 
     189                    // get the score divider for this result set 
     190                    $divider = 0; 
     191                    foreach($reportvars['output'] as $key => $value) { 
     192                        $divider = max($divider, $value['score']); 
     193                    } 
     194 
     195                    // calculate the relevance for this result set 
     196                    foreach($reportvars['output'] as $key => $value) { 
     197                        $reportvars['output'][$key]['relevance'] = $value['score'] / $divider * 100; 
     198                    } 
    194199                } 
    195200 
    196                 // get the score divider for this result set 
    197                 $divider = 0; 
    198                 foreach($reportvars['output'] as $key => $value) { 
    199                     $divider = max($divider, $value['score']); 
    200                 } 
    201  
    202                 // calculate the relevance for this result set 
    203                 foreach($reportvars['output'] as $key => $value) { 
    204                     $reportvars['output'][$key]['relevance'] = $value['score'] / $divider * 100; 
    205                 } 
    206             } 
    207         } 
     201            } 
     202 
     203            // add the amount of rows found to the total rows counter 
     204            $variables['rows'] += $rows; 
     205 
     206        } 
     207 
    208208    } 
    209209} 
Note: See TracChangeset for help on using the changeset viewer.