Changeset 1098191
- Timestamp:
- 02/24/2015 03:08:26 PM (11 years ago)
- Location:
- opensearchserver-search/trunk
- Files:
-
- 2 edited
-
index.php (modified) (1 diff)
-
opensearchserver_admin.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
opensearchserver-search/trunk/index.php
r1091184 r1098191 239 239 add_action('admin_menu', 'opensearchserver_admin_actions'); 240 240 add_action('template_redirect', 'opensearchserver_search'); 241 add_filter( 'query_vars', 'add_query_vars_filter' ) 241 add_action('synchronize_with_cron','opensearchserver_synchronize_with_cron' ); 242 add_filter( 'query_vars', 'add_query_vars_filter' ); 242 243 ?> -
opensearchserver-search/trunk/opensearchserver_admin.php
r1085512 r1098191 191 191 * @param number $limit 192 192 */ 193 function opensearchserver_checkindex(OSSIndexDocument $index, $limit = 1, $idx = 0, $total = 0 ) {193 function opensearchserver_checkindex(OSSIndexDocument $index, $limit = 1, $idx = 0, $total = 0 ,$is_not_cron = TRUE) { 194 194 global $wpdb; 195 195 if ($index->count() < $limit) { … … 198 198 opensearchserver_start_indexing($index); 199 199 $index = null; 200 wp_cache_flush(); 201 $wpdb->flush(); 202 if (function_exists('gc_enabled')) { 203 if (gc_enabled()) { 204 gc_collect_cycles(); 205 } 206 } 207 208 if ($idx != 0 && $total != 0) { 209 $percent = (floatval($idx) / floatval($total)) * 100; 210 $mem = floatval(memory_get_usage()) / 1024 / 1024; 211 opensearchserver_display_messages(sprintf('Completed: %.2f %% (%d/%d)- Memory usage: %2f', $percent, $idx, $total, $mem)); 200 if(is_not_cron) { 201 wp_cache_flush(); 202 $wpdb->flush(); 203 if (function_exists('gc_enabled')) { 204 if (gc_enabled()) { 205 gc_collect_cycles(); 206 } 207 } 208 209 if ($idx != 0 && $total != 0) { 210 $percent = (floatval($idx) / floatval($total)) * 100; 211 $mem = floatval(memory_get_usage()) / 1024 / 1024; 212 opensearchserver_display_messages(sprintf('Completed: %.2f %% (%d/%d)- Memory usage: %2f', $percent, $idx, $total, $mem)); 213 } 212 214 } 213 215 return new OSSIndexDocument(); … … 227 229 return $docs_count; 228 230 } 229 230 231 /* 231 * Function to reindex the website .232 * Function to reindex the website with cron. 232 233 */ 233 function opensearchserver_reindex_site($id,$type, $from = 0, $to = 0) { 234 function opensearchserver_reindex_site_with_cron() { 235 global $wpdb; 236 opensearchserver_reindex_init(); 237 opensearchserver_delete_document('*:*'); 238 $contentTypesToKeep = array(); 239 foreach (get_post_types() as $post_type) { 240 if (get_option('oss_index_types_'.$post_type) == 1) { 241 $contentTypesToKeep[] = $post_type; 242 } 243 } 244 $sql_query = 'SELECT ID FROM '.$wpdb->posts.' WHERE post_status = \'publish\' AND post_type IN ("'.implode('","', $contentTypesToKeep).'") ORDER BY ID'.$limitSuffix; 245 $posts = $wpdb->get_results($sql_query); 246 $total_count = count($posts); 247 $index = new OSSIndexDocument(); 248 for ($i = 0; $i < $total_count; $i++) { 249 $post = get_post($posts[$i]->ID); 250 opensearchserver_add_documents_to_index($index, $lang, $post); 251 $index = opensearchserver_checkindex($index, 200, $i, $total_count, FALSE); 252 } 253 opensearchserver_checkindex($index, 1, $i, $total_count,FALSE); 254 opensearchserver_optimize(); 255 opensearchserver_autocompletionBuild(); 256 return 1; 257 } 258 /* 259 * Function to initialize the variable for reindex. 260 */ 261 function opensearchserver_reindex_init() { 234 262 global $wpdb; 235 263 $oss_server_url = get_option('oss_serverurl'); … … 244 272 $ossEngineConnectTimeOut = config_request_value('ossEngineConnectTimeOut', 5, 'engineConnectTimeOut'); 245 273 $ossEngineIndex = config_request_value('ossEngineIndex', $oss_indexname, 'engineIndex'); 274 } 275 /* 276 * Function to reindex the website. 277 */ 278 function opensearchserver_reindex_site($id,$type, $from = 0, $to = 0) { 279 global $wpdb; 280 opensearchserver_reindex_init(); 246 281 if($id) { 247 282 $delete='id:'.$type.'_'.$id; … … 858 893 859 894 function opensearchserver_admin_set_reindex() { 860 $oss_index_from = isset($_POST['oss_index_from']) ? $_POST['oss_index_from'] : NULL; 861 $oss_index_to = isset($_POST['oss_index_to']) ? $_POST['oss_index_to'] : NULL; 862 update_option('oss_index_from', $oss_index_from); 863 update_option('oss_index_to', $oss_index_to); 864 $index_success = opensearchserver_reindex_site(NULL,NULL, $oss_index_from, $oss_index_to); 865 $suffix = ($oss_index_from !== null && $oss_index_from != '' && $oss_index_to !== null && $oss_index_to != '') ? '(indexed documents from #'.$oss_index_from.' to #'.$oss_index_to.')' : ''; 866 opensearchserver_display_messages('Re indexing has been finished successfully '. $suffix .'.'); 867 } 895 $post_oss_submit = $_POST['opensearchserver_submit']; 896 if($post_oss_submit == 'Synchronize with CRON') { 897 wp_schedule_single_event(time(), 'synchronize_with_cron'); 898 opensearchserver_display_messages('Re indexing has been successfully scheduled with cron will be executed in next 15 minutes.'); 899 }else { 900 $oss_index_from = isset($_POST['oss_index_from']) ? $_POST['oss_index_from'] : NULL; 901 $oss_index_to = isset($_POST['oss_index_to']) ? $_POST['oss_index_to'] : NULL; 902 update_option('oss_index_from', $oss_index_from); 903 update_option('oss_index_to', $oss_index_to); 904 $index_success = opensearchserver_reindex_site(NULL,NULL, $oss_index_from, $oss_index_to); 905 $suffix = ($oss_index_from !== null && $oss_index_from != '' && $oss_index_to !== null && $oss_index_to != '') ? '(indexed documents from #'.$oss_index_from.' to #'.$oss_index_to.')' : ''; 906 opensearchserver_display_messages('Re indexing has been finished successfully '. $suffix .'.'); 907 } 908 } 909 /* 910 * Re-index using cron 911 */ 912 function opensearchserver_synchronize_with_cron() { 913 opensearchserver_reindex_site_with_cron(); 914 } 915 916 868 917 /* 869 918 * The admin page settings actions … … 911 960 } elseif ($action == 'opensearchserver_reindex') { 912 961 opensearchserver_admin_set_reindex(); 913 } elseif ($action == 'opensearchserver_advanced_settings') {962 }elseif ($action == 'opensearchserver_advanced_settings') { 914 963 opensearchserver_admin_set_advanced_settings(); 915 964 } … … 1537 1586 name="opensearchserver_submit" value="Synchronize / Re-Index" 1538 1587 class="button-primary" /> 1588 <input type="submit" 1589 name="opensearchserver_submit" value="Synchronize with CRON" 1590 class="button-primary" /> 1539 1591 </p> 1540 1592 </form>
Note: See TracChangeset
for help on using the changeset viewer.