...
Solr allows you to load custom code to perform a variety of tasks within Solr – from custom Request Handlers to process your searches, to custom Analyzers and Token Filters for your text field, even custom Field Types.
Looking for examples of Solr Plugins? Checkout the website solr.cool!
Table of Contents |
---|
How to Load Plugins
Plugin code can be loaded into Solr by putting your classes into a JAR file, and then configuring Solr to know how to find them.
...
- Place your JARs in a
lib
directory in the instanceDir of your SolrCore. In the example program, the location is example/solr/lib. This directory does not exist in the distribution, so you would need to domkdir
for the first time. - Use the lib directive in your solrconfig.xml file to specify an arbitrary JAR path, directory of JAR files, or a directory plus regex that JAR file names must match. Do not load jars in this way that have already been loaded from $SOLR_HOME/lib or $INSTANCEDIR/lib.
Loading plugins uses a custom Class Loader. It has been tested with a variety of Servlet Containers, but given the multitudes of servlet containers available in the wild it may not always work with every servlet container.
...
- unpack the solr.war
- add a jar containing your custom classes to the
WEB-INF/lib
directory - repack your new, customized, solr.war and use it.
Classes that are 'Pluggable'
...
No Format |
---|
<requestHandler name="dismax" class="solr.SearchHandler" > <lst name="defaults"> <str name="defType">myqueryparser</str> ... |
ValueSourceParser
Use this to plugin your own custom functions see FunctionQuery.
...
Highlighting
:TODO: NEED DOCS
SolrFragmenter
:TODO: NEED DOCS
SolrFormatter
:TODO: NEED DOCS
UpdateRequestProcessorFactory
:TODO: NEED DOCS
...
No Format |
---|
<similarity class="my.package.CustomSimilarity"/> |
CacheRegenerator
The CacheRegenerator API allows people who are writing custom SolrRequestHandlers which utilize custom User Caches to specify how those caches should be populated during autowarming. A regenerator class can be specified when the cache is declared in your solrconfig.xml...
...
Specifying an Analyzer class in your schema.xml makes a lot of sense if you already have an existing Analyzer you wish to use as is, but if you are planning to write Analysis code from scratch that you would like to use in Solr, you should keep reading the following sections...
Tokenizer and TokenFilter
In addition to specifing specific Analyzer classes, Solr can construct Analyzers on the fly for each field type using a Tokenizer and any number of TokenFilters. To take advantage of this functionality with any Tokenizers or TokenFilters you may have (or may want to implement) you'll need to provide a TokenizerFactory and TokenFilterFactory which takes care of any initialization and configuration, and specify these Factories in your schema.xml...
No Format |
---|
<fieldtype name="text_zop" class="solr.TextField" positionIncrementGap="100"> <analyzer> <tokenizer class="my.package.CustomTokenizerFactory"/> <!-- this TokenFilterFactory has custom options --> <filter class="my.package.CustomTokenFilter" optA="yes" optB="maybe" optC="42.5"/> <!-- Solr has many existing FilterFactories that you can reuse --> <filter class="solr.StopFilterFactory" ignoreCase="true"/> </analyzer> </fieldtype> |
FieldType
If you have very specialized data type needs, you can specify your own FieldType class for each <fieldtype>
you declare in your schema.xml, to control how the values for those fields are encoded in your index...
No Format |
---|
<fieldtype name="wacko" class="my.package.CustomFieldType" /> |
Internals
SolrCache
The SolrCache API allows you to specify custom Cache implementations for any of the various caches you might declare in your solrconfig.xml...
No Format |
---|
<filterCache class="my.package.CustomCache" size="512" /> <queryResultsCache class="my.package.CustomCache" size="512" /> <documentCache class="my.package.AlternateCustomCache" size="512" /> |
SolrEventListener
Instances of the SolrEventListener Interface can be configured in your solrconfig.xml to be be executed any time specific events occur within Solr.
...
No Format |
---|
<listener event="newSearcher" class="my.package.CustomEventListener"> <-- init args for the EventListener instance can be specified here --> <lst name="arg1"> <str name="q">solr</str> <str name="start">0</str> <str name="rows">10</str> </lst> <int name="otherArg">42</int> </listener> |
UpdateHandler
The UpdateHandler API allows you to specify a custom algorithm for determining how sequences of adds and deletes are processed by Solr. The UpdateHandler you wish to use can be configured in your solrconfig.xml, but implementing a new UpdateHandler is considered extremely advanced and is not recommended....
...
, the children must not be SolrCoreAware. see PluginInfo.
Solr3.1 As of Solr3.1 any subnode which is not a "lst","str","int","bool","arr","float" or "double" is considered a child. (Yes "long" is missing - see SOLR-2541)
ResourceLoaderAware
Classes that need to know about the ResourceLoader can implement ResourceLoaderAware. Valid ResourceLoaderAware include:
- TokenFilterFactory
- TokenizerFactory
- FieldType
SolrCoreAware
Wiki Markup |
---|
Classes that need to know about the \[SolrCore\] can implement [SolrCoreAware|http://lucene.apache.org/solr/api/org/apache/solr/util/plugin/SolrCoreAware.html]. Classes implementing SolrCoreAware must not have a dedicated Constructor. Valid SolrCoreAware classes include: |
...
Lifecycle
The initialization lifecycle is:
...