Skip to content

Commit

Permalink
search: Quit indexing when complete, drop work break iterator for now
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Hancock committed Mar 10, 2015
1 parent f9997d8 commit afa9692
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/class.format.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
28 changes: 25 additions & 3 deletions include/class.search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down

0 comments on commit afa9692

Please sign in to comment.