Commit 1eae549b authored by webchick's avatar webchick

#615508 by Crell: Use slave servers for search module.

parent ca8eee75
......@@ -1228,7 +1228,7 @@ public function union(SelectQueryInterface $query, $type = '') {
case '':
$type = 'UNION';
break;
case 'ALL':
$type = 'UNION ALL';
default:
......
......@@ -1141,7 +1141,7 @@ function node_build($node, $build_mode = 'full') {
$build = $node->content;
// We don't need duplicate rendering info in node->content.
unset($node->content);
$build += array(
'#theme' => 'node',
'#node' => $node,
......@@ -1316,7 +1316,7 @@ function template_preprocess_node(&$variables) {
// Flatten the node object's member fields.
$variables = array_merge((array)$node, $variables);
// Helpful $content variable for templates.
foreach (element_children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
......@@ -1490,7 +1490,7 @@ function node_search_admin() {
$form['content_ranking']['info'] = array(
'#value' => '<em>' . t('The following numbers control which properties the content search should favor when ordering the results. Higher numbers mean more influence, zero means the property is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') . '</em>'
);
// Note: reversed to reflect that higher number = higher ranking.
$options = drupal_map_assoc(range(0, 10));
foreach (module_invoke_all('ranking') as $var => $values) {
......@@ -1509,13 +1509,13 @@ function node_search_admin() {
*/
function node_search_execute($keys = NULL) {
// Build matching conditions
$query = db_select('search_index', 'i')->extend('SearchQuery')->extend('PagerDefault');
$query = db_select('search_index', 'i', array('target' => 'slave'))->extend('SearchQuery')->extend('PagerDefault');
$query->join('node', 'n', 'n.nid = i.sid');
$query
->condition('n.status', 1)
->addTag('node_access')
->searchExpression($keys, 'node');
// Insert special keywords.
$query->setOption('type', 'n.type');
$query->setOption('language', 'n.language');
......@@ -1526,19 +1526,19 @@ function node_search_execute($keys = NULL) {
if (!$query->executeFirstPass()) {
return array();
}
// Add the ranking expressions.
_node_rankings($query);
// Add a count query.
$inner_query = clone $query;
$count_query = db_select($inner_query->fields('i', array('sid')));
$count_query = db_select($inner_query->fields('i', array('sid')), NULL, array('target' => 'slave'));
$count_query->addExpression('COUNT(*)');
$query->setCountQuery($count_query);
$find = $query
->limit(10)
->execute();
// Load results.
$results = array();
foreach ($find as $item) {
......@@ -1546,14 +1546,14 @@ function node_search_execute($keys = NULL) {
$node = node_load($item->sid);
node_build_content($node, 'search_result');
$node->rendered = drupal_render($node->content);
// Fetch comments for snippet.
$node->rendered .= ' ' . module_invoke('comment', 'node_update_index', $node);
// Fetch terms for snippet.
$node->rendered .= ' ' . module_invoke('taxonomy', 'node_update_index', $node);
$extra = module_invoke_all('node_search_result', $node);
$results[] = array(
'link' => url('node/' . $item->sid, array('absolute' => TRUE)),
'type' => check_plain(node_type_get_name($node)),
......@@ -2161,7 +2161,7 @@ function node_page_view(stdClass $node) {
function node_update_index() {
$limit = (int)variable_get('search_cron_limit', 100);
$result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit);
$result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit, array(), array('target' => 'slave'));
foreach ($result as $node) {
_node_index_node($node);
......
......@@ -327,7 +327,7 @@ function search_update_totals() {
// Update word IDF (Inverse Document Frequency) counts for new/changed words.
foreach (search_dirty() as $word => $dummy) {
// Get total count
$total = db_query("SELECT SUM(score) FROM {search_index} WHERE word = :word", array(':word' => $word))->fetchField();
$total = db_query("SELECT SUM(score) FROM {search_index} WHERE word = :word", array(':word' => $word), array('target' => 'slave'))->fetchField();
// Apply Zipf's law to equalize the probability distribution.
$total = log10(1 + 1/(max(1, $total)));
db_merge('search_total')
......@@ -338,7 +338,7 @@ function search_update_totals() {
// Find words that were deleted from search_index, but are still in
// search_total. We use a LEFT JOIN between the two tables and keep only the
// rows which fail to join.
$result = db_query("SELECT t.word AS realword, i.word FROM {search_total} t LEFT JOIN {search_index} i ON t.word = i.word WHERE i.word IS NULL");
$result = db_query("SELECT t.word AS realword, i.word FROM {search_total} t LEFT JOIN {search_index} i ON t.word = i.word WHERE i.word IS NULL", array(), array('target' => 'slave'));
$or = db_or();
foreach ($result as $word) {
$or->condition('word', $word->realword);
......@@ -553,7 +553,7 @@ function search_index($sid, $type, $text) {
$linknid = $match[1];
if ($linknid > 0) {
// Note: ignore links to uncacheable nodes to avoid redirect bugs.
$node = db_query('SELECT title, nid, vid FROM {node} WHERE nid = :nid', array(':nid' => $linknid))->fetchObject();
$node = db_query('SELECT title, nid, vid FROM {node} WHERE nid = :nid', array(':nid' => $linknid), array('target' => 'slave'))->fetchObject();
$link = TRUE;
$linktitle = $node->title;
}
......@@ -650,7 +650,7 @@ function search_index($sid, $type, $text) {
$result = db_query("SELECT nid, caption FROM {search_node_links} WHERE sid = :sid AND type = :type", array(
':sid' => $sid,
':type' => $type
));
), array('target' => 'slave'));
$links = array();
foreach ($result as $link) {
$links[$link->nid] = $link->caption;
......@@ -716,7 +716,7 @@ function search_touch_node($nid) {
*/
function search_node_update_index(stdClass $node) {
// Transplant links to a node into the target node.
$result = db_query("SELECT caption FROM {search_node_links} WHERE nid = :nid", array(':nid' => $node->nid));
$result = db_query("SELECT caption FROM {search_node_links} WHERE nid = :nid", array(':nid' => $node->nid), array('target' => 'slave'));
$output = array();
foreach ($result as $link) {
$output[] = $link->caption;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment