I like to have a feature like this:
User should be able to search across sites on demand.There should be a drop down in the search page which shows all domains
ie,if user is on a.site.com by default he should see the search results from domain a.But if he choose another domain ie,b.site.com he can see the search results of b.If he choose all he should see all the results from all domains.
Is this possible.If yes where should I make the changes.Please help.

Comments

agentrickard’s picture

It's not really possible without causing a cascade of problems. Since node access rules are per page-request, if you override those rules for search, then if you have domain-specific menu items, those will also change.

So it's not really possible in Drupal, without causing potentially unwanted behavior.

agentrickard’s picture

Status: Active » Closed (works as designed)

You can. however, do this with Views and Search API module, I believe. Views gives you the ability to disable SQL rewrites, which means you can apply your own filter using Domain Views.

ktrev’s picture

I was thinking of altering the search form.Add a new filter and filter the nodes before displaying based on the domain.
What you suggest seems to be more easy. Thanks for the reply.

ktrev’s picture

I used another method for this.I wrote a custom module that alters the search form.Provided a drop down in the form with the domains and altered the search query as follows.

function search_alter_form_alter(&$form, $form_state, $form_id) {
     if ($form_id == 'search_form') {
	 $_domain = domain_get_domain();   
	$domain_id = $_domain['domain_id'];
	 $form['#submit'][] = 'search_alter_form_submit';
    $form['mode_select'] = array(
    '#type' => 'select',
    '#title' => t('Domain'),
    '#options' => array('1' => 'DOMAIN1','2' => 'DOMAIN2','3' => 'DOMAIN3'),
	'#weight' => 0,
	'#default_value' => (isset($_GET['mode_select']) ? $_GET['mode_select'] : $domain_id),
	   
  );
    }

}
function search_alter_form_submit($form, &$form_state) {
    $path = $form_state['redirect'];
    $options = array(
        'query' => array(
            'mode_select' => $form_state['values']['mode_select']
        )
    );
    drupal_goto($path, $options);
}

function search_alter_query_alter(QueryAlterableInterface $query) {
  if ($query->hasTag('node_access') && $query->hasTag('pager')) {
      $tables = $query->getTables();
	  $site=$_GET['mode_select'];
      foreach ($tables as $table) {
        if ($table['table'] == 'search_index') {
          $query->leftJoin('domain_access', 's', 's.nid = i.sid');
           $query->condition('s.gid', $site);
        }
      }
  }
}