Skip to content

A SearchComponent to impose maximum values for the start & rows parameters.

License

Notifications You must be signed in to change notification settings

jorgelbg/solr-maxparams

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

solr-maxparams

This is a very simple SearchComponent that will allow you to specify max values for the start and rows parameters in any Search Request Handler. The code is dead simple but I hope it helps someone.

This search component basically will check the start/rows parameters against the configured maximum values, if any of this values is greater than the configured value an exception will be thrown and an 400 HTTP error code will be returned along with the Your start or rows parameter has exceeded the allowed valuesmessage. This will make easy to catch this HTTP error code in the application layer and handle it gracefully.

You can read this blog post about the code and how it works for more details.

Building

Execute:

$ mvn package

And then copy the generated jar in the target directory in the lib folder of your collection or somewhere when Solr can find it and load it.

Configuration

Once the jar is located by Solr, then you just need no configure a new searchComponent in your solrconfig.xml file:

<searchComponent name="max-parameters" class="cu.uci.solr.MaxParamsSearchComponent">
    <str name="rows">10</str>
    <str name="start">2</str>
    <str name="overwriteParams">true</str>
</searchComponent>

Now just go to the requestHandler where you want to use the component and add it to the first-components configuration option:

<arr name="first-components">
    <str>max-parameters</str>
</arr>

Configuration options

This search component has only 3 options to configure:

  • rows: This option will allow you to specify the maximum value for the rows parameter.
  • start: This option will allow you to specify the maximum value for the start parameter.
  • overwriteParams: This option will allow you to rewrite the original query if the maximum values are exceeded, in this case no exception or HTTP error code will be returned, but the query will be executed silently using the specified values in the configuration.

About

A SearchComponent to impose maximum values for the start & rows parameters.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages