diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-11-01 21:46:16 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-11-01 21:46:16 +0000 |
commit | 1eae549bd6fd9bcc134d139f4dec9275db82a31e (patch) | |
tree | 9c4e7fecc1d5c8eae48ff9ba8dc3da6f8a3e16e6 /modules | |
parent | ca8eee7545f75c199bde0121bd6a0792d67c5b91 (diff) | |
download | brdo-1eae549bd6fd9bcc134d139f4dec9275db82a31e.tar.gz brdo-1eae549bd6fd9bcc134d139f4dec9275db82a31e.tar.bz2 |
#615508 by Crell: Use slave servers for search module.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/node/node.module | 26 | ||||
-rw-r--r-- | modules/search/search.module | 10 |
2 files changed, 18 insertions, 18 deletions
diff --git a/modules/node/node.module b/modules/node/node.module index 7fecc2a74..6a25cfc05 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -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); diff --git a/modules/search/search.module b/modules/search/search.module index 07c369366..c64d38297 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -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; |