'10', '8:1000.0' => '9', '8:700.0' => '8', '8:500.0' => '7', '4:300.0' => '6', '4:200.0' => '5', '4:150.0' => '4', '2:150.0' => '3', '2:100.0' => '2', '1:100.0' => '1', '0:0' => t('Normal'), ); $form['biasing']['apachesolr_votingapi_boost'] = array( '#type' => 'select', '#options' => $options, '#title' => t('Higher votes bias'), '#default_value' => $vote_settings, '#description' => t('This setting will change the result scoring so that nodes with better average vote scores may appear before those with higher keyword matching.'), '#weight' => -2, ); } /** * Retrieve which tally is being used by this site as a basis for Solr sorting. See README.txt * * @return array * A $criteria array for use by votingapi_select_single_result_value(). */ function apachesolr_votingapi_get_criteria() { $criteria_default = array( 'title' => t('Rating'), 'content_type' => 'node', 'value_type' => 'points', 'function' => 'average', 'tag' => 'vote', ); return variable_get('apachesolr_votingapi_criteria', $criteria_default); } /** * Implementation of hook_apachesolr_update_index(). */ function apachesolr_votingapi_apachesolr_update_index(&$document, $node) { // Sites may alter the variable 'apachesolr_votingapi_criteria' in order to pick the result used for indexing. See README.txt $criteria = apachesolr_votingapi_get_criteria(); $criteria['content_id'] = $node->nid; // Nodes without any votes will get indexed as 0. $value = (int)votingapi_select_single_result_value($criteria); $document->fs_votingapi_result = $value; } /** * Implementation of hook_apachesolr_modify_query(). * * Inject admin specified boost for voting. */ function apachesolr_votingapi_apachesolr_modify_query(&$query, &$params) { // Retrieve the votingapi result in the field list. $params['fl'] .= ',fs_votingapi_result'; // Apply boost based on votes. Based on the boost for comment_count. $vote_settings = variable_get('apachesolr_votingapi_boost', '0:0'); // Get $total. Copied from apachesolr_search_search $solr = apachesolr_get_solr(); $data = $solr->getLuke(); if (isset($data->index->numDocs)) { $total = $data->index->numDocs; } else { $total = db_result(db_query("SELECT COUNT(nid) FROM {node}")); } list($vote_steepness, $vote_boost) = explode(':', $vote_settings); if ($vote_boost) { $params['bf'][] = "recip(rord(fs_votingapi_result),$vote_steepness,$total,$total)^$vote_boost"; } } /** * Implementation of hook_apachesolr_prepare_query(). * * Add votes as a sort. */ function apachesolr_votingapi_apachesolr_prepare_query(&$query) { $criteria = apachesolr_votingapi_get_criteria(); $query->set_available_sort('fs_votingapi_result', array( 'title' => $criteria['title'], 'default' => 'desc', )); } /** * Implementation of hook_votingapi_results(). * * When a vote's tallys are recalculated, mark the node for re-indexing. */ function apachesolr_votingapi_votingapi_results($cached, $content_type, $content_id) { $criteria = apachesolr_votingapi_get_criteria(); if ($content_type == $criteria['content_type']) { apachesolr_mark_node($content_id); } } /** * Implementation of hook_enable(). */ function apachesolr_votingapi_enable() { drupal_set_message(t('The Apache Solr votingapi integration module will take effect as nodes when votes are indexed or re-indexed.')); }