I have two sites, each set up with search_api and search_api_solr. Site A has been set up with a solr server and is using the Default node index, this is working as expected. I would like to have Site B set up so that it can connect to Site A's Default node index and return search results from Site A. Is this possible?

My attempts to date end up with Site B creating a new index on Site A's solr server instead of being able to access the existing index.

I have started investigating sarnia (http://drupal.org/project/sarnia) as a possible solution, however it has compatibility issues with the current search_api_solr release (https://drupal.org/node/1884572 and https://drupal.org/node/2013134).

Any pointers or suggestions are greatly appreciated.

Comments

drunken monkey’s picture

Create the same server and index setup on site B as well, with the only difference being that you should mark the search index on site B read-only. It is especially important that both indexes have the same machine name!
Then, set the search server on site B up to retrieve result data directly from Solr.
After that, you should be able to retrieve results from site A on site B. However, all metadata used by Views (e.g., existing fields, options, etc.) will be from site B, and things like "Link this field to its entity" will link to site B. So you'd have to work around that in a custom way.

Other than that, wait until Sarnia's problems are fixed and then use that.

Beanjammin’s picture

Thank you for the very quick response, I will give this another shot and report back.

Beanjammin’s picture

Status: Active » Closed (works as designed)

My initial issue must have been a machine name mismatch. Now that I have made sure that the index names between the two sites match I am able to search the content in site A's index from site B.

Thanks again for your help drunken monkey!

Beanjammin’s picture

Status: Closed (works as designed) » Active

Sorry to re-open this, but I've run into a bump:

When the search results from Site A include an nid that exists on Site B (the site local to the search) any field that would be empty based on the solr index contents *and* that has a matching equivalent in the node with the same nid on Site B (ie Body) gets populated with the content from Site B.

Is there anyway to disable the local node being loaded and its fields being used? I have checked "Retrieve result data from Solr", but I take it this doesn't disable the node being loaded.

drunken monkey’s picture

No, it really doesn't and I'm sorry to say that I also don't know of any other (non-code) means to disable entity loading.
If writing a bit of custom code, the following hook implementation should help (haven't tested it, though):


function MODULE_search_api_solr_search_results_alter(array &$results, SearchApiQueryInterface $query, $response) {
  if (!empty($results['results'])) {
    foreach ($results['results'] as &$result) {
      $result['entity'] = (object) (!empty($result['fields']) ? $result['fields']) : array());
    }
  }
}

Beanjammin’s picture

Status: Active » Closed (works as designed)

Brilliant, this worked like a charm. Thank-you, I really appreciate the help and quick response!

It has the added bonus that if used on Site A only content from the solr index is used, which means that the same view can be used on both sites and will show the same solr-only results. I have found it faster to build the view on Site A and then move it as a feature to Site B, however I have been having trouble ensuring solr-only content was being used in the view.

There was a minor typo in the code above (an extra bracket). It is corrected here:

function MODULE_search_api_solr_search_results_alter(array &$results, SearchApiQueryInterface $query, $response) {
  if (!empty($results['results'])) {
    foreach ($results['results'] as &$result) {
      $result['entity'] = (object) (!empty($result['fields']) ? $result['fields'] : array());
    }
  }
}
jelo’s picture

Issue summary: View changes

Has there been any progress on this in the past few years? I think it would be an amazing feature if we could query various Solr indexes that have not been created by the site itself. All the talk about de-coupled websites would apply here as well, when we are able to switch the database backend against one or more Solr backends.

I will give Sarnia a try, but wondered if there are any other solutions available as well? I saw this sandbox which seems to suggest the same setup: https://www.drupal.org/sandbox/mihai_brb/2427325

J.