{business intelligently}

Drupal Apache Solr Search: Multi Site (Instance) Setup

Ok.  So I ran into a little issue when I tried to run two Solr site searches at the same time.  Basically, all of the data for each site goes into the same index and when you search on one site, you get content from the other. 

Not good.  And there is almost nothing out there to tell you how to deal with this issue, aside from posts on *.drupal.org telling you that the module itself isn't ready to deal with the issue.

So here's how you get it done.  I'm running Windows XP so the paths might look a bit different for you folks using Linux or Mac servers, but this should work.  All of the breadcrumbs I found during my search to do this were for *nix anyway.

I'm going to assume that you already have a single-site instance of Solr for Drupal running.  If you do not, follow the instruction here but STOP after #5 (right where it says "STOP").

We'll pick up here:

 

  1. Make a copy of the "example" directory found in the "apache-solr-nightly" directory; call it "drupal_multisite".
  2. Delete the following directories.  They're just in the way:
    - example-DIH
    - exampleAnalysis
    - exampledocs
    - work
  3. Copy "drupal_multisite/multicore/solr.xml" to "drupal_multisite/solr/solr.xml" 
  4. Delete the "drupal_multisite/multicore" directory.
  5. Now create directories within the "drupal_multisite/solr" directory for each site you want to use Solr with.  For example, if I had two sites "anovasolutions.com" and "myrandomideas.com" and I wanted to use Solr with them both, I might create the following directories:
    drupal_multisite/solr/site_anovasolutions
    drupal_multisite/solr/site_myrandomideas
  6. Copy the "drupal_multisite/conf" directory into each directory you just created.  When you're done each site's directory should have a copy of "conf" in them.
  7. Delete the "drupal_multisite/conf" directory.
  8. Now alter the solr.xml file you copied over in step 3 to accommodate both site.  So my solr.xml would look like this:
    <?xml version="1.0" encoding="UTF-8" ?>
    <solr persistent="false">
         <cores adminPath="/admin/cores">
              <core name="anovasolutions" instanceDir="site_anovasolutions" />
              <core name="myrandomideas" instanceDir="site_myrandomideas" />
         </cores>
    </solr>
  9. Now fire up the .jar from the command line with: "java -jar start.jar"
  10. Activate the Solr modules like I talked about in step 7 here, but of course you'll do this for both sites.
  11. This is the key: follow the instructions for step 8 from here, but the Solr paths will be as follows for each site:
    /solr/anovasolutions (for anovasolutions.com)
    /solr/myrandomideas (for myrandomideas.com)
  12. You're ready to rock.  You'll need to index with the cron like I talked about in the other post.
I hope this helps someone.

Comments

multiple solr instances for same drupal site

I have a solr instance running for bespoke data already on Drupal using the solr module. What I would now like to do is to replace core search with solr. The current behaviour is: All content types via drupal native search and 'shopping' content type via solr. The solr index is built offline rather than using the drupal cron, and for drupal native search index for all other content types, i am not able to run the cron as there are millions of nodes from the 'shopping' content type i need to exclude. I thought one way to do this is to run a multi-core Solr but within the *same* drupal site, so that one serves 'shopping' content and the other serves all other content types on Drupal. Any thoughts? Thank you!

I would be great if you would

I would be great if you would post a version of the above to the drupal.org handbook under CC license (with a link back if you like): http://drupal.org/node/343467
Thats a way we can make it easier for people to get started - multi-site is easy enough once you get it going, but has been a bit in flux still in Solr 1.4.
 
 

Done. http://drupal.org/node/

Done.

http://drupal.org/node/484800

I'll try to get some screenshots to make this as clear as possible.

  I think this is a slight

 

I think this is a slight mis-perception here.  Obviosuly the module itself deals fine with each site using a different core in multi-core (different path to solr).  What the module is not yet prepared to do well is what you you propose to avoid - having the data from multiple sites in one index and effectively searching across it or restricting it to one site.

You could, also, have enforced this single-site search restriction rather trivially with a little module that adds an additional fq (filter query) paramter to every query to limit results to the current site.  That code is so trivial (a couple lines) that maybe we should add it to the module now for convenience.

I think I have found that

I think I have found that trivial piece of code and made a handbook page for it: http://drupal.org/node/698042

Thanks for taking the time to

Thanks for taking the time to comment; it's flattering to have someone from Acquia read my yammering. :)

The solution of adding the fq parameter is a good one, and one that I'd have likely employed had my Googling taken me in that direction.  There just wasn't anything out there on how to execute a multisite setup, aside from other people asking "how the heck do you do this?" and getting crickets.

I do think that this would be a good thing to add into the module; there's some great momentum building for Drupal Solr Search and I think the lack of clear support for distinct sites on the same instance could become more of an issue.

All that said, thank you for writing such an amazing module.  It's on my list of "how did I ever live without this" modules along with Views and CCK.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options