Differences between revisions 66 and 67
Revision 66 as of 2011-09-13 05:37:32
Size: 18504
Editor: mail
Comment: Corrected mistake: Big Fixes -> Bug Fixes
Revision 67 as of 2011-09-19 14:51:19
Size: 18464
Editor: JanHoydahl
Comment: Note about "ant eclipse"
Deletions are marked like this. Additions are marked like this.
Line 59: Line 59:
Eclipse .classpath and .project files for Lucene/Solr projects are attached to [[http://markmail.org/message/yb5qgeamosvdscao|this email]] from the Solr mailing list. To get correct classpath and project setting in Eclipse, simply run {{{ant eclipse}}} and then reload the project in Eclipse.

How to Contribute to Solr

"Contributing" to an Apache project is about more then just writing code -- it's about doing what you can to make the project better. There are lots of ways to contribute....

Be Involved

Contributors should join the Solr mailing lists. In particular:

  • the user list (to help others)
  • The commit list (to see changes as they are made)
  • The dev list (to join discussions of changes)

Please keep discussions about Solr on list so that everyone benefits. Emailing individual committers with questions about specific Solr issues is discouraged. See http://people.apache.org/~hossman/#private_q.

Write/Improve User Documentation

Solr can always use more/better documentation targeted at end users, most of which is in this wiki where anyone can edit it. If you see a gap in the Solr documentation, fill it in. Even if you don't know exactly what to say, ask on the user list and you'll probably get a lot of great responses -- talking informally about how Solr works is something lots of people tend to have time for, but aggregating all of that info into concise cohesive documentation takes a little more work/patience.

If there is a patch in Jira that you think is really great, writing some "user guide" style docs about how it works (or is suppose to work) in the wiki is a great way to help the patch get committed: It helps serve as a road map for what the "goal" of the issue is, what should be possible for users to do once the issue is resolved; it helps get people who may not understand the low level details get excited about the new functionality; and it can eventually evolve into the final documentation once the code is committed. (just make sure to link to the issue so people who find your wiki page first know it's not included in Solr's main code line yet).

Contributing Code (Features, Bug Fixes, Tests, etc...)

This section identifies the optimal steps community member can take to submit a changes or additions to the Solr code base. This can be new features, bug fixes optimizations of existing features, or tests of existing code to prove it works as advertised (and to make it more robust against possible future changes).

Please note that these are the "optimal" steps, and community members that don't have the time or resources to do everything outlined on this below should not be discouraged from submitting their ideas "as is" per "Yonik's Law of Patches" ...

A half-baked patch in Jira, with no documentation, no tests
and no backwards compatibility is better than no patch at all.

Just because you may not have the time to write unit tests, or cleanup backwards compatibility issues, or add documentation, doesn't mean other people don't. Putting your patch out there allows other people to try it and possibly improve it.

Getting the source code

First of all, you need the Solr source code.

Get the source code on your local drive using SVN. Most development is done on the "trunk":

> svn checkout http://svn.apache.org/repos/asf/lucene/dev/trunk

Note that committers have to use https instead of http here, but http is fine for read-only access to the trunk code.

Making Changes

Before you start, you should send a message to the Solr developer mailing list (Note: you have to subscribe before you can post), or file a bug in Jira. Describe your proposed changes and check that they fit in with what others are doing and have planned for the project. Be patient, it may take folks a while to understand your requirements.

Modify the source code and add some (very) nice features using your favorite IDE.

But take care about the following points

  • All public classes and methods should have informative Javadoc comments.

  • Code should be formatted according to Sun's conventions, with one exception:

    • indent two spaces per level, not four.
  • Contributions should pass existing unit tests.
  • New unit tests should be provided to demonstrate bugs and fixes (http://www.junit.org).

Notes for Eclipse and the New Merged Lucene/Solr checkout

Another issue you may see is character encoding, especially if you are including the lucene/contrib/analyzers package. On Eclipse, you can solve this by going to Project > Properties > Resources, and then changing the encoding on that page to UTF-8. Then let Eclipse rebuild the workspace (either automatically if you have that checked, or force a rebuild) and you should be golden!

(thanks to Mark Miller and Erik Hatcher for contributing to this)

To get correct classpath and project setting in Eclipse, simply run ant eclipse and then reload the project in Eclipse.

Generating a patch

A "patch file" is the format that all good contributions come in. It bundles up everything that is being added, removed, or changed in your contribution.

Unit Tests

Please make sure that all unit tests succeed before constructing your patch.

> cd solr-trunk
> ant clean test

After a while, if you see


all is ok. but if you see


please, read carefully the errors messages and check your code. If the test fails you may want to repeatedly rerun a single test as you debug and sort out any problems. In which case you could run

> ant -Dtestcase=TestXXX test

Where "TestXXX" is the name of the particular Junit test you want to run.

Creating the patch file

Check to see what files you have modified with:

svn stat

Add any new files with:

svn add src/.../MyNewClass.java

Subversions "add" command only modifies your local copy, so it does not require commit permissions. By using "svn add", your entire contribution can be included in a single patch file, without needing to submit a separate set of "new" files.

Edit the CHANGES.txt file, adding a description of your change, including the bug number it fixes.

In order to create a patch, just type:

svn diff > SOLR-NNN.patch

This will report all modifications done on Solr sources on your local disk and save them into the SOLR-NNN.patch file. Read the patch file. Make sure it includes ONLY the modifications required to fix a single issue.

Note the SOLR-NNN.patch patch file name. Please use this naming pattern when creating patches for uploading to JIRA. Once you create a new JIRA issue, note its name and use that name when naming your patch file. For example, if you are creating a patch for a JIRA issue named SOLR-123, then name your patch filename SOLR-123.patch. If you are creating a new version of an existing patch, use the existing patch's file name. JIRA will automatically "gray out" the old patch and clearly mark your newly uploaded patch as the latest.

Please do not:

  • reformat code unrelated to the bug being fixed: formatting changes should be separate patches/commits.
  • comment out code that is now obsolete: just remove it.
  • insert comments around each change, marking the change: folks can use subversion to figure out what's changed and by whom.
  • make things public which are not required by end users.
  • Combine multiple issues into a single patch, especially if they are unrelated or only loosely related. This is true even if the changes affect the same files. In some rare cases it is warranted, but for the most part it makes it harder for committers to evaluate the patch.

Please do:

  • try to adhere to the coding style of files you edit;
  • comment code whose function or rationale is not obvious;
  • update documentation (e.g., package.html files, this wiki, etc.)

  • try to provide a unit test that shows a bug was indeed fixed or the new functionality truly works

Contributing your work

Finally, patches should be attached to a bug report in Jira. If you are revising an existing patch, please re-use the exact same name as the previous attachment, Jira will "gray out" the older versions so it's clear which version is the newest.

Please be patient. Committers are busy people too. If no one responds to your patch after a few days, please make friendly reminders. Please incorporate other's suggestions into your patch if you think they're reasonable. Finally, remember that even a patch that is not committed is useful to the community.

JIRA tips (our issue/bug tracker)

The issue tracker we use is a JIRA instance at https://issues.apache.org/jira/browse/SOLR. If you don't yet have an account, just click the "login" link and you'll get the opportunity to create one that will allow you to add tickets, upload patches etc.

  • When creating new issues in JIRA, please keep the "Description" field short - every change or followup on the issue will cause an email to be sent to the solr-dev mailing list, and will include the complete Description every time.
  • When attaching newer versions of a file/patch, use the same name... JIRA will "gray out" the older versions automatically.
  • Please do not delete older files that you have already added - the complete history of an issue is important.
  • If you aren't sure if something is a bug, please ask on the solr-user mailing list before opening an issue.

Review/Improve Existing Patches

If there's a Jira issue that already has a patch you think is really good, and works well for you -- please add a comment saying so. If there's room for improvement (more tests, better javadocs, etc...) then make the changes and attach it as well. If a lot of people review a patch and give it a thumbs up, that's a good sign for committers when deciding if it's worth spending time on the patch -- and if other people have already put in effort to improve the docs/tests for a patch, that helps even more.

Working With Patches

You can easily download a patch from JIRA and test it by doing the following:

$ cd <your Solr trunk checkout dir>
$ svn up
$ wget <URL of the patch>
$ patch -p0 -i name of the patch --dry-run

(note: --dry-run just pretends to apply a patch, so you can see if it would succeed or fail. Remove --dry-run to *really* apply the patch)

The address for the patch can be obtained from the issue page, under the "File Attachments" section of the issue.

For people who like one-liners, The following should work as well:

$ cd <your Solr trunk checkout dir>
$ svn up
$ wget <URL to the patch> -O - | patch -p0 --dry-run

If you are on Solaris, you should replace 'patch' with 'gpatch' to use GNU Patch instead.

Reverting to pre-patch state is one line:

svn revert -R .

Though this leaves added files, which can be removed with

svn st | grep '?' | awk '{print $2}' | xargs rm

Another useful trick is to have multiple checkouts of trunk and "bounce" an active changeset from one to another with

svn diff | (cd ../otherbranch; patch -p0)

Helpful Resources

The following resources may prove helpful when developing Solr contributions. (These are not an endorsement of any specific development tools, but Eclipse and IntelliJ seem to be the most popular)

  • Eclipse (Eclipse codestyle).

  • IntelliJ (IntelliJ codestyle) NOTE: there is no need to install this file separately if you execute "ant idea", it is done for you. If you do install it, you'll have to tweak the name to select in in IntelliJ as it's currently anonymous (all the more reason to use the ant target, see the IntelliJ instructions).

<!> Solr1.3 If you are using eclipse to follow trunk (leading up to the 1.3 release) eclipse will give several errors about not resolving components in the solrj library. This will appear in the org.apache.solr.handler.component package relating to distributed search (sharedrequest.java ...etc) The solution is to compile the solrj library via the dist-solrj target and add them to your eclipse build path. After running the dist-solrj target look in dist/solrj-lib and add apache-solr-solrj-1.3-dev.jar and commons-httpclient-3.1.jar to your buildpath.

Development Environment Tips

There was a recent thread concerning trying to set up Lucene and SOLR in Eclipse. Here is a guide for setting up Eclipse and IntelliJ dev environments:

Follow the instructions above to fetch the combined Lucene and SOLR trunk. For the remainder of this document, the installation path is assumed to be ~/apache/trunk/lucene and ~/apache/trunk/solr. NOTE: I'm installing on a Macbook, so this is a *nix style file system etc. These instructions should work for windows as well, but if you try to use them in that environment, feel free to update this page with anything you uncover.

Before fiddling with the IDE, I'd strongly recommend you get the tests to run from the shell. This will insure that your machine has the proper setup for the IDEs to magically find what's necessary. See the instructions above. Hint: Issue 'ant clean test' in the SOLR and Lucene directories and look for "BUILD SUCCESSFUL" minutes later.

Setting things up is actually very smooth when it's smooth, especially if the tests have run <G>.

Eclipse (Galileo, J2EE version, but any relatively recent Eclipse should do):

Checkout the trunk with subclipse (location: https://svn.apache.org/repos/asf/lucene/dev/trunk), then run 'ant eclipse' and refresh your project.

DO NOT BE SURPRISED IF SOME TESTS FAIL IN THE IDE. There are some anomalies when running Junit tests for these projects in an IDE. Some of them are already cleaned up, but others may still fail when run in an IDE. The definitive case for whether a test fails or not is running it as an Ant task.

Enabling Assertions for unit tests in Eclipse

By default, Eclipse does not run test with assertions enabled. This causes some tests to run incorrectly in Eclipse and excludes some checks in the source code.

Change this by checking the box "Add '-ea' to VM arguments when creating a new JUnit launch configuration".

This checkbox is available under Windows>Preferences>Java>JUnit

Installing the code style file

Lucene and SOLR have a common code style preferences. Install one in your Eclipse and set it as the default for the project. Do this by:

  • Getting the Eclipse code style xml files (link).

  • In Eclipse, click "Project>>Properties". In the dialog box, click "Java code style>>Formatter". Up in the upper right of the dialog box that comes, click "Configure Workspace Settings". NOTE: you can do this on an individual project basis if you prefer.

You should now be able to click the "import" button, and import the codestyle file you downloaded. Eclipse doesn't immediately show that the selected import is the new code style, but closing the dialog boxes and coming back to the formatter page should allow you to choose it.


  • For importing code style xml in Eclipse Helios go to Window > Preferences > Java > Code Style > Formatter, Import to import the file.

  • Under some conditions, I've seen this process have thousands of compile errors, something like "class XXX defined in multiple places". This went away when I highlighted the project and clicked "refresh".
  • Think about installing the subclipse plugin, it'll allow you to update your source from within Eclipse. See: http://subclipse.tigris.org/servlets/ProjectProcess?pageID=p4wYuA

  • You can create patches for the committers to apply from within the IDE easily.
  • By and large, you won't "run" a Lucene program, you'll really run unit tests. (Others, please chime in here!!!). The general development cycle for Lucene is to add functionality, add unit tests, make sure all unit tests run and check in (actually, submit a patch to check in, preferably attached to a JIRA issue). There's no "program" that you start up in your IDE to test changes, just use unit tests.

Running SOLR in Eclipse: See: http://www.lucidimagination.com/developers/articles/setting-up-apache-solr-in-eclipse.

Eclipse (using Git)

Work has begun to maintain a Git repository with project settings. It allows a simple "File -> Import... -> Projects from Git" workflow using EGit (version >= 0.9). Currently it's a single Eclipse project compiling Lucene and Solr without errors. It's likely better to have separate projects for proper dependency management. Please contribute!

The repository is available on GitHub (git://github.com/eclipseguru/lucene-solr.git). It can be easily kept in sync with Apache SVN using the Lucene & Solr Git mirror.

IntelliJ (9.0.X and 10.X)

See the Lucene wiki page on configuring IntelliJ - it also covers Solr configuration.


There is information about using Maven with Solr and Lucene in the source tree, at dev-tools/maven/README.maven. The information differs slightly by code branch. Here are links to this file for each Solr version:

Solr Version

Link to Lucene/Solr Maven build instructions



3.2 (unreleased)


trunk/4.0 (unreleased)


One final note

As always, there are gremlins out there. If you find problems with the information here, and especially if you subsequently find solutions to the problems you find, please either write to the solr-user mailing list or update this page directly so others can benefit.

HowToContribute (last edited 2018-08-17 03:21:42 by SteveRowe)