Posted by Kelvin on 02 Jul 2018 at 10:38 am | Tagged as: Lucene / Solr / Elasticsearch / Nutch
In this article, I discuss SearchComponents briefly, and show how straightforward it is (in non-SolrCloud mode) to develop a custom Solr SearchComponent. In the next articles in the series, we examine the flow of logic in SolrCloud mode, and how you might be able to develop a SolrCloud-compatible SearchComponent.
In standalone Solr mode, there are 3 methods to implement when developing a custom SearchComponent. Here is the simplest no-op SearchComponent.
The Java class that encapsules Solr search workflow is SearchHandler.
For non-SolrCloud mode, the general application flow is:
If you look at some of Solr's standard SearchComponents, you'll see that it is fairly arbitrary what goes into prepare() vs process(). It is entirely possible to do stuff entirely in prepare() or process(). If you'd like to modify how a certain component works, or to modify its output, you could either subclass it and override the method altogether, or add a component before or after it and modify its side-effects (in the request params or the response).
Deploying your custom SearchComponent
To deploy your new SearchComponent, bundle it as a jar and place it in the lib folder of your Solr core. If this is your first SearchComponent, this lib folder *does not exist* and must be created.
The path to the lib directory will be something like:
The lib directory is at the same level as the conf and data directories for your Solr core.
Then, in solrconfig.xml, add
<requestHandler name="/test" class="org.apache.solr.handler.component.SearchHandler">
As the Solr guide shows, you can also use first-components and last-components in place of components when declaring your component.
This concludes the first article in the series. In the next article, we will examine how search requests are served in SolrCloud and how the application flow is more involved and complex.
- Introducing this series on developing Solr SearchComponents
- Developing a Solr SearchComponent for standalone Solr
- Introducing SolrCloud
- SolrCloud search request lifecycle and writing distributed Solr SearchComponents