Options -Indexes <Files ~ "\.(php|php3|php4|php5|pl|cgi|sh|bash)$"> Deny from all </Files>
require_once('{ }/src/common.php'); $dir = '{ , }/dicts'; $lang = 'ru_RU'; $opts = array( 'storage' => PHPMORPHY_STORAGE_FILE, ); try { $morphy = new phpMorphy($dir, $lang, $opts); } catch(phpMorphy_Exception $e) { die('Error occured while creating phpMorphy instance: ' . $e->getMessage()); }
class Model_Searchindex extends ORM { protected $_table_name = 'searchindex'; }
Route::set('index', 'updateindex(/<offset>)') ->defaults(array( 'directory' => 'admin', 'controller' => 'updateindex', 'action' => 'index', ));
$offset = $this->request->param('offset'); // if ($offset == 1) { $index = DB::query(Database::DELETE, 'DELETE FROM `searchindex`'); $index->execute(); } $data = array(); // $posts = ORM::factory('post')->where('delete', '=', 0)->offset(100*$offset)->limit(100)->find_all(); foreach ($posts as $post) { $words = array(); // html, $title = mb_strtoupper(str_ireplace("", "", strip_tags($post->title)), "UTF-8"); $comments = ORM::factory('comment')->where('post_id', '=', $post->id)->order_by('id', 'ASC')->find_all(); // , $text = $post->text; if ($post->type == 1) { // , . , ... } foreach ($comments as $comment) { // , $text = $text.' '.$comment->text; } $text = mb_strtoupper (str_ireplace("", "", strip_tags($text)), "UTF-8"); preg_match_all ('/([a-z-]+)/ui', $title, $word_title); // preg_match_all ('/([a-z-]+)/ui', $text, $word_text); // , => $start_form_title = $morphy->lemmatize($word_title[1]); $start_form_text = $morphy->lemmatize($word_text[1]); foreach ($start_form_title as $k=>$w) { if (!$w) { // , $w[0] = $k; } if (mb_strlen($w[0], "UTF-8") > 2) // , { if (! isset ( $words[$w[0]]))$words[$w[0]] = 0; $words[$w[0]]+= 3; // } } foreach ($start_form_text as $k=>$w) { // } // foreach ($words as $word=>$weight) { $data['post_id'] = $post->id; $data['word'] = $word; $data['weight'] = $weight; $addindex = ORM::factory('searchindex'); $addindex->values($data); try { $addindex->save(); } catch (ORM_Validation_Exception $e) { $errors = $e->errors('validation'); } } } /* json, , */ $pcount = ORM::factory('post')->where('delete', '=', 0)->count_all(); if (($pcount - (100*$offset)) > 0) { $complateu = ($offset) * 100; $percent = ($complateu / $pcount) * 100; $percent = round($percent, 0); $json = array('status'=>'next', 'nextid'=>1+$offset, 'percent'=>$percent); $this->response->body(json_encode($json)); } else { $json = array('status'=>'finish', 'percent'=>100); $this->response->body(json_encode($json)); }
public function action_search() { $data = null; $request = null; $errors = null; if (!empty($_GET['text'])) // { // html- $search = $this->_clear_var($_GET['text']); $request = $search; } /* phpMorphy */ if (!empty($search)) { // if (mb_strlen($search, "UTF-8") > 2) { preg_match_all('/([a-z-]+)/ui', mb_strtoupper($search, "UTF-8"), $search_words); $words = $morphy->lemmatize($search_words[1]); $s_words = array(); $pre_result = array(); foreach ($words as $k => $w) { if (!$w)$w[0] = $k; if (mb_strlen($w[0], "UTF-8") > 2) { $s_words[] = $w[0]; } } if (!count($s_words)) { // ( 2 ) } else { foreach($s_words as $s_word) { $search_index = ORM::factory('searchindex')->where('word', '=', $s_word)->find_all(); foreach ($search_index as $si) { if (!empty($pre_result[$si->post_id])) { $pre_result[$si->post_id] = (int) $si->weight + $pre_result[$si->post_id]; } else { $pre_result[$si->post_id] = (int) $si->weight; } } } arsort($pre_result); // foreach ($pre_result as $id => $weight) { // , , $data[] = $result; } } } else { // - } } else { // - } $this->template->content = View::factory('content/v_search') ->bind('data', $data) ->bind('errors', $errors) ->bind('request', $request) }
Source: https://habr.com/ru/post/165715/
All Articles