public static function doIndex(TableCtl $controller, $fields = array('content')) { if (!is_array($fields)) { $fields = array($fields); } //TODO This is a bad idea. rather use a query and while $object = $controller->get_list('all', 0); $total = false; if ($object->list) { $total = 0; $first = current($object->list); foreach ($fields as $field) { if (array_key_exists($field, $first)) { $result = 0; foreach ($object->list as $row) { $info = str_word_count($row[$field], 1); $counts = array_count_values($info); $sequence = 0; foreach ($counts as $word => $count) { unset($counts[$word]); if ($word = self::filter($word, $count)) { $data = array('table' => $object->getSource(), 'table_id' => $row[$object->getMeta('id_field')], 'word' => $word, 'count' => $count, 'sequence' => $sequence++); $b_search = new BackendSearchObj(); if ($b_search->replace($data)) { $result++; $total++; } else { if ($b_search->error_msg != 'Error executing statement(1062)') { Backend::addError('Could not add ' . $word . ' to ' . get_class($controller) . '::' . $field . ' index'); } } } } } if ($result > 0) { Backend::addSuccess($result . ' words were indexed for ' . get_class($controller) . '::' . $field); } } else { Backend::addError($field . ' does not exist in ' . get_class($object)); } } } return $total; }