0

I am using Domain and Search API Solr module in my project. On all domains, searching for a content gets result(content) from all domains. I would like to get search results according to the domain.
For example, if a user is on domain a.domain.com, then the search should return content which is published on a.example.com only and not on any other domains or sub-domains.

1

You could take a look at Search API Domain Access sandbox project: https://www.drupal.org/sandbox/raf/2244229

I did a work around based on that code that worked for me:

<?php
/**
 * Implements hook_entity_property_info_alter().
 *
 * Adds an entity property for the domain access of the node.
 *
 * @TODO this is just a workaround @see https://www.drupal.org/sandbox/raf/2244229
 */
function my_module_entity_property_info_alter(&$info) {
  $properties = &$info['node']['properties'];
  $properties['my_module_domain_access'] = array(
    'label' => t('My Domain Access Information'),
    'description' => t('The domains to which the node is published.'),
    'type' => 'list<integer>',
    'getter callback' => 'my_module_get_domain_info',
  );
}

/**
 * Custom getter callback for the domains in
 *
 * @param $data
 * @param array $options
 * @param $name
 * @param $type
 * @param $info
 * @return null
 */
function my_module_get_domain_info($data, array $options, $name, $type, $info) {
  return (!empty($data->domains) ? $data->domains : NULL);
}

/**
 * Implements hook_search_api_query_alter().
 *
 * Adds a filter for the current domain.
 */
function my_module_search_api_query_alter(SearchApiQueryInterface $query) {
  $domain = domain_get_domain();
  $query->condition('my_module_domain_access', $domain['domain_id']);
}

Now, you will be able to choose the field for indexing under "admin/config/search/search_api/index/your_index/fields" and in query time this code will filter out data based on current domain, not many more things.

Hope it helps, but notice that this code it is not fully tested (nodes that have been published in more than one domain... etc).

0

In your Search View set the use current domain as a View filter.

1
  • A view build on the Search index doesn't have "domain" filters... I'm stuck with the same issue and I'm trying to find a proper solution! – Michiel Mar 26 '14 at 14:29

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.