Home / Adding a custom plugin to Solr

Adding a custom plugin to Solr

Internally at Acquia we had the need to add a custom plugin to our Solr 3.4 Build. This was already developed for Solr 1.4 but since Solr 3.x is using a very different approach while building and compiling its contrib folder.

I'll warn you because this is probably a very unlikely use-case for 90% of the users.
Normally the process of building Solr goes like this :

# Get the source code from the subversion repository.
svn co https://svn.apache.org/repos/asf/lucene/dev/branches/lucene_solr_3_4/ lucene_solr_3_4
cd lucene_solr_3_4
# This will launch the build process
ant example
# After the build finishes you can start the solr server.
# Move into the example directory...
cd example
# Now is the time to copy your Drupal solrconfig.xml and schema.xml
# into ./solr/conf
# And then start things up.
java -jar start.jar

We have build our own plugin for solr and we needed modifications to web.xml and also we needed this process to be automated without changing any source in the solr codebase.
Our structure of the custom plugin

  • customplugin
    • build.xml
    • README.txt
    • web-custom.xml
    • src
      • test
      • test-files
      • java
        • com.. etc
    • contrib
      • pre compiled jar files

Our requirement was :

  • Compile the custom java files from src
  • Include the compiled jar in the example war file that is build during ant example
  • Replace the web.xml with a web-custom.xml

We came up with the following build.xml (situated in lucene_solr_3_4/contrib/customplugin/build.xml)

<?xml version="1.0"?>
   <project name="solr-customplugin" default="default">
    <property name="contrib.has.webapp" value="true" />
    <import file="../contrib-build.xml"/>
    <!-- Add the compiled jar to our war file -->
    <target name="add-to-war">
      <echo message="CUSTOM: Cleaning ${common-solr.dir}/lib/${fullnamever}.jar from the build " />
      <delete failonerror="false" file="${common-solr.dir}/lib/${fullnamever}.jar" />
      <echo message="CUSTOM: Copying ${common-solr.dir}/dist/${fullnamever}.jar to ${common-solr.dir}/lib" />
      <copy file="${common-solr.dir}/dist/${fullnamever}.jar" todir="${common-solr.dir}/lib"/>
      <delete failonerror="false" file="${common-solr.dir}/webapp/web/WEB-INF/web.xml" />
      <copy file="web-custom.xml" tofile="${common-solr.dir}/webapp/web/WEB-INF/web.xml"/>
    </target>
    <description>Build file for CUSTOM Search specifics</description>
    <!-- Add this whenever we want to build the example -->
    <target name="example" depends="common-solr.dist"/>
  </project>

There we go, we now have complete pluggable contrib plugin for solr that fits our needs. This process can easiliy be automated since all the required files are included in the custom plugin.
Hope it helped someone! If you have useful comments on how to improve this, please leave comment below!
PS: When you run ant test, make sure the lib folder is clean from any copied .jar files

Reactie toevoegen

Plain text

  • Geen HTML toegestaan.
  • Adressen van webpagina's en e-mailadressen worden automatisch naar links omgezet.
  • Regels en alinea's worden automatisch gesplitst.

Filtered HTML

  • Use [acphone_sales], [acphone_sales_text], [acphone_support], [acphone_international], [acphone_devcloud], [acphone_extra1] and [acphone_extra2] as placeholders for Acquia phone numbers. Add class "acquia-phones-link" to wrapper element to make number a link.
  • To post pieces of code, surround them with <code>...</code> tags. For PHP code, you can use <?php ... ?>, which will also colour it based on syntax.
  • Adressen van webpagina's en e-mailadressen worden automatisch naar links omgezet.
  • Toegelaten HTML-tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <h4> <h5> <h2> <img>
  • Regels en alinea's worden automatisch gesplitst.
Bij het indienen van dit fomulier gaat u akkoord met het privacybeleid van Mollom.