2

I'm attempting to sort nodes by ratings using the Search API faceted search with Solr integration. I've already set up fivestar ratings (about 9 per node, its a large multi-axis rating system.) but i'm unable to index these ratings!

Can someone help me understand how to change this so I can use a facet search for ratings?

Otherwise, are there any recommendations on other modules (aside from fivestar) which would allow the votes to be indexed?

Thank you!

Justin

3

You can best create a new Entity property in a hook_entity_property_info_alter(), and add a custom field "rating" with a custom getter callback. Like so:

...
      $properties = &$info['flatrow']['properties'];
      $properties['my_indexable_rating_axis_1'] = array(
        'type' => 'integer',
        'label' => t('Rating axis 1'),
        'query callback' => 'entity_metadata_table_query',
        'getter callback' => 'rating_axis_one_get_properties',
      );
      return $properties;
...

Use it to extend the node entity. The getter callback is where you retrieve the value to be indexed,

function rating_axis_one_get_properties($entity, array $options, $name, $entity_type) {
  $value = $node->field_fivestar['average_rating']; // I made this up, check how to do it

  return $value;
}

Then index the field with Search API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.