/** * This is the real full index building process. It is meant to be kicked off * by $this->buildFullIndex(...) via registration with the PHP shutdown function. * It will continue running after the conenction with the client closes. * Don't call this directly. It must be public to work with the PHP shutdown * function handler. * @param bool $index_comments * @param bool $index_categories */ public function asyncBuildFullIndex($index_comments = FALSE, $index_categories = FALSE) { try { WPSearch_Log::add('debug', "Starting index build .."); $timer = "Index build process"; WPSearch_Benchmark::start($timer); $page = 0; $per_page = 20; $total = WPSearch_Model::getPublishedPostCount(); $index = $this->_getIndex(true); $started = time(); do { WPSearch_Log::add('debug', "Pulling down page {$page}, with {$per_page} rows"); $post_batch = WPSearch_Model::getPublishedDocuments($page, $per_page); WPSearch_Log::add('debug', "Got " . count($post_batch) . " posts back .."); if (count($post_batch) == 0) { break; } foreach ($post_batch as $post) { $comments = $index_comments ? $this->_getCommentsAsString($post->ID) : FALSE; $categories = $index_categories ? $this->_getCategoriesAsStrings($post->ID) : FALSE; # WPSearch_Log::add('debug', "Indexing post: $post->ID"); $index->addDocument($this->_createLuceneDocument($post, $categories, $comments)); } # TODO: Output status to file $status = array('total' => $total, 'current' => $page * $per_page, 'last_rebuild' => $started, 'reindexing' => true, 'last_updated' => time()); $this->_setStatusInfo($status); $page++; } while (true); $index->commit(); $index->optimize(); WPSearch_Log::add('debug', "Completing index build .."); $this->_deleteStatusInfo(); $this->_setRebuildTime(); WPSearch_Benchmark::stop($timer); } catch (Exception $ex) { WPSearch_Log::add('error', "Exception during index! " . $ex->__toString()); } }