3

I've got a site with multiple domains using Domain Access. I want to display a search form on each site that searches for users on that site.

I'm using a modified version of the code here (that code works fine when searching for nodes) but it doesn't work. When searching it always return an empty result.

Here's my code:

/**
* Implements hook_entity_property_info_alter().
*
* Adds an entity property for the domain access of the user.
*/
function custom_search_users_entity_property_info_alter(&$info) {
  $properties = &$info['user']['properties'];

  $properties['custom_search_users_domain_access'] = array(
    'label' => t('Domain Access Information'),
    'description' => t('The domains to which the user has access.'),
    'type' => 'list<integer>',
    'getter callback' => 'custom_search_users_get_domain_info',
  );
}

function custom_search_users_get_domain_info($data, array $options, $name, $type, $info) {
  return (!empty($data->domain_user) ? $data->domain_user : NULL);
}

/**
* Implements hook_search_api_query_alter().
*
* Adds a filter for the current domain.
*/
function custom_search_users_search_api_query_alter(SearchApiQueryInterface $query) {
  $domain = domain_get_domain();

  $query->condition('custom_search_users_domain_access', $domain['domain_id']);
}

So basically what I've changed in my code is the use of $data->domain_user instead of $data->domain to comply with the user object.

Anyone got any idea of why this doesn't work?

1

I think your approach is just fine, but you forgot to index your field. You've to check the field you created on the field page (admin/config/search/search_api/index/**your_index**/fields)

enter image description here

Once checked, you'll be able to index your extra field and by so, filter on domain.

1
  • Hi a bit late to the party but, I cannot see the Domain Access information field in my search index fields tab. Nov 14 '17 at 16:22

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.