function getBody() { $ret = $this->smarty->fetch('service/' . $this->props['lang'] . '/search.form.tpl'); $max_per_page = 20; $this->page = CUtils::_getVar('page', true, 1); if (CUtils::_getVar('text')) { $search_array = array(); $simple_search_array = explode(' ', CUtils::_getVar('text')); foreach ($simple_search_array as $ssa) { inc_lib('tools/stemming/stemming.php'); $ssa = PorterStem::stemming($ssa); $search_array[] = $ssa; } if (count($search_array)) { $results = $this->getResults($search_array); } else { $results = $this->getResults(addslashes($this->text)); } $this->smarty->assign('search_text', addslashes(CUtils::_getVar('text'))); if (sizeof($results) > 0) { $pages_cnt = ceil(sizeof($results) / $max_per_page); if ($pages_cnt > 1) { $pages = '<div>'; if ($this->page > 1) { $ref = '?text=' . urlencode(CUtils::_getVar('text')) . '&page=' . ($this->page - 1); $pages .= '<a title="назад" href="' . $ref . '">←</a>'; } for ($i = 1; $i <= $pages_cnt; $i++) { $pages .= $i == $this->page ? ' ' . $i . ' ' : ' <a href="?text=' . urlencode(CUtils::_getVar('text')) . '&page=' . $i . '">' . $i . '</a> '; } if ($this->page < $pages_cnt) { $ref = '?text=' . urlencode(CUtils::_getVar('text')) . '&page=' . ($this->page + 1); $pages .= '<a title="вперед" href="' . $ref . '">→</a>'; } $pages .= '</div>'; $this->smarty->assign('ptext', $pages); } if ($this->page == $pages_cnt && sizeof($results) % $max_per_page > 0) { $max_per_page_cur = count($results) % $max_per_page; } else { $max_per_page_cur = $max_per_page; } $items = array(); for ($i = 1; $i <= $max_per_page_cur; $i++) { $j = $i + ($this->page - 1) * $max_per_page; $results[$j - 1]['num'] = $j; $items[] = $results[$j - 1]; } $this->smarty->assign('items', $items); $ret .= $this->smarty->fetch('service/' . $this->props['lang'] . '/search.list.tpl'); } else { $ret .= $this->smarty->fetch('service/' . $this->props['lang'] . '/search.no.tpl'); } } return $ret; }
public static function stemming($word) { // RUSSIAN DIRTY LOWERCASE: $word = PorterStem::rustolower($word); $a = PorterStem::rv($word); $start = $a[0]; $rv = $a[1]; $rv = PorterStem::step1($rv); $rv = PorterStem::step2($rv); $rv = PorterStem::step3($rv); $rv = PorterStem::step4($rv); return $start . $rv; }