I am moving my user search from vanilla Views to the Search API/Solr backend/Facet API with Views.

On my site, I have a Countries field on the user profile, and I would like to give users the option to choose between two options: from Japan or not from Japan.

In Views, I did this using a grouped filter:

views grouped filter

Now I am trying to make a facet that does the same thing. However, I don't think this is possible from the Facet UI, even with Facet API Bonus installed. There appears to be no way to provide users with the choice of A or NOT A for a facet that has 100+ values.

How can I implement this A or NOT A search using the Facet API for a specific facet?

  • I recently had this on boolean value fields where the default was either "1" or "0" unless you set a label. This was for unique fields though with a facet for each, not ideal in your case as you would need a unique boolean checkbox on/off field for each country.
    – Collins
    Commented Jun 4, 2015 at 12:18

1 Answer 1


Based on this article, I was able to do this with the following code:

 * Implements hook_entity_property_info_alter().
function MYMODULE_entity_property_info_alter(&$info) {
  $info['user']['properties']['agg_nat'] = array(
    'type' => 'text',
    'label' => t('Search API Agg Nationality'),
    'sanitized' => TRUE,
    'getter callback' => 'MYMODULE_search_agg_nat_getter_callback',

 * Getter callback for agg nationality property.
function MYMODULE_search_agg_nat_getter_callback($item) {
  // Need to load the user object to get fields
  $account = user_load($item->uid);
  $nationality = $account->field_gen_nationality['und'][0]['iso2'];
  switch ($nationality) {
    case 'JP':
      return 'ja';
      return 'en';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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