I allow users to vote via Fivestar CCK and am interested in including a block that will allow users to sort content from highest to lowest and vice versa in the search results page via the Apache Solr Search Integration module. Solr search is way better than that of Core’s and as such, I chose to utilize Solr. This would be an awesome feature and I’m hoping someone can help.

Comments

wonder95’s picture

See my issue in the Fivestar issue queue for a similar question on getting the Fivestar data for Solr. In your case, once you have the Fivestar data, you would just need to implement the hook_apachesolr_prepare_query() and hook_apachesolr_update_index() hooks in your module. hook_apachesolr_update_query() adds the data to the Solr index, and hook_apachesolr_prepare_query() adds the sort option to the Apache Solr Core: Sorting block.

As an example, here's an implementation I wrote that adds a custom sort on node views based on data in the statistics module:

/**
 * Implementation of hook_apachesolr_prepare_query
 */
function mymodule_apachesolr_prepare_query(&$query, &$params) {
  $query->set_available_sort('tis_hit_count', array(
    'title' => t('Number of Views'),
    'default' => 'asc',
  )); 
}

/**
 * Implementation of hook_apachesolr_update_index()
 */
function mymodule_apachesolr_update_index(&$document, $node) {
  //Get count from node_counter table
  $count = db_result(db_query("SELECT totalcount FROM {node_counter} WHERE nid = %d", $node->nid));
  
  //Add field to index
 if ($count !== FALSE) {
  $document->tis_hit_count = (int) $count;
 }
}

As you can see, it doesn't require much code at all. I'd be willing to bet Robert and James would be willing to accept a patch for this, too.

The video from the session at Drupalcon San Francisco on Apache Solr Search Mastery gives a lot of great info on how to do this.

AntiNSA’s picture

I cant get it to sort properly ... I get this error http://drupal.org/node/802230 not using Solr.

dbt102’s picture

Assigned: Unassigned » dbt102
Issue summary: View changes
Status: Active » Closed (won't fix)

Fivestar for Drupal 6

Drupal 6 is now end of life, and is no longer supported. So Drupal 6 issues for Fivestar are being closed as "Closed (won't fix)". However, we don't want users who are porting from Drupal 6 to 7 to feel unwanted, so if you have any migration issues, please open them as Drupal 7 issues.