Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.967 diff -u -p -r1.967 node.module --- modules/node/node.module 26 May 2008 17:12:55 -0000 1.967 +++ modules/node/node.module 19 Jun 2008 00:03:20 -0000 @@ -1355,6 +1355,13 @@ function node_ranking() { // The promote flag is either 0 or 1, which is automatically normalized. 'score' => 'n.promote', ), + 'links' => array( + 'title' => t('Incoming Links'), + 'score' => '2.0 - 2.0 / (1.0 + search_node_links_totals.count * %f)', + 'join' => 'LEFT JOIN {search_node_links_totals} search_node_links_totals ON search_node_links_totals.sid = i.sid', + 'arguments' => array(variable_get('node_rank_links', '0')), + ) + ); // Add relevance based on creation or changed date. Index: modules/search/search.install =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.install,v retrieving revision 1.15 diff -u -p -r1.15 search.install --- modules/search/search.install 15 Mar 2008 12:31:29 -0000 1.15 +++ modules/search/search.install 19 Jun 2008 00:03:20 -0000 @@ -153,6 +153,73 @@ function search_schema() { 'nid' => array('nid'), ), ); + + $schema['search_node_links_totals'] = array( + 'description' => t('Counts the number of incoming links for each node.'), + 'fields' => array( + 'sid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'deafult' => 0, + 'description' => t('The {search_dataset}.sid of the searchable item containing the link to the node.') + ), + 'type' => array( + 'type' => 'varchar', + 'length' => 16, + 'not null' => TRUE, + 'description' => t('The {search_dataset}.type of the searchable item containing the link to the node.') + ), + 'count' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => t('The number of links that the searchable item has linking to it') + ), + ), + 'primary key' => array('sid'), + 'indexes' => array( + 'node_count' => array('count'), + ), + ); return $schema; } + +function search_update_1() { + $ret = array(); + + $schema['search_node_links_totals'] = array( + 'description' => t('Counts the number of incoming links for each node.'), + 'fields' => array( + 'sid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'deafult' => 0, + 'description' => t('The {search_dataset}.sid of the searchable item containing the link to the node.') + ), + 'type' => array( + 'type' => 'varchar', + 'length' => 16, + 'not null' => TRUE, + 'description' => t('The {search_dataset}.type of the searchable item containing the link to the node.') + ), + 'count' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => t('The number of links that the searchable item has linking to it') + ), + ), + 'primary key' => array('sid'), + 'indexes' => array( + 'node_count' => array('count'), + ), + ); + + db_create_table($ret, 'search_node_links_totals', $schema['search_node_links_totals']); + return $ret; +} Index: modules/search/search.module =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.module,v retrieving revision 1.258 diff -u -p -r1.258 search.module --- modules/search/search.module 26 May 2008 17:22:59 -0000 1.258 +++ modules/search/search.module 19 Jun 2008 00:03:21 -0000 @@ -613,6 +613,12 @@ function search_index($sid, $type, $text db_query("DELETE FROM {search_node_links} WHERE sid = %d AND type = '%s' AND nid = %d", $sid, $type, $nid); search_touch_node($nid); } + // Update node_links_totals count for this node + $count = db_result(db_query("SELECT COUNT(nid) as count FROM {search_node_links} WHERE nid = %d AND type = '%s'", $sid, $type)); + $query = db_query("UPDATE {search_node_links_totals} SET count = %d WHERE sid = %d AND type = '%s'", $count, $sid, $type); + if (!db_affected_rows()) { + $query = db_query("INSERT INTO {search_node_links_totals} (sid, type, count) VALUES (%d, '%s', %d)", $sid, $type, $count); + } } /**