开发者

Search API Solr integration with fivestar (or similar) rating system (fascet and sort)

开发者_如何转开发

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


first you need install facetapi module -that's for facets. second, on hook_update_index, you need to add rating to apachesolr index

<?php function module_apachesolr_update_index(&$document, $node) {
    //add additional offers;
    if (count($node->field_add_offers)) {
      $field = $node->field_add_offers;
      foreach ($field as $lang => $values) {
        foreach ($values as $value) {
          if (isset($value['value'])) {
            $document->setMultiValue('sm_offers', $value['value']);
          }
        }
      }
    }
} ?>

Please note, it's just an example. I run 2 loops because of multilingual site and problem with this "und" key in field array. Here also you can not add all ratings, but calculate, for instance,one modifier per node, which will be used for sorting (if you don't have that one in ratings)

Third, add facets with using hook_facetapi_facet_info

<?php function module_facetapi_facet_info(array $searcher_info) {
  return array(
    'sm_games_facet' => array(
      'name' => 'sm_games_facet',
      'label' => t('games'),
      'description' => t('Filter games'),
      'field' => 'sm_games',
      'field alias' => 'game',
      'query type' => 'term',
      'default widget' => 'facetapi_links',
      'allowed operators' => array(FACETAPI_OPERATOR_OR => TRUE, FACETAPI_OPERATOR_AND => TRUE),
      'default sorts' => array(
        array('display', SORT_ASC),
      ),
    )
);
} ?>

more about facets you can find at facetapi.api.php file;

Forth - reindex content and enable facet in apachesolr settings.

Regards, Slava

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜