1

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

stopshinal
  • 1,891
  • 4
  • 16
  • 24

1 Answers1

1

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

32i
  • 626
  • 4
  • 12
  • Will this also work for the Solar API with SOLR search? I'm not using the apache search integration. But I suppose this may make or break my decision to go that route. – stopshinal Sep 29 '11 at 14:10
  • mhmh, apachesolr - that's the name of the module, which provides solr integration with Drupal. It provides schema.xmk and solrconfig as well, so drupal can communicate with Solr. That's not apache search, it's just called in this way. – 32i Sep 30 '11 at 10:51
  • https://www.drupal.org/project/apachesolr vs. https://www.drupal.org/project/search_api_solr. This is two different module in drupal so i think it will not working. – zsd Jun 01 '15 at 14:32