当前位置: 首页>>代码示例>>PHP>>正文


PHP split_words函数代码示例

本文整理汇总了PHP中split_words函数的典型用法代码示例。如果您正苦于以下问题:PHP split_words函数的具体用法?PHP split_words怎么用?PHP split_words使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了split_words函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: search_text_in_db

function search_text_in_db($searchstr, $base_sql, $where_search, $add_where = array(), $strict = false)
{
    global $db, $config;
    //$stopword_array = @file($root_path . 'languages/lang_' . $config['default_lang'] . '/search_stopwords.txt');
    //$synonym_array = @file($root_path . 'languages/lang_' . $config['default_lang'] . '/search_synonyms.txt');
    $match_types = array('or', 'not', 'and');
    $add_where = sizeof($add_where) ? ' AND ' . implode(' AND ', $add_where) : '';
    $cleansearchstr = searchfield($searchstr);
    $lower_searchstr = utf_strtolower($searchstr);
    if ($strict) {
        $split_search = array($lower_searchstr);
    } else {
        $split_search = split_words($cleansearchstr);
        if ($lower_searchstr != $searchstr) {
            $search_full_string = true;
            foreach ($match_types as $_null => $match_type) {
                if (strpos($lower_searchstr, $match_type) !== false) {
                    $search_full_string = false;
                }
            }
            if ($search_full_string) {
                $split_search[] = $lower_searchstr;
            }
        }
    }
    $word_count = 0;
    $current_match_type = 'and';
    $word_match = array();
    $result_list = array();
    for ($i = 0; $i < sizeof($split_search); $i++) {
        if (utf_strlen(str_replace(array('*', '%'), '', trim($split_search[$i]))) < $config['search_min_chars'] && !in_array($split_search[$i], $match_types)) {
            $split_search[$i] = '';
            continue;
        }
        switch ($split_search[$i]) {
            case 'and':
                $current_match_type = 'and';
                break;
            case 'or':
                $current_match_type = 'or';
                break;
            case 'not':
                $current_match_type = 'not';
                break;
            default:
                if (!empty($search_terms)) {
                    $current_match_type = 'and';
                }
                if ($strict) {
                    $search = $where_search . ' = \'' . sqlesc($split_search[$i]) . '\'' . $add_where;
                } else {
                    $match_word = str_replace('*', '%', $split_search[$i]);
                    $search = $where_search . ' LIKE \'%' . sqlesc($match_word) . '%\'' . $add_where;
                    //$search = $where_search . ' REGEXP \'[[:<:]]' . $db->sql_escape($match_word) . '[[:>:]]\'' . $add_where;
                }
                $sql = $base_sql . ' WHERE ' . $search;
                $result = sql_query($sql);
                $row = array();
                while ($temp_row = mysqli_fetch_row($result)) {
                    $row[$temp_row['id']] = 1;
                    if (!$word_count) {
                        $result_list[$temp_row['id']] = 1;
                    } else {
                        if ($current_match_type == 'or') {
                            $result_list[$temp_row['id']] = 1;
                        } else {
                            if ($current_match_type == 'not') {
                                $result_list[$temp_row['id']] = 0;
                            }
                        }
                    }
                }
                if ($current_match_type == 'and' && $word_count) {
                    @reset($result_list);
                    foreach ($result_list as $id => $match_count) {
                        if (!isset($row[$id]) || !$row[$id]) {
                            //$result_list[$id] = 0;
                            @($result_list[$id] -= 1);
                        } else {
                            @($result_list[$id] += 1);
                        }
                    }
                }
                $word_count++;
                mysqli_fetch_assoc($result);
        }
    }
    @reset($result_list);
    $search_ids = array();
    foreach ($result_list as $id => $matches) {
        if ($matches > 0) {
            //if ( $matches ) {
            $search_ids[] = $id;
        }
    }
    unset($result_list);
    return $search_ids;
}
开发者ID:Bigjoos,项目名称:U-232-V5,代码行数:98,代码来源:functions_search.php

示例2: update_search_index

function update_search_index($mode, $post_id, $message, $subject = null)
{
    global $db_type;
    // Get Slim current session
    $feather = \Slim\Slim::getInstance();
    $message = utf8_strtolower($message);
    $subject = utf8_strtolower($subject);
    // Remove any bbcode that we shouldn't index
    $message = strip_bbcode($message);
    // Split old and new post/subject to obtain array of 'words'
    $words_message = split_words($message, true);
    $words_subject = $subject ? split_words($subject, true) : array();
    if ($mode == 'edit') {
        $select_update_search_index = array('w.id', 'w.word', 'm.subject_match');
        $result = \DB::for_table('search_words')->table_alias('w')->select_many($select_update_search_index)->inner_join('search_matches', array('w.id', '=', 'm.word_id'), 'm')->where('m.post_id', $post_id)->find_many();
        // Declare here to stop array_keys() and array_diff() from complaining if not set
        $cur_words['post'] = array();
        $cur_words['subject'] = array();
        foreach ($result as $row) {
            $match_in = $row['subject_match'] ? 'subject' : 'post';
            $cur_words[$match_in][$row['word']] = $row['id'];
        }
        $pdo = \DB::get_db();
        $pdo = null;
        $words['add']['post'] = array_diff($words_message, array_keys($cur_words['post']));
        $words['add']['subject'] = array_diff($words_subject, array_keys($cur_words['subject']));
        $words['del']['post'] = array_diff(array_keys($cur_words['post']), $words_message);
        $words['del']['subject'] = array_diff(array_keys($cur_words['subject']), $words_subject);
    } else {
        $words['add']['post'] = $words_message;
        $words['add']['subject'] = $words_subject;
        $words['del']['post'] = array();
        $words['del']['subject'] = array();
    }
    unset($words_message);
    unset($words_subject);
    // Get unique words from the above arrays
    $unique_words = array_unique(array_merge($words['add']['post'], $words['add']['subject']));
    if (!empty($unique_words)) {
        $select_unique_words = array('id', 'word');
        $result = \DB::for_table('search_words')->select_many($select_unique_words)->where_in('word', $unique_words)->find_many();
        $word_ids = array();
        foreach ($result as $row) {
            $word_ids[$row['word']] = $row['id'];
        }
        $pdo = \DB::get_db();
        $pdo = null;
        $new_words = array_values(array_diff($unique_words, array_keys($word_ids)));
        unset($unique_words);
        if (!empty($new_words)) {
            switch ($db_type) {
                case 'mysql':
                case 'mysqli':
                case 'mysql_innodb':
                case 'mysqli_innodb':
                    // Quite dirty, right? :-)
                    $placeholders = rtrim(str_repeat('(?), ', count($new_words)), ', ');
                    \DB::for_table('search_words')->raw_execute('INSERT INTO ' . $feather->prefix . 'search_words (word) VALUES ' . $placeholders, $new_words);
                    break;
                default:
                    foreach ($new_words as $word) {
                        $word_insert['word'] = $word;
                        \DB::for_table('search_words')->create()->set($word_insert)->save();
                    }
                    break;
            }
        }
        unset($new_words);
    }
    // Delete matches (only if editing a post)
    foreach ($words['del'] as $match_in => $wordlist) {
        $subject_match = $match_in == 'subject' ? 1 : 0;
        if (!empty($wordlist)) {
            $sql = array();
            foreach ($wordlist as $word) {
                $sql[] = $cur_words[$match_in][$word];
            }
            \DB::for_table('search_matches')->where_in('word_id', $sql)->where('post_id', $post_id)->where('subject_match', $subject_match)->delete_many();
        }
    }
    // Add new matches
    foreach ($words['add'] as $match_in => $wordlist) {
        $subject_match = $match_in == 'subject' ? 1 : 0;
        if (!empty($wordlist)) {
            $wordlist = array_values($wordlist);
            $placeholders = rtrim(str_repeat('?, ', count($wordlist)), ', ');
            \DB::for_table('search_words')->raw_execute('INSERT INTO ' . $feather->prefix . 'search_matches (post_id, word_id, subject_match) SELECT ' . $post_id . ', id, ' . $subject_match . ' FROM ' . $feather->prefix . 'search_words WHERE word IN (' . $placeholders . ')', $wordlist);
        }
    }
    unset($words);
}
开发者ID:beaver-dev,项目名称:featherbb,代码行数:91,代码来源:search_idx.php

示例3: main

 function main($action)
 {
     global $template, $lang, $config, $pafiledb_config, $db, $images, $user;
     if (!$this->auth_global['auth_search']) {
         if (!$user->data['session_logged_in']) {
             redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=dload.' . PHP_EXT . '&action=stats', true));
         }
         $message = sprintf($lang['Sorry_auth_search'], $this->auth_global['auth_search_type']);
         message_die(GENERAL_MESSAGE, $message);
     }
     include IP_ROOT_PATH . 'includes/functions_search.' . PHP_EXT;
     $search_keywords = request_var('search_keywords', '', true);
     $search_keywords = htmlspecialchars_decode($search_keywords, ENT_COMPAT);
     $search_author = request_var('search_author', '', true);
     $search_author = htmlspecialchars_decode($search_author, ENT_COMPAT);
     $search_id = request_var('search_id', 0);
     $search_terms = request_var('search_terms', '');
     $search_terms = $search_terms == 'all' ? 1 : 0;
     $cat_id = request_var('cat_id', 0);
     $comments_search = request_var('comments_search', '');
     $comments_search = $comments_search == 'YES' ? 1 : 0;
     $start = request_var('start', 0);
     $start = $start < 0 ? 0 : $start;
     $sort_method = request_var('sort_method', $pafiledb_config['sort_method']);
     $sort_method = check_var_value($sort_method, array('file_name', 'file_time', 'file_dls', 'file_rating', 'file_update_time'));
     $sort_method = $sort_method == 'file_rating' ? 'rating' : $sort_method;
     $sort_order = request_var('order', $pafiledb_config['sort_order']);
     $sort_order = check_var_value($sort_order, array('DESC', 'ASC'));
     $limit_sql = $start == 0 ? $pafiledb_config['settings_file_page'] : $start . ',' . $pafiledb_config['settings_file_page'];
     // encoding match for workaround
     $multibyte_charset = 'utf-8, big5, shift_jis, euc-kr, gb2312';
     if (isset($_POST['submit']) || $search_author != '' || $search_keywords != '' || $search_id) {
         $store_vars = array('search_results', 'total_match_count', 'split_search', 'sort_method', 'sort_order');
         if ($search_author != '' || $search_keywords != '') {
             if ($search_author != '' && $search_keywords == '') {
                 $search_author = str_replace('*', '%', trim($search_author));
                 $sql = get_users_sql($search_author, true, false, true, false);
                 $result = $db->sql_query($sql);
                 $matching_userids = '';
                 if ($row = $db->sql_fetchrow($result)) {
                     do {
                         $matching_userids .= ($matching_userids != '' ? ', ' : '') . $row['user_id'];
                     } while ($row = $db->sql_fetchrow($result));
                 } else {
                     message_die(GENERAL_MESSAGE, $lang['No_search_match']);
                 }
                 $sql = "SELECT *\n\t\t\t\t\t\tFROM " . PA_FILES_TABLE . "\n\t\t\t\t\t\tWHERE user_id IN ({$matching_userids})";
                 $result = $db->sql_query($sql);
                 $search_ids = array();
                 while ($row = $db->sql_fetchrow($result)) {
                     if ($this->auth[$row['file_catid']]['auth_view']) {
                         $search_ids[] = $row['file_id'];
                     }
                 }
                 $db->sql_freeresult($result);
                 $total_match_count = sizeof($search_ids);
             } elseif ($search_keywords != '') {
                 stopwords_synonyms_init();
                 $split_search = array();
                 $split_search = !strstr($multibyte_charset, $lang['ENCODING']) ? split_words(clean_words('search', stripslashes($search_keywords), $stopwords_array, $synonyms_array), 'search') : split(' ', $search_keywords);
                 $word_count = 0;
                 $current_match_type = 'or';
                 $word_match = array();
                 $result_list = array();
                 for ($i = 0; $i < sizeof($split_search); $i++) {
                     switch ($split_search[$i]) {
                         case 'and':
                             $current_match_type = 'and';
                             break;
                         case 'or':
                             $current_match_type = 'or';
                             break;
                         case 'not':
                             $current_match_type = 'not';
                             break;
                         default:
                             if (!empty($search_terms)) {
                                 $current_match_type = 'and';
                             }
                             $match_word = addslashes('%' . str_replace('*', '', $split_search[$i]) . '%');
                             $sql = "SELECT file_id\n\t\t\t\t\t\t\t\t\tFROM " . PA_FILES_TABLE . "\n\t\t\t\t\t\t\t\t\tWHERE (file_name LIKE '{$match_word}'\n\t\t\t\t\t\t\t\t\tOR file_creator LIKE '{$match_word}'\n\t\t\t\t\t\t\t\t\tOR file_desc LIKE '{$match_word}'\n\t\t\t\t\t\t\t\t\tOR file_longdesc LIKE '{$match_word}')";
                             $result = $db->sql_query($sql);
                             $row = array();
                             while ($temp_row = $db->sql_fetchrow($result)) {
                                 $row[$temp_row['file_id']] = 1;
                                 if (!$word_count) {
                                     $result_list[$temp_row['file_id']] = 1;
                                 } elseif ($current_match_type == 'or') {
                                     $result_list[$temp_row['file_id']] = 1;
                                 } elseif ($current_match_type == 'not') {
                                     $result_list[$temp_row['file_id']] = 0;
                                 }
                             }
                             if ($current_match_type == 'and' && $word_count) {
                                 @reset($result_list);
                                 while (list($file_id, $match_count) = @each($result_list)) {
                                     if (!$row[$file_id]) {
                                         $result_list[$file_id] = 0;
                                     }
                                 }
//.........这里部分代码省略.........
开发者ID:ALTUN69,项目名称:icy_phoenix,代码行数:101,代码来源:pa_search.php

示例4: add_search_words

function add_search_words($mode, $post_id, $post_text, $post_title = '')
{
    global $db, $phpbb_root_path, $board_config, $lang;
    $stopword_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . "/search_stopwords.txt");
    $synonym_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . "/search_synonyms.txt");
    $search_raw_words = array();
    $search_raw_words['text'] = split_words(clean_words('post', $post_text, $stopword_array, $synonym_array));
    $search_raw_words['title'] = split_words(clean_words('post', $post_title, $stopword_array, $synonym_array));
    @set_time_limit(0);
    $word = array();
    $word_insert_sql = array();
    while (list($word_in, $search_matches) = @each($search_raw_words)) {
        $word_insert_sql[$word_in] = '';
        if (!empty($search_matches)) {
            for ($i = 0; $i < count($search_matches); $i++) {
                $search_matches[$i] = trim($search_matches[$i]);
                if ($search_matches[$i] != '') {
                    $word[] = $search_matches[$i];
                    if (!strstr($word_insert_sql[$word_in], "'" . $search_matches[$i] . "'")) {
                        $word_insert_sql[$word_in] .= $word_insert_sql[$word_in] != "" ? ", '" . $search_matches[$i] . "'" : "'" . $search_matches[$i] . "'";
                    }
                }
            }
        }
    }
    if (count($word)) {
        sort($word);
        $prev_word = '';
        $word_text_sql = '';
        $temp_word = array();
        for ($i = 0; $i < count($word); $i++) {
            if ($word[$i] != $prev_word) {
                $temp_word[] = $word[$i];
                $word_text_sql .= ($word_text_sql != '' ? ', ' : '') . "'" . $word[$i] . "'";
            }
            $prev_word = $word[$i];
        }
        $word = $temp_word;
        $check_words = array();
        switch (SQL_LAYER) {
            case 'postgresql':
            case 'msaccess':
            case 'mssql-odbc':
            case 'oracle':
            case 'db2':
                $sql = "SELECT word_id, word_text\r\n                                        FROM " . SEARCH_WORD_TABLE . "\r\n                                        WHERE word_text IN ({$word_text_sql})";
                if (!($result = $db->sql_query($sql))) {
                    message_die(GENERAL_ERROR, 'Could not select words', '', __LINE__, __FILE__, $sql);
                }
                while ($row = $db->sql_fetchrow($result)) {
                    $check_words[$row['word_text']] = $row['word_id'];
                }
                break;
        }
        $value_sql = '';
        $match_word = array();
        for ($i = 0; $i < count($word); $i++) {
            $new_match = true;
            if (isset($check_words[$word[$i]])) {
                $new_match = false;
            }
            if ($new_match) {
                switch (SQL_LAYER) {
                    case 'mysql':
                    case 'mysql4':
                        $value_sql .= ($value_sql != '' ? ', ' : '') . '(\'' . $word[$i] . '\', 0)';
                        break;
                    case 'mssql':
                    case 'mssql-odbc':
                        $value_sql .= ($value_sql != '' ? ' UNION ALL ' : '') . "SELECT '" . $word[$i] . "', 0";
                        break;
                    default:
                        $sql = "INSERT INTO " . SEARCH_WORD_TABLE . " (word_text, word_common)\r\n                                                        VALUES ('" . $word[$i] . "', '0')";
                        if (!$db->sql_query($sql)) {
                            message_die(GENERAL_ERROR, 'Could not insert new word', '', __LINE__, __FILE__, $sql);
                        }
                        break;
                }
            }
        }
        if ($value_sql != '') {
            switch (SQL_LAYER) {
                case 'mysql':
                case 'mysql4':
                    $sql = "INSERT IGNORE INTO " . SEARCH_WORD_TABLE . " (word_text, word_common)\r\n                                                VALUES {$value_sql}";
                    break;
                case 'mssql':
                case 'mssql-odbc':
                    $sql = "INSERT INTO " . SEARCH_WORD_TABLE . " (word_text, word_common)\r\n                                                {$value_sql}";
                    break;
            }
            if (!$db->sql_query($sql)) {
                message_die(GENERAL_ERROR, 'Could not insert new word', '', __LINE__, __FILE__, $sql);
            }
        }
    }
    while (list($word_in, $match_sql) = @each($word_insert_sql)) {
        $title_match = $word_in == 'title' ? 1 : 0;
        if ($match_sql != '') {
            $sql = "INSERT INTO " . SEARCH_MATCH_TABLE . " (post_id, word_id, title_match)\r\n                                SELECT {$post_id}, word_id, {$title_match}\r\n                                        FROM " . SEARCH_WORD_TABLE . "\r\n                                        WHERE word_text IN ({$match_sql})";
//.........这里部分代码省略.........
开发者ID:rotvulpix,项目名称:php-nuke,代码行数:101,代码来源:functions_search.php

示例5: get_similar_topics

/**
* Get similar topics
* If user is guest or bot it will create a cache list in topics table to save some SQL charge
*/
function get_similar_topics($similar_forums_auth, $topic_id, $topic_title, $similar_topics_ids = '', $topic_desc = '')
{
    global $db, $config, $user, $lang;
    $similar_topics = array();
    if ($similar_topics_ids !== '' && (!$user->data['session_logged_in'] || $user->data['is_bot'])) {
        if ($similar_topics_ids == 'empty') {
            return $similar_topics;
        }
        $topics_array = $similar_topics_ids;
        $sql = "SELECT t.*, u.user_id, u.username, u.user_active, u.user_color, u2.username as user2, u2.user_id as id2, u2.user_active as user_active2, u2.user_color as user_color2, f.forum_id, f.forum_name, p.post_time, p.post_username\n\t\t\t\t\tFROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p, " . USERS_TABLE . " u2\n\t\t\t\t\tWHERE t.topic_id IN (" . $topics_array . ")\n\t\t\t\t\t\tAND t.forum_id = f.forum_id\n\t\t\t\t\t\tAND p.poster_id = u2.user_id\n\t\t\t\t\t\tAND p.post_id = t.topic_last_post_id\n\t\t\t\t\t\tAND t.topic_poster = u.user_id\n\t\t\t\t\t\tAND t.topic_status <> " . TOPIC_MOVED . "\n\t\t\t\t\tGROUP BY t.topic_id\n\t\t\t\t\tORDER BY p.post_time";
        $result = $db->sql_query($sql);
        $similar_topics = $db->sql_fetchrowset($result);
        $db->sql_freeresult($result);
        return $similar_topics;
    }
    if ($config['similar_ignore_forums_ids']) {
        $ignore_forums_ids = array_map('intval', explode("\n", trim($config['similar_ignore_forums_ids'])));
    } else {
        $ignore_forums_ids = array();
    }
    // Get forum auth information to insure privacy of hidden topics
    $forums_auth_sql = '';
    //foreach ($similar_forums_auth as $k=>$v)
    //$similar_forums_auth = auth(AUTH_ALL, AUTH_LIST_ALL, $user->data);
    foreach ($similar_forums_auth as $k => $v) {
        if (sizeof($ignore_forums_ids) && in_array($k, $ignore_forums_ids)) {
            continue;
        }
        if ($v['auth_view'] && $v['auth_read']) {
            $forums_auth_sql .= ($forums_auth_sql == '' ? '' : ', ') . $k;
        }
    }
    if ($forums_auth_sql != '') {
        $forums_auth_sql = ' AND t.forum_id IN (' . $forums_auth_sql . ') ';
    }
    if ($config['similar_stopwords']) {
        // encoding match for workaround
        $multibyte_charset = 'utf-8, big5, shift_jis, euc-kr, gb2312';
        // check against stopwords start
        @(include_once IP_ROOT_PATH . 'includes/functions_search.' . PHP_EXT);
        stopwords_synonyms_init();
        $synonyms_array = array();
        // check against stopwords end
        $title_search = '';
        $title_search_array = !strstr($multibyte_charset, $lang['ENCODING']) ? split_words(clean_words('post', $topic_title, $stopwords_array, $synonyms_array), 'search') : split(' ', $topic_title);
        for ($i = 0; $i < sizeof($title_search_array); $i++) {
            $title_search .= ($title_search == '' ? '' : ' ') . $title_search_array[$i];
        }
    } else {
        $title_search = $topic_title;
    }
    /*
    if (!empty($topic_desc) && $config['similar_topicdesc'])
    {
    	if ($config['similar_stopwords'])
    	{
    		$topicdesc = '';
    		$topic_desc_array = (!strstr($multibyte_charset, $lang['ENCODING'])) ? split_words(clean_words('post', $topic_desc, $stopwords_array, $synonyms_array), 'search') : split(' ', $topic_desc);
    		for ($i = 0; $i < sizeof($topic_desc_array); $i++)
    		{
    			$topicdesc .= (($topicdesc == '') ? '': ' ') . $topic_desc_array[$i];
    		}
    	}
    	else
    	{
    		$topicdesc = $topic_desc;
    	}
    	$sql_topic_desc = "+MATCH(t.topic_desc) AGAINST('" . $db->sql_escape($topicdesc) . "')";
    }
    
    $sql_match = "MATCH(t.topic_title) AGAINST('" . $db->sql_escape($title_search) . "')" . $sql_topic_desc;
    */
    $sql_match = "MATCH(t.topic_title) AGAINST('" . $db->sql_escape($title_search) . "')";
    if ($config['similar_sort_type'] == 'time') {
        $sql_sort = 'p.post_time';
    } else {
        $sql_sort = 'relevance';
    }
    //ORDER BY t.topic_type DESC, ' . $sql_sort . ' DESC LIMIT 0,' . intval($config['similar_max_topics']);
    $sql = "SELECT t.*, u.user_id, u.username, u.user_active, u.user_color, u2.username as user2, u2.user_id as id2, u2.user_active as user_active2, u2.user_color as user_color2, f.forum_id, f.forum_name, p.post_time, p.post_username, {$sql_match} as relevance\n\t\t\t\tFROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p, " . USERS_TABLE . " u2\n\t\t\t\tWHERE t.topic_id <> {$topic_id} {$forums_auth_sql}\n\t\t\t\t\tAND {$sql_match}\n\t\t\t\t\tAND t.forum_id = f.forum_id\n\t\t\t\t\tAND p.poster_id = u2.user_id\n\t\t\t\t\tAND p.post_id = t.topic_last_post_id\n\t\t\t\t\tAND t.topic_poster = u.user_id\n\t\t\t\t\tAND t.topic_status <> " . TOPIC_MOVED . "\n\t\t\t\tGROUP BY t.topic_id\n\t\t\t\tORDER BY " . $sql_sort . " DESC LIMIT 0," . intval($config['similar_max_topics']);
    $result = $db->sql_query($sql);
    $similar_topics = $db->sql_fetchrowset($result);
    $db->sql_freeresult($result);
    $count_similar = sizeof($similar_topics);
    if (!$user->data['session_logged_in'] || $user->data['is_bot']) {
        $similar_ids_array = 'empty';
        if (!empty($count_similar)) {
            $similar_ids_array = '';
            for ($i = 0; $i < $count_similar; $i++) {
                $similar_ids_array .= (empty($similar_ids_array) ? '' : ',') . $similar_topics[$i]['topic_id'];
            }
        }
        $sql = "UPDATE " . TOPICS_TABLE . " SET topic_similar_topics = '" . $similar_ids_array . "' WHERE topic_id = " . $topic_id;
        $result = $db->sql_query($sql);
    }
    return $similar_topics;
//.........这里部分代码省略.........
开发者ID:ALTUN69,项目名称:icy_phoenix,代码行数:101,代码来源:functions_topics.php

示例6: message_die

         }
     }
     if (!($result = $db->sql_query($sql))) {
         message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
     }
     $search_ids = array();
     while ($row = $db->sql_fetchrow($result)) {
         $search_ids[] = $row['post_id'];
     }
     $db->sql_freeresult($result);
     $total_match_count = count($search_ids);
 } else {
     if ($search_keywords != '') {
         $stopword_array = file('language/' . $board_config['default_lang'] . '/Forums/search_stopwords.txt');
         $synonym_array = file('language/' . $board_config['default_lang'] . '/Forums/search_synonyms.txt');
         $split_search = !strstr($multibyte_charset, $lang['ENCODING']) ? split_words(clean_words('search', $search_keywords, $stopword_array, $synonym_array), 'search') : split(' ', $search_keywords);
         $search_msg_only = !$search_fields ? "AND m.title_match = 0" : (strstr($multibyte_charset, $lang['ENCODING']) ? '' : '');
         $word_count = 0;
         $current_match_type = 'or';
         $word_match = array();
         $result_list = array();
         for ($i = 0; $i < count($split_search); $i++) {
             if (preg_match('#^[\\*%]+$#', trim($split_search[$i])) || preg_match('#^[^\\*]{1,2}$#', str_replace(array('*', '%'), '', trim($split_search[$i])))) {
                 $split_search[$i] = '';
                 continue;
             }
             switch ($split_search[$i]) {
                 case 'and':
                     $current_match_type = 'and';
                     break;
                 case 'or':
开发者ID:cbsistem,项目名称:nexos,代码行数:31,代码来源:search.php

示例7: add_search_words

function add_search_words($mode, $post_id, $post_text, $post_title = '')
{
    $stopword_array = @file("core/lib/phpbb/search_stopwords.txt");
    $synonym_array = @file("core/lib/phpbb/search_synonyms.txt");
    $search_raw_words = array();
    $search_raw_words['text'] = split_words(clean_words('post', $post_text, $stopword_array, $synonym_array));
    $search_raw_words['title'] = split_words(clean_words('post', $post_title, $stopword_array, $synonym_array));
    @set_time_limit(0);
    $word = array();
    $word_insert_sql = array();
    while (list($word_in, $search_matches) = @each($search_raw_words)) {
        $word_insert_sql[$word_in] = '';
        if (!empty($search_matches)) {
            for ($i = 0; $i < count($search_matches); $i++) {
                $search_matches[$i] = trim($search_matches[$i]);
                if ($search_matches[$i] != '') {
                    $word[] = $search_matches[$i];
                    if (!strstr($word_insert_sql[$word_in], "'" . $search_matches[$i] . "'")) {
                        $word_insert_sql[$word_in] .= $word_insert_sql[$word_in] != "" ? ", '" . $search_matches[$i] . "'" : "'" . $search_matches[$i] . "'";
                    }
                }
            }
        }
    }
    if (count($word)) {
        sort($word);
        $prev_word = '';
        $word_text_sql = '';
        $temp_word = array();
        for ($i = 0; $i < count($word); $i++) {
            if ($word[$i] != $prev_word) {
                $temp_word[] = $word[$i];
                $word_text_sql .= ($word_text_sql != '' ? ', ' : '') . "'" . $word[$i] . "'";
            }
            $prev_word = $word[$i];
        }
        $word = $temp_word;
        $check_words = array();
        $value_sql = '';
        $match_word = array();
        for ($i = 0; $i < count($word); $i++) {
            $new_match = true;
            if (isset($check_words[$word[$i]])) {
                $new_match = false;
            }
            if ($new_match) {
                $value_sql .= ($value_sql != '' ? ', ' : '') . '(\'' . $word[$i] . '\', 0)';
            }
        }
        if ($value_sql != '') {
            $sql = "INSERT IGNORE INTO `z_phpbb_search_wordlist` (word_text, word_common) \n                VALUES {$value_sql}";
            mysql_query($sql);
        }
    }
    while (list($word_in, $match_sql) = @each($word_insert_sql)) {
        $title_match = $word_in == 'title' ? 1 : 0;
        if ($match_sql != '') {
            $sql = "INSERT INTO z_phpbb_search_wordmatch (post_id, word_id, title_match) \n                SELECT {$post_id}, word_id, {$title_match}  \n                FROM z_phpbb_search_wordlist \n                WHERE word_text IN ({$match_sql})";
            mysql_query($sql);
        }
    }
    if ($mode == 'single') {
        remove_common('single', 4 / 10, $word);
    }
    return;
}
开发者ID:ItsHaden,项目名称:epicLanBootstrap,代码行数:66,代码来源:search.php

示例8: update_search_index

function update_search_index($mode, $post_id, $message, $subject = null)
{
    global $db_type, $forum_db;
    $return = ($hook = get_hook('si_fn_update_search_index_start')) ? eval($hook) : null;
    if ($return != null) {
        return;
    }
    $message = utf8_strtolower($message);
    $subject = utf8_strtolower($subject);
    // Split old and new post/subject to obtain array of 'words'
    $words_message = split_words($message);
    $words_subject = empty($subject) ? array() : split_words($subject);
    if ($mode == 'edit') {
        $query = array('SELECT' => 'w.id, w.word, m.subject_match', 'FROM' => 'search_words AS w', 'JOINS' => array(array('INNER JOIN' => 'search_matches AS m', 'ON' => 'w.id=m.word_id')), 'WHERE' => 'm.post_id=' . $post_id);
        ($hook = get_hook('si_fn_update_search_index_qr_get_current_words')) ? eval($hook) : null;
        $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
        // Declare here to stop array_keys() and array_diff() from complaining if not set
        $cur_words = array('post' => array(), 'subject' => array());
        while ($row = $forum_db->fetch_assoc($result)) {
            $cur_words[$row['subject_match'] == 1 ? 'subject' : 'post'][$row['word']] = $row['id'];
        }
        $forum_db->free_result($result);
        $words = array('add' => array('post' => array_diff($words_message, array_keys($cur_words['post'])), 'subject' => array_diff($words_subject, array_keys($cur_words['subject']))), 'del' => array('post' => array_diff(array_keys($cur_words['post']), $words_message), 'subject' => array_diff(array_keys($cur_words['subject']), $words_subject)));
    } else {
        $words = array('add' => array('post' => $words_message, 'subject' => $words_subject), 'del' => array('post' => array(), 'subject' => array()));
    }
    // Get unique words from the above arrays
    $unique_words = array_unique(array_merge($words['add']['post'], $words['add']['subject']));
    if (!empty($unique_words)) {
        $query = array('SELECT' => 'id, word', 'FROM' => 'search_words', 'WHERE' => 'word IN(\'' . implode('\',\'', array_map(array($forum_db, 'escape'), $unique_words)) . '\')');
        ($hook = get_hook('si_fn_update_search_index_qr_get_existing_words')) ? eval($hook) : null;
        $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
        $existing_words = array();
        while ($row = $forum_db->fetch_row($result)) {
            $existing_words[] = $row[1];
        }
        $forum_db->free_result($result);
        $new_words = array_diff($unique_words, $existing_words);
        if (!empty($new_words)) {
            $query = array('INSERT' => 'word', 'INTO' => 'search_words', 'VALUES' => preg_replace('#^(.*)$#', '\'\\1\'', array_map(array($forum_db, 'escape'), $new_words)));
            ($hook = get_hook('si_fn_update_search_index_qr_insert_words')) ? eval($hook) : null;
            $forum_db->query_build($query) or error(__FILE__, __LINE__);
        }
    }
    // Delete matches (only if editing a post)
    foreach ($words['del'] as $match_in => $wordlist) {
        if (!empty($wordlist)) {
            $word_ids = array();
            foreach ($wordlist as $word) {
                $word_ids[] = $cur_words[$match_in][$word];
            }
            $query = array('DELETE' => 'search_matches', 'WHERE' => 'word_id IN (' . implode(', ', $word_ids) . ') AND post_id=' . $post_id . ' AND subject_match=' . ($match_in == 'subject' ? '1' : '0'));
            ($hook = get_hook('si_fn_update_search_index_qr_delete_matches')) ? eval($hook) : null;
            $forum_db->query_build($query) or error(__FILE__, __LINE__);
        }
    }
    // Add new matches
    foreach ($words['add'] as $match_in => $wordlist) {
        if (!empty($wordlist)) {
            $subquery = array('SELECT' => $post_id . ', id, ' . ($match_in == 'subject' ? '1' : '0'), 'FROM' => 'search_words', 'WHERE' => 'word IN (\'' . implode('\',\'', array_map(array($forum_db, 'escape'), $wordlist)) . '\')');
            // Really this should use the query builder too, though it doesn't currently support the syntax
            $sql = 'INSERT INTO ' . $forum_db->prefix . 'search_matches (post_id, word_id, subject_match) ' . $forum_db->query_build($subquery, true);
            ($hook = get_hook('si_fn_update_search_index_qr_add_matches')) ? eval($hook) : null;
            $forum_db->query($sql) or error(__FILE__, __LINE__);
        }
    }
    unset($words);
}
开发者ID:vebnz,项目名称:lifelitup,代码行数:68,代码来源:search_idx.php

示例9: update_search_index

function update_search_index($mode, $post_id, $message, $subject = null)
{
    global $db;
    $message = utf8_strtolower($message);
    $subject = utf8_strtolower($subject);
    // Remove any bbcode that we shouldn't index
    $message = strip_bbcode($message);
    // Split old and new post/subject to obtain array of 'words'
    $words_message = split_words($message, true);
    $words_subject = $subject ? split_words($subject, true) : array();
    if ($mode == 'edit') {
        $data = array(':id' => $post_id);
        $ps = $db->run('SELECT w.id, w.word, m.subject_match FROM ' . $db->prefix . 'search_words AS w INNER JOIN ' . $db->prefix . 'search_matches AS m ON w.id=m.word_id WHERE m.post_id=:id', $data);
        // Declare here to stop array_keys() and array_diff() from complaining if not set
        $cur_words['post'] = array();
        $cur_words['subject'] = array();
        foreach ($ps as $result) {
            $match_in = $result['subject_match'] ? 'subject' : 'post';
            $cur_words[$match_in][$result['word']] = $result['id'];
        }
        $db->free_result($ps);
        $words['add']['post'] = array_diff($words_message, array_keys($cur_words['post']));
        $words['add']['subject'] = array_diff($words_subject, array_keys($cur_words['subject']));
        $words['del']['post'] = array_diff(array_keys($cur_words['post']), $words_message);
        $words['del']['subject'] = array_diff(array_keys($cur_words['subject']), $words_subject);
    } else {
        $words['add']['post'] = $words_message;
        $words['add']['subject'] = $words_subject;
        $words['del']['post'] = array();
        $words['del']['subject'] = array();
    }
    unset($words_message);
    unset($words_subject);
    // Get unique words from the above arrays
    $unique_words = array_unique(array_merge($words['add']['post'], $words['add']['subject']));
    $data = $placeholders = array();
    foreach ($unique_words as $word) {
        $placeholders[] = '?';
        $data[] = $word;
    }
    if (!empty($unique_words)) {
        $ps = $db->run('SELECT id, word FROM ' . $db->prefix . 'search_words WHERE word IN(' . implode(',', $placeholders) . ')', array_values($data));
        $word_ids = array();
        foreach ($ps as $cur_row) {
            $word_ids[$cur_row['word']] = $cur_row['id'];
        }
        $db->free_result($ps);
        $new_words = array_diff($unique_words, array_keys($word_ids));
        unset($unique_words);
        if (!empty($new_words)) {
            foreach ($new_words as $word) {
                $data = array('word' => $word);
                $db->insert('search_words', $data);
            }
        }
        unset($new_words);
    }
    // Delete matches (only if editing a post)
    foreach ($words['del'] as $match_in => $wordlist) {
        $placeholders = $data = array();
        if (!empty($wordlist)) {
            foreach ($wordlist as $word) {
                $placeholders[] = '?';
                $data[] = $cur_words[$match_in][$word];
            }
            $data[] = $post_id;
            $data[] = $match_in == 'subject' ? 1 : 0;
            $db->run('DELETE FROM ' . $db->prefix . 'search_matches WHERE word_id IN(' . implode(',', $placeholders) . ') AND post_id=? AND subject_match=?', $data);
        }
    }
    // Add new matches
    foreach ($words['add'] as $match_in => $wordlist) {
        $placeholders = $data = array();
        $subject_match = $match_in == 'subject' ? 1 : 0;
        foreach ($wordlist as $word) {
            $placeholders[] = '?';
            $data[] = $word;
        }
        if (!empty($wordlist)) {
            $db->run('INSERT INTO ' . $db->prefix . 'search_matches (post_id, word_id, subject_match) SELECT ' . $post_id . ', id, ' . $subject_match . ' FROM ' . $db->prefix . 'search_words WHERE word IN(' . implode(',', $placeholders) . ')', $data);
        }
    }
    unset($words);
}
开发者ID:mtechnik,项目名称:pantherforum,代码行数:84,代码来源:search_idx.php

示例10: get_search_results


//.........这里部分代码省略.........
             if ($this->user->last_search && time() - $this->user->last_search < $this->user->g_search_flood && time() - $this->user->last_search >= 0) {
                 message(sprintf($lang_search['Search flood'], $this->user->g_search_flood, $this->user->g_search_flood - (time() - $this->user->last_search)));
             }
             if (!$this->user->is_guest) {
                 DB::for_table('users')->where('id', $this->user->id)->update_many('last_search', time());
             } else {
                 DB::for_table('online')->where('ident', get_remote_address())->update_many('last_search', time());
             }
             switch ($sort_by) {
                 case 1:
                     $sort_by_sql = $show_as == 'topics' ? 't.poster' : 'p.poster';
                     $sort_type = SORT_STRING;
                     break;
                 case 2:
                     $sort_by_sql = 't.subject';
                     $sort_type = SORT_STRING;
                     break;
                 case 3:
                     $sort_by_sql = 't.forum_id';
                     $sort_type = SORT_NUMERIC;
                     break;
                 case 4:
                     $sort_by_sql = 't.last_post';
                     $sort_type = SORT_NUMERIC;
                     break;
                 default:
                     $sort_by_sql = $show_as == 'topics' ? 't.last_post' : 'p.posted';
                     $sort_type = SORT_NUMERIC;
                     break;
             }
             // If it's a search for keywords
             if ($keywords) {
                 // split the keywords into words
                 $keywords_array = split_words($keywords, false);
                 if (empty($keywords_array)) {
                     message($lang_search['No hits']);
                 }
                 // Should we search in message body or topic subject specifically?
                 $search_in_cond = $search_in ? $search_in > 0 ? ' AND m.subject_match = 0' : ' AND m.subject_match = 1' : '';
                 $word_count = 0;
                 $match_type = 'and';
                 $sort_data = array();
                 foreach ($keywords_array as $cur_word) {
                     switch ($cur_word) {
                         case 'and':
                         case 'or':
                         case 'not':
                             $match_type = $cur_word;
                             break;
                         default:
                             if (is_cjk($cur_word)) {
                                 $where_cond = str_replace('*', '%', $cur_word);
                                 $where_cond_cjk = $search_in ? $search_in > 0 ? 'p.message LIKE %:where_cond%' : 't.subject LIKE %:where_cond%' : 'p.message LIKE %:where_cond% OR t.subject LIKE %:where_cond%';
                                 $result = DB::for_table('posts')->raw_query('SELECT p.id AS post_id, p.topic_id, ' . $sort_by_sql . ' AS sort_by FROM ' . $this->feather->prefix . 'posts AS p INNER JOIN ' . $this->feather->prefix . 'topics AS t ON t.id=p.topic_id LEFT JOIN ' . $this->feather->prefix . 'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id=' . $this->user->g_id . ') WHERE (' . $where_cond_cjk . ') AND (fp.read_forum IS NULL OR fp.read_forum=1)' . $forum_sql, array(':where_cond' => $where_cond))->find_many();
                             } else {
                                 $result = DB::for_table('posts')->raw_query('SELECT m.post_id, p.topic_id, ' . $sort_by_sql . ' AS sort_by FROM ' . $this->feather->prefix . 'search_words AS w INNER JOIN ' . $this->feather->prefix . 'search_matches AS m ON m.word_id = w.id INNER JOIN ' . $this->feather->prefix . 'posts AS p ON p.id=m.post_id INNER JOIN ' . $this->feather->prefix . 'topics AS t ON t.id=p.topic_id LEFT JOIN ' . $this->feather->prefix . 'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id=' . $this->user->g_id . ') WHERE w.word LIKE :where_cond' . $search_in_cond . ' AND (fp.read_forum IS NULL OR fp.read_forum=1)' . $forum_sql, array(':where_cond' => str_replace('*', '%', $cur_word)))->find_many();
                             }
                             $row = array();
                             foreach ($result as $temp) {
                                 $row[$temp['post_id']] = $temp['topic_id'];
                                 if (!$word_count) {
                                     $keyword_results[$temp['post_id']] = $temp['topic_id'];
                                     $sort_data[$temp['post_id']] = $temp['sort_by'];
                                 } elseif ($match_type == 'or') {
                                     $keyword_results[$temp['post_id']] = $temp['topic_id'];
                                     $sort_data[$temp['post_id']] = $temp['sort_by'];
开发者ID:beaver-dev,项目名称:featherbb,代码行数:67,代码来源:search.php

示例11: message_die

     if (!($result = $db->sql_query($sql))) {
         message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
     }
     $search_ids = array();
     while ($row = $db->sql_fetchrow($result)) {
         $search_ids[] = $row['post_id'];
     }
     $db->sql_freeresult($result);
     $total_match_count = count($search_ids);
 } else {
     if ($search_keywords != '') {
         $stopword_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_stopwords.txt');
         $synonym_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_synonyms.txt');
         $split_search = array();
         $cleaned_search = clean_words('search', stripslashes($search_keywords), $stopword_array, $synonym_array);
         $split_search = split_words($cleaned_search, 'search');
         $search_msg_only = !$search_fields ? "AND m.title_match = 0" : '';
         $word_count = 0;
         $current_match_type = 'or';
         $word_match = array();
         $result_list = array();
         for ($i = 0; $i < count($split_search); $i++) {
             switch ($split_search[$i]) {
                 case 'and':
                     $current_match_type = 'and';
                     break;
                 case 'or':
                     $current_match_type = 'or';
                     break;
                 case 'not':
                     $current_match_type = 'not';
开发者ID:noikiy,项目名称:owaspbwa,代码行数:31,代码来源:search.php

示例12: array

 $result_array = array(array(), array(), array());
 $i = 0;
 while ($row && ($post_size <= $board_config['dbmtnc_rebuildcfg_maxmemory'] * 1024 || $i < $board_config['dbmtnc_rebuildcfg_minposts'])) {
     $last_post = $row['post_id'];
     // handle text
     $word_list = split_words(clean_words('post', $row['post_text'], $empty_array, $empty_array));
     foreach ($word_list as $word) {
         // cutting of long words in functions_search.php seems not to work under some conditions - so check it again
         if ($word != '' && strlen($word) <= 20) {
             $result_array[0][] = $last_post;
             $result_array[1][] = 0;
             $result_array[2][] = $word;
         }
     }
     // handle subject
     $word_list = split_words(clean_words('post', $row['post_subject'], $empty_array, $empty_array));
     foreach ($word_list as $word) {
         // cutting of long words in functions_search.php seems not to work under some conditions - so check it again
         if ($word != '' && strlen($word) <= 20) {
             $result_array[0][] = $last_post;
             $result_array[1][] = 1;
             $result_array[2][] = $word;
         }
     }
     unset($word_list);
     $row = $db->sql_fetchrow($result);
     $i++;
     $post_size += strlen($row['post_text']) + strlen($row['post_subject']);
 }
 // sort array
 array_multisort($result_array[2], SORT_ASC, SORT_STRING, $result_array[0], SORT_ASC, SORT_NUMERIC, $result_array[1]);
开发者ID:Nekrofage,项目名称:FJR,代码行数:31,代码来源:admin_db_maintenance.php

示例13: update_search_index

function update_search_index($mode, $post_id, $message, $subject = null)
{
    global $db;
    // Split old and new post/subject to obtain array of 'words'
    $words_message = split_words($message);
    $words_subject = $subject ? split_words($subject) : array();
    if ($mode == 'edit') {
        $result = $db->query('SELECT w.id, w.word, m.subject_match FROM ' . $db->prefix . 'search_words AS w INNER JOIN ' . $db->prefix . 'search_matches AS m ON w.id=m.word_id WHERE m.post_id=' . $post_id) or error('Unable to fetch search index words', __FILE__, __LINE__, $db->error());
        // Declare here to stop array_keys() and array_diff() from complaining if not set
        $cur_words['post'] = array();
        $cur_words['subject'] = array();
        while ($row = $db->fetch_row($result)) {
            $match_in = $row[2] ? 'subject' : 'post';
            $cur_words[$match_in][$row[1]] = $row[0];
        }
        $db->free_result($result);
        $words['add']['post'] = array_diff($words_message, array_keys($cur_words['post']));
        $words['add']['subject'] = array_diff($words_subject, array_keys($cur_words['subject']));
        $words['del']['post'] = array_diff(array_keys($cur_words['post']), $words_message);
        $words['del']['subject'] = array_diff(array_keys($cur_words['subject']), $words_subject);
    } else {
        $words['add']['post'] = $words_message;
        $words['add']['subject'] = $words_subject;
        $words['del']['post'] = array();
        $words['del']['subject'] = array();
    }
    unset($words_message);
    unset($words_subject);
    // Get unique words from the above arrays
    $unique_words = array_unique(array_merge($words['add']['post'], $words['add']['subject']));
    if ($unique_words) {
        $result = $db->query('SELECT id, word FROM ' . $db->prefix . 'search_words WHERE word IN(' . implode(',', preg_replace('#^(.*)$#u', '\'\\1\'', $unique_words)) . ')') or error('Unable to fetch search index words', __FILE__, __LINE__, $db->error());
        $word_ids = array();
        while ($row = $db->fetch_row($result)) {
            $word_ids[$row[1]] = $row[0];
        }
        $db->free_result($result);
        $new_words = array_unique(array_diff($unique_words, array_keys($word_ids)));
        unset($unique_words);
        if ($new_words) {
            $db->query('INSERT INTO ' . $db->prefix . 'search_words (word) VALUES' . implode(',', preg_replace('#^(.*)$#u', '(\'\\1\')', $new_words))) or error('Unable to insert search index words', __FILE__, __LINE__, $db->error());
        }
        unset($new_words);
    }
    // Delete matches (only if editing a post)
    while (list($match_in, $wordlist) = @each($words['del'])) {
        $subject_match = $match_in == 'subject' ? 1 : 0;
        if ($wordlist) {
            $sql = null;
            while (list(, $word) = @each($wordlist)) {
                $sql .= ($sql ? ',' : '') . $cur_words[$match_in][$word];
            }
            $db->query('DELETE FROM ' . $db->prefix . 'search_matches WHERE word_id IN(' . $sql . ') AND post_id=' . $post_id . ' AND subject_match=' . $subject_match) or error('Unable to delete search index word matches', __FILE__, __LINE__, $db->error());
        }
    }
    // Add new matches
    while (list($match_in, $wordlist) = @each($words['add'])) {
        $subject_match = $match_in == 'subject' ? 1 : 0;
        if ($wordlist) {
            $db->query('INSERT INTO ' . $db->prefix . 'search_matches (post_id, word_id, subject_match) SELECT ' . $post_id . ', id, ' . $subject_match . ' FROM ' . $db->prefix . 'search_words WHERE word IN(' . implode(',', preg_replace('#^(.*)$#', '\'\\1\'', $wordlist)) . ')') or error('Unable to insert search index word matches', __FILE__, __LINE__, $db->error());
        }
    }
    unset($words);
}
开发者ID:tipsun91,项目名称:punbb-mod,代码行数:64,代码来源:search_idx.php

示例14: update_search_index

function update_search_index($mode, $post_id, $message, $subject = null)
{
    global $db_type, $db;
    $message = utf8_strtolower($message);
    $subject = utf8_strtolower($subject);
    // Remove any bbcode that we shouldn't index
    $message = strip_bbcode($message);
    // Split old and new post/subject to obtain array of 'words'
    $words_message = split_words($message, true);
    $words_subject = $subject ? split_words($subject, true) : array();
    if ($mode == 'edit') {
        // Declare here to stop array_keys() and array_diff() from complaining if not set
        $cur_words = array('post' => array(), 'subject' => array());
        $query = $db->select(array('wid' => 'w.id', 'word' => 'w.word', 'subject_match' => 'm.subject_match'), 'search_words AS w');
        $query->innerJoin('m', 'search_matches AS m', 'w.id = m.word_id');
        $query->where = 'm.post_id = :post_id';
        $params = array(':post_id' => $post_id);
        $result = $query->run($params);
        foreach ($result as $cur_word) {
            $match_in = $cur_word['subject_match'] ? 'subject' : 'post';
            $cur_words[$match_in][$cur_word['word']] = $cur_word['id'];
        }
        unset($query, $params, $result);
        $words['add']['post'] = array_diff($words_message, array_keys($cur_words['post']));
        $words['add']['subject'] = array_diff($words_subject, array_keys($cur_words['subject']));
        $words['del']['post'] = array_diff(array_keys($cur_words['post']), $words_message);
        $words['del']['subject'] = array_diff(array_keys($cur_words['subject']), $words_subject);
    } else {
        $words['add']['post'] = $words_message;
        $words['add']['subject'] = $words_subject;
        $words['del']['post'] = array();
        $words['del']['subject'] = array();
    }
    unset($words_message);
    unset($words_subject);
    // Get unique words from the above arrays
    $unique_words = array_unique(array_merge($words['add']['post'], $words['add']['subject']));
    if (!empty($unique_words)) {
        $word_ids = array();
        $query = $db->select(array('id' => 'w.id', 'word' => 'w.word'), 'search_words AS w');
        $query->where = 'w.word IN :words';
        $params = array(':words' => $unique_words);
        $result = $query->run($params);
        foreach ($result as $cur_word) {
            $word_ids[$cur_word['word']] = $cur_word['id'];
        }
        unset($result, $query, $params);
        $new_words = array_diff($unique_words, array_keys($word_ids));
        unset($unique_words);
        if (!empty($new_words)) {
            $insert_query = $db->insert(array('word' => ':word'), 'search_words');
            foreach ($new_words as $cur_word) {
                $params = array(':word' => $cur_word);
                $insert_query->run($params);
                unset($params);
            }
            unset($insert_query);
        }
        unset($new_words);
    }
    $delete_query = $db->delete('search_matches');
    $delete_query->where = 'word_id IN :wids AND post_id = :post_id AND subject_match = :subject_match';
    // Delete matches (only if editing a post)
    foreach ($words['del'] as $match_in => $wordlist) {
        $subject_match = $match_in == 'subject' ? 1 : 0;
        if (!empty($wordlist)) {
            $word_ids = array();
            foreach ($wordlist as $cur_word) {
                $word_ids[] = $cur_words[$match_in][$cur_word];
            }
            $params = array(':wids' => $word_ids, ':post_id' => $post_id, ':subject_match' => $subject_match);
            $delete_query->run($params);
            unset($params);
        }
    }
    unset($delete_query);
    // Add new matches
    foreach ($words['add'] as $match_in => $wordlist) {
        $subject_match = $match_in == 'subject' ? 1 : 0;
        if (!empty($wordlist)) {
            $db->query('INSERT INTO ' . $db->prefix . 'search_matches (post_id, word_id, subject_match) SELECT ' . $post_id . ', id, ' . $subject_match . ' FROM ' . $db->prefix . 'search_words WHERE word IN(' . implode(',', array_map(array($db, 'quote'), $wordlist)) . ')') or error('Unable to insert search index word matches', __FILE__, __LINE__, $db->error());
        }
    }
    unset($words);
}
开发者ID:rakete,项目名称:affenbande-fluxbb,代码行数:85,代码来源:search_idx.php

示例15: update_search_index

function update_search_index($mode, $post_id, $message, $subject = null)
{
    global $db_type, $db;
    $message = utf8_strtolower($message);
    $subject = utf8_strtolower($subject);
    // Remove any bbcode that we shouldn't index
    $message = strip_bbcode($message);
    // Split old and new post/subject to obtain array of 'words'
    $words_message = split_words($message, true);
    $words_subject = $subject ? split_words($subject, true) : array();
    if ($mode == 'edit') {
        $result = $db->query('SELECT w.id, w.word, m.subject_match FROM ' . $db->prefix . 'search_words AS w INNER JOIN ' . $db->prefix . 'search_matches AS m ON w.id=m.word_id WHERE m.post_id=' . $post_id, true) or error('Unable to fetch search index words', __FILE__, __LINE__, $db->error());
        // Declare here to stop array_keys() and array_diff() from complaining if not set
        $cur_words['post'] = array();
        $cur_words['subject'] = array();
        while ($row = $db->fetch_row($result)) {
            $match_in = $row[2] ? 'subject' : 'post';
            $cur_words[$match_in][$row[1]] = $row[0];
        }
        $db->free_result($result);
        $words['add']['post'] = array_diff($words_message, array_keys($cur_words['post']));
        $words['add']['subject'] = array_diff($words_subject, array_keys($cur_words['subject']));
        $words['del']['post'] = array_diff(array_keys($cur_words['post']), $words_message);
        $words['del']['subject'] = array_diff(array_keys($cur_words['subject']), $words_subject);
    } else {
        $words['add']['post'] = $words_message;
        $words['add']['subject'] = $words_subject;
        $words['del']['post'] = array();
        $words['del']['subject'] = array();
    }
    unset($words_message);
    unset($words_subject);
    // Get unique words from the above arrays
    $unique_words = array_unique(array_merge($words['add']['post'], $words['add']['subject']));
    if (!empty($unique_words)) {
        $result = $db->query('SELECT id, word FROM ' . $db->prefix . 'search_words WHERE word IN(\'' . implode('\',\'', array_map(array($db, 'escape'), $unique_words)) . '\')', true) or error('Unable to fetch search index words', __FILE__, __LINE__, $db->error());
        $word_ids = array();
        while ($row = $db->fetch_row($result)) {
            $word_ids[$row[1]] = $row[0];
        }
        $db->free_result($result);
        $new_words = array_diff($unique_words, array_keys($word_ids));
        unset($unique_words);
        if (!empty($new_words)) {
            switch ($db_type) {
                case 'mysql':
                case 'mysqli':
                case 'mysql_innodb':
                case 'mysqli_innodb':
                    $db->query('INSERT INTO ' . $db->prefix . 'search_words (word) VALUES(\'' . implode('\'),(\'', array_map(array($db, 'escape'), $new_words)) . '\')');
                    break;
                default:
                    foreach ($new_words as $word) {
                        $db->query('INSERT INTO ' . $db->prefix . 'search_words (word) VALUES(\'' . $db->escape($word) . '\')');
                    }
                    break;
            }
        }
        unset($new_words);
    }
    // Delete matches (only if editing a post)
    foreach ($words['del'] as $match_in => $wordlist) {
        $subject_match = $match_in == 'subject' ? 1 : 0;
        if (!empty($wordlist)) {
            $sql = '';
            foreach ($wordlist as $word) {
                $sql .= ($sql != '' ? ',' : '') . $cur_words[$match_in][$word];
            }
            $db->query('DELETE FROM ' . $db->prefix . 'search_matches WHERE word_id IN(' . $sql . ') AND post_id=' . $post_id . ' AND subject_match=' . $subject_match) or error('Unable to delete search index word matches', __FILE__, __LINE__, $db->error());
        }
    }
    // Add new matches
    foreach ($words['add'] as $match_in => $wordlist) {
        $subject_match = $match_in == 'subject' ? 1 : 0;
        if (!empty($wordlist)) {
            $db->query('INSERT INTO ' . $db->prefix . 'search_matches (post_id, word_id, subject_match) SELECT ' . $post_id . ', id, ' . $subject_match . ' FROM ' . $db->prefix . 'search_words WHERE word IN(\'' . implode('\',\'', array_map(array($db, 'escape'), $wordlist)) . '\')') or error('Unable to insert search index word matches', __FILE__, __LINE__, $db->error());
        }
    }
    unset($words);
}
开发者ID:BogusCurry,项目名称:Luna,代码行数:80,代码来源:search_idx.php


注:本文中的split_words函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。