Loading...
 

common - wiki - search functionality

Промени в системата за търсене

Разлики между функционалност и задание

Задание:
1. Търсенето да е case-insensitive и да може да се търси и по част от дума, както и по израз, по няколко думи, които не са поредни
2. В резултатите да се показват резултатите, като само търсеният стринг е подчертан и без да има объркани тагове (незатворени болд табгове и т.н.)
3. При отваряне на конкретна страница от резултатите за търсене пак да се подвертава търсеният стринг в текста на страницата.

Неща от заданието, които не са постигнати:
При търсене на повече от 1 дума намерените думи не винаги се виждат подчертани в извадката от текста на страницата в списъка с резултати от търсенето, но като се отвори самата страница са подчертани правилно.

Промени в кода

tiki-listpages.php

редове 327-330 и 333 - коментирани, за да не прави exact_match, а да търси и по част от думата

tililib.php

започвайки от ред 3379

                if $f {//look for space...
//                    $mid = " where LOWER(`pageName`) like LOWER('click="javascript:toggle_dynamic_var("$find");" title="Click to edit dynamic variable: $find">NaV')";
                    $mid = " where LOWER(`pageName`) like LOWER('NaV') OR LOWER(tp.`data`) LIKE LOWER('NaV') "; //Modified By Tihomir Tenchev
                } else {
                    $findop = $forListPages ? ' AND' : ' OR';
//                    $mid = " where LOWER(`pageName`) like ".implode($findop . ' LOWER(`pageName`) like ', array_fill(0, count($f), 'LOWER(?)'));
                    $mid = " where LOWER(`pageName`) like ".implode($findop . ' LOWER(`pageName`) like ', array_fill(0, count($f), 'LOWER(?)')) .
                                                " OR LOWER(tp.`data`) like ".implode($findop . ' LOWER(tp.`data`) like ', array_fill(0, count($f), 'LOWER(?)')); //Modified By Tihomir Tenchev
                    $bindvars = $f;
                                        foreach ($f as $f1) {
                                            array_push($bindvars,$f1);
                                        }

също така във функцията get_snippet след if ($prefs'search_parsed_snippet' == 'y') {...} следващия IF се заменя с

        $data = strip_tags($data);
                $highlight = trim($highlight);
                if ($highlight != '') {
                    $offset = ($length > 0)?(int) $length/2:100;
                    if (mb_stripos(' ',$highlight) !== false) {
                        foreach " ",$highlight) as $k=>$hl) {
                            if (mb_stripos($data, $hl) !== false) {
                                $s_start = max(mb_stripos($data, $hl)-$offset,0);
                                $s_end = min(mb_stripos($data, $hl)+$offset,mb_strlen($data
;
                                $data = mb_substr($data,$s_start,($s_end-$s_start)-1);
//                                return $ret;
//                                return preg_replace("~$hl~ui", ''.$hl.'', $ret);
                            }
                        }
                    
                    } else {
                            $hl=  mb_strtolower($highlight);
                            $start = max(mb_stripos($data, $hl)-$offset,0);
                            $end = min(mb_stripos($data, $hl)+$offset,mb_strlen($data));
                            $data = mb_substr($data,$start,($end-$start)-1);
//                            return $ret;
//                            return preg_replace("~$hl~ui", ''.$hl.'', $ret);
                         
                    }
                    return $data;
                }

и в lib/smarty_tiki/outputfilter.highlight.php ървите две функции се заменят с:

function smarty_outputfilter_highlight($source, $smarty)
{
    global $prefs;

    if $_REQUEST'highlight' {
            if $_REQUEST'find'
        return $source;
            else
                $_REQUEST'highlight' = $_REQUEST'find';
    }
    if (!strstr($source, 'id="tiki-center"')) {
        return $source;
    }
    $highlight = $_REQUEST'highlight';

    if | $_REQUEST'boolean' == 'y' {
        $highlight = str_replace'(', ')', '*', '-', '"', '~', '<', '>'), ' ', $highlight);
    }

    if | empty($highlight        return $source;
    }

    $matches = array();

    $end = 0;

    if ( $end = strrpos($source, 'id="col2"') )
        $stop_pattern = '(

*\s+id="col2".*)';
    elseif ( $end = strrpos($source, 'id="col3"') )
        $stop_pattern = '(

^>*\s+id="col3".*)';
    else
        $stop_pattern = ;

    $result = false;

    if ( function_exists('mb_eregi') ) {
        // UTF8 support enabled
        $result = mb_eregi('^(.*\s+id="tiki-center"*>)(.*)' . $stop_pattern . '$', $source, $matches);
    } else {
        // We do not fallback on the preg_match function, since it is limited by 'pcre.backtrack_limit' which is too low by default (100K)
        //  and this script will not be allowed to change its value on most systems
        //
        if ( ( $start = strpos($source, 'id="tiki-center"') ) > 0 ) {
            $matches = array(
                $source,
                substr($source, 0, $start),
                ( $end > $start ? substr($source, $start, $end - $start) : substr($source, $start) ),
                ( $end > $start ? substr($source, $end) :
)
            );
            $result = true;
        }
    }

    if ( ! $result )
        return $source;
    if ) > ini_get('pcre.backtrack_limit' {
        return $source;
    }

    if ( ! isset( $matches ) )
        $matches = ;

    // Avoid highlight parsing in unknown cases where $matches is empty, which will result in an empty page.
    if ( $matches !=
)
//                $source = $matches;
//                foreach (explode(" ",$highlight) as $k=>$hl) {
//                    if (!empty($hl) && mb_stripos($source, $hl) !== false) {
//                        $source = preg_replace("/$hl/ui",'^>*nohighlight.*

# div with nohightlight
        |                       # script blocks
        |*onmouseover.*onmouseout*>           # onmouseover (user popup)
        |<*>                                        # all html tags
        |(' . _enlightColor($highlight) . '))~xsmiu',
            '_enlightColor',
            $matches
        );

    return $matches.$source.$matches;
}

function _enlightColor($matches)
{
    static $colword = array();
    if (is_string($matches)) { // just to set the color array
        // Wrap all the highlight words with tags bolding them and changing
        // their background colors
        $i = 0;
        $seaword = $seasep = ;
        $wordArr = preg_split('~%20|\+|\s+~', $matches);
        foreach ($wordArr as $word) {
            if ($word ==
)
                continue;
            $seaword .= $seasep.preg_quote($word, '~');
            $seasep ='|';
            $colword = 'highlight_word_'.$i%5;
            $i++;
        }
        return $seaword;
    }
    // actual replacement callback
    if {
        return '1)" rel="">mb_strtolower($matches


Contributors to this page: petar and tisho .
Page last modified on Thursday 05 of February, 2015 14:34:39 UTC by petar.