From afa9692191617147bf010918d7c8f844685d0b79 Mon Sep 17 00:00:00 2001 From: Jared Hancock Date: Tue, 10 Mar 2015 10:18:57 -0500 Subject: [PATCH] search: Quit indexing when complete, drop work break iterator for now --- include/class.format.php | 2 +- include/class.search.php | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/include/class.format.php b/include/class.format.php index e597de6185..53ad259c6e 100644 --- a/include/class.format.php +++ b/include/class.format.php @@ -570,7 +570,7 @@ function searchable($text, $lang=false) { // Drop leading and trailing whitespace $text = trim($text); - if (class_exists('IntlBreakIterator')) { + if (false && class_exists('IntlBreakIterator')) { // Split by word boundaries if ($tokenizer = IntlBreakIterator::createWordInstance( $lang ?: ($cfg ? $cfg->getSystemLanguage() : 'en_US')) diff --git a/include/class.search.php b/include/class.search.php index fd8c7e2cff..47254dd407 100644 --- a/include/class.search.php +++ b/include/class.search.php @@ -202,19 +202,37 @@ function bootstrap() { } } +require_once(INCLUDE_DIR.'class.config.php'); +class MySqlSearchConfig extends Config { + var $table = CONFIG_TABLE; + + function __construct() { + parent::Config("mysqlsearch"); + } +} + class MysqlSearchBackend extends SearchBackend { static $id = 'mysql'; static $BATCH_SIZE = 30; // Only index 20 batches per cron run var $max_batches = 60; + var $_reindexed = 0; function __construct() { $this->SEARCH_TABLE = TABLE_PREFIX . '_search'; } + function getConfig() { + if (!isset($this->config)) + $this->config = new MySqlSearchConfig(); + return $this->config; + } + + function bootstrap() { - Signal::connect('cron', array($this, 'IndexOldStuff')); + if ($this->getConfig()->get('reindex', true)) + Signal::connect('cron', array($this, 'IndexOldStuff')); } function update($model, $id, $content, $new=false, $attrs=array()) { @@ -588,7 +606,10 @@ function IndexOldStuff() { // FILES ------------------------------------ // Flush non-full batch of records - $this->__index(null, true); + if (!$this->_reindexed) { + // Stop rebuilding the index + $this->getConfig()->set('reindex', 0); + } } function __index($record, $force_flush=false) { @@ -608,9 +629,10 @@ function __index($record, $force_flush=false) { $sql = 'INSERT INTO `'.TABLE_PREFIX.'_search` (`object_type`, `object_id`, `title`, `content`) VALUES '.implode(',', $queue); - if (!db_query($sql) || count($queue) != db_affected_rows()) + if (!db_query($sql, false) || count($queue) != db_affected_rows()) throw new Exception('Unable to index content'); + $this->_reindexed += count($queue); $queue = array(); if (!--$this->max_batches)