예제 #1
0
 /**
  * Create a custom search index for the messages table.
  *
  * What it does:
  * - Called by ?action=admin;area=managesearch;sa=createmsgindex.
  * - Linked from the action_edit screen.
  * - Requires the admin_forum permission.
  * - Depending on the size of the message table, the process is divided in steps.
  *
  * @uses ManageSearch template, 'create_index', 'create_index_progress', and 'create_index_done'
  * sub-templates.
  */
 public function action_create()
 {
     global $modSettings, $context, $txt, $db_show_debug;
     // Scotty, we need more time...
     @set_time_limit(600);
     if (function_exists('apache_reset_timeout')) {
         @apache_reset_timeout();
     }
     $context[$context['admin_menu_name']]['current_subsection'] = 'method';
     $context['page_title'] = $txt['search_index_custom'];
     $messages_per_batch = 50;
     $index_properties = array(2 => array('column_definition' => 'small', 'step_size' => 1000000), 4 => array('column_definition' => 'medium', 'step_size' => 1000000, 'max_size' => 16777215), 5 => array('column_definition' => 'large', 'step_size' => 100000000, 'max_size' => 2000000000));
     // Resume building an index that was not completed
     if (isset($_REQUEST['resume']) && !empty($modSettings['search_custom_index_resume'])) {
         $context['index_settings'] = unserialize($modSettings['search_custom_index_resume']);
         $context['start'] = (int) $context['index_settings']['resume_at'];
         unset($context['index_settings']['resume_at']);
         $context['step'] = 1;
     } else {
         $context['index_settings'] = array('bytes_per_word' => isset($_REQUEST['bytes_per_word']) && isset($index_properties[$_REQUEST['bytes_per_word']]) ? (int) $_REQUEST['bytes_per_word'] : 2);
         $context['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
         $context['step'] = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0;
         // Admin timeouts are painful when building these long indexes
         if ($_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) {
             $_SESSION['admin_time'] = time();
         }
     }
     if ($context['step'] !== 0) {
         checkSession('request');
     }
     // Step 0: let the user determine how they like their index.
     if ($context['step'] === 0) {
         $context['sub_template'] = 'create_index';
     }
     require_once SUBSDIR . '/ManageSearch.subs.php';
     // Logging may cause session issues with many queries
     $old_db_show_debug = $db_show_debug;
     $db_show_debug = false;
     // Step 1: insert all the words.
     if ($context['step'] === 1) {
         $context['sub_template'] = 'create_index_progress';
         list($context['start'], $context['step'], $context['percentage']) = createSearchIndex($context['start'], $messages_per_batch, $index_properties[$context['index_settings']['bytes_per_word']]['column_definition'], $context['index_settings']);
     } elseif ($context['step'] === 2) {
         if ($context['index_settings']['bytes_per_word'] < 4) {
             $context['step'] = 3;
         } else {
             list($context['start'], $complete) = removeCommonWordsFromIndex($context['start'], $index_properties[$context['index_settings']['bytes_per_word']]);
             if ($complete) {
                 $context['step'] = 3;
             }
             $context['sub_template'] = 'create_index_progress';
             $context['percentage'] = 80 + round($context['start'] / $index_properties[$context['index_settings']['bytes_per_word']]['max_size'], 3) * 20;
         }
     }
     // Restore previous debug state
     $db_show_debug = $old_db_show_debug;
     // Step 3: everything done.
     if ($context['step'] === 3) {
         $context['sub_template'] = 'create_index_done';
         updateSettings(array('search_index' => 'custom', 'search_custom_index_config' => serialize($context['index_settings'])));
         removeSettings('search_custom_index_resume');
     }
 }
예제 #2
0
 /**
  * Rebuild the search index
  */
 public static function ext_rebuildSearchIndex()
 {
     global $output, $PIVOTX;
     $PIVOTX['session']->minLevel(PIVOTX_UL_NORMAL);
     $output = "";
     // initialise the threshold.. Initially it's set to 10 * the rebuild_threshold,
     // roughly assuming we index 10 entries per second.
     if ($PIVOTX['config']->get('rebuild_threshold') > 4) {
         $chunksize = 10 * $PIVOTX['config']->get('rebuild_threshold');
     } else {
         $chunksize = 100;
     }
     @set_time_limit(0);
     include_once "modules/module_search.php";
     $start = isset($_POST['start']) ? $_POST['start'] : 0;
     $time = isset($_POST['time']) ? $_POST['time'] : 0;
     $stop = $start + $chunksize;
     if ($start == 0) {
         $PIVOTX['db']->clearIndex('search');
     }
     $continue = createSearchIndex($start, $stop, $time);
     writeSearchIndex(FALSE);
     $time += timeTaken('int');
     $result = array();
     $result['func'] = 'rebuildSearchIndex';
     $result['start'] = $stop;
     $result['time'] = $time;
     if ($continue) {
         $result['done'] = false;
     } else {
         $result['done'] = true;
         $status = sprintf(__('Finished! Generating index for %s entries took %s seconds '), $PIVOTX['db']->get_entries_count(), $time);
         $output .= sprintf("<br />\n<b>%s</b><br />\n", $status);
     }
     $result['text'] = $output;
     echo json_encode($result);
 }