0

I have a facet for a field, the values of which are:

(FACETAPI DEFAULT)

  • yes (db: y)
  • no (db: n)
  • maybe (db: m)

By default, the facet shows all three of these options. However, I only want to show yes or no to the user, and I want to include the value of maybe in both:

(WHAT I WANT)

  • yes (db: y or m)
  • no (db: (n or m)

What I have tried

I know I could try to do an OR search with the facet and rewrite my links to search both, but I don't want to give users the option to search just "maybe"; I only want two options, not three.

It would be great if there was a stable version of the Apachesolr Facet Builder for D7. One can dream...

I am using the Facet API Bonus module but this allows me to "Rewrite items" or "Exclude items," not combine three items into two as I described above.

I read this wunderkraut article on extending Facet API but it covers adding sorts, plugins, widgets, dependencies, and the like-- not the facets themselves.

I also looked at this wunderkraut article, which suggests I should use something like hook_facetapi_facet_info_alter(), but I don't know how to edit the field values to combine them.

0

I decided to implement this by creating a new facet instead of editing an existing one. This article describes the process.

The basic code looks like this:

/**
 * Implements hook_entity_property_info_alter().
 */
function MYMODULE_entity_property_info_alter(&$info) {
  $info['user']['properties']['agg_gender'] = array(
    'type' => 'text',
    'label' => t('Search API Agg Gender'),
    'sanitized' => TRUE,
    'getter callback' => 'MYMODULE_search_agg_gender_getter_callback',
  );
}

/**
 * Getter callback for agg gender property.
 */
function MYMODULE_search_agg_gender_getter_callback($item) {
  // Need to load the user object to get fields
  $account = user_load($item->uid);
  switch ($account->field_gender['und'][0]['value']) {
    case 'F':
      return 'f';
      break;
    case 'M':
      return 'm';
      break;
    case 'O':
      return 'fm';
      break;
  }
}

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.