Skip to content

Compile User supplied Custom Methods at Runtime

haschart edited this page Sep 20, 2016 · 1 revision

Previous SolrMarc Custom methods

Originally SolrMarc provided a number of pre-defined custom methods to provide additional functionality over what could be handled with a simple index specification. Additionally the system allowed you to define one additional class containing custom indexing methods, provided that your class extended the SolrIndexer class. The user-supplied class containing custom methods needed to be compiled into a separate jar file and be referenced by the configuration properties file. To support the building of this custom jar the SolrMarc project used a confusing and complicated two-step build process that could produce a locally customized build environment, which individual sites could then use to build, test and use their custom jar. Additionally since this method only allowed a single user-supplied class of custom methods, in highly customized environments, that class would grow quite large and become unwieldy.

Subsequently SolrMarc was extended to also support scripted custom methods in the Java-like scripting language, BeanShell. These scripts were much easier to use, since you only needed to place the script in a specific directory, and reference it in an index specification. However, they were somewhat more tricky to create and debug, and were quite a bit slower than a compiled version could be.

Even more recently the ability to create, compile and include multiple indexing "Mixins" was added. These were an attempt at addressing the issues that arose with the two previous customization methods. The mixins are compiled, so they are faster than using a script, plus a separate mixin build environment was provided to aid in the process of building and testing the custom indexing methods. However they've never been used much since they aren't well documented, and they are still more complicated than the scripts.

A New Way to Include Custom Methods

With this new version of SolrMarc, the previous three methods of supplying custom indexing methods are still supported (although the use of a single, large class extending SolrIndexer is deemed to be deprecated. However there is a new method that attempts to achieve the best-of-both-worlds, in that all the user needs to do is place source files in a specific directory and reference a method therein in an index specification, but the source files are compiled as the indexing process is being run, so they should be every bit as any other compiled method.

Similar to how beanshell script files have always been placed in an index_scripts directory, these java source files containing custom indexing methods are merely in an index_java/src directory. When the new SolrMarc is run, it will compile all of the source files in that directory, writing the output to the index_java/bin directory, and they dynamically load and use the generated class files.

This new way of including custom methods should make it much easier for sites to share methods they've created, and for other sites to include and use those methods.

Clone this wiki locally