Accueil / Blog / 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 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"/>
    <description>Build file for CUSTOM Search specifics</description>
    <!-- Add this whenever we want to build the example -->
    <target name="example" depends="common-solr.dist"/>

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

Ajouter un commentaire

Plain text

  • Aucune balise HTML autorisée.
  • Les adresses de pages web et de courriels sont transformées en liens automatiquement.
  • Les lignes et les paragraphes vont à la ligne automatiquement.

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.
  • Pour publier des morceaux de code, entourez-les avec les balises <code>...</code>. Pour du PHP, utilisez. <?php ... ?>, ce qui va colorier le code en fonction de sa syntaxe.
  • Les adresses de pages web et de courriels sont transformées en liens automatiquement.
  • Tags HTML autorisés : <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <h4> <h5> <h2> <img>
  • Les lignes et les paragraphes vont à la ligne automatiquement.
By submitting this form, you accept the Mollom privacy policy.