Architecture: ParameterStore

James McKinney edited this page Apr 13, 2013 · 10 revisions

Table of Contents

The ParameterStore, as its name suggests, stores Solr parameters.

The ParameterStore defines functions for getting, setting, and removing Solr parameters. Some Solr parameters – like facet.field and fq – may be specified multiple times, while others – like q and start – may be specified only once. The isMultiple method returns true if the parameter may be specified multiple times.

The following functions, which operate on Solr parameters, behave differently depending on whether the parameter may be specified multiple times or only once: get, values, add, remove, find, addByValue, and removeByValue. See the documentation for details.

string returns the Solr parameters as a query string. parseString parses a query string into Solr parameters.

Parameters

Solr parameters are represented as Parameter objects. Parameter defines val, for getting and setting the parameter value; local for getting and setting local parameters; and remove for removing local parameters.

Parameter defines methods used by the ParameterStore string and parseString methods: string, which returns the parameter as a query string key-value pair; parseString, which parses that back into a parameter; valueString, which returns the parameter value as a query string-safe value; and parseValueString, which parses that back into a parameter value.

Available parameters

For a list of possible parameters, please consult the links below:

Exposed parameters

Widgets allow the user to change Solr parameters; for example, the demo site‘s tagcloud widget allows the user to change the fq parameter. Whenever the user changes the values of parameters, the application’s state changes. In order for the user to bookmark states and to move between states with the browser’s navigation buttons, each state must be saved. The easiest method is to store these parameters in the URL hash: for example, by using the ParameterHashStore. However, you may implement your own storage method by extending the ParameterStore.

Using the ParameterHashStore

The ParameterHashStore stores Solr parameters in the URL hash. It is currently incompatible with Internet Explorer, although it should be easy to extend it to use the YUI Browser History Manager (or other) to support all browsers. To use the ParameterHashStore, add its JavaScript file:

<script type="text/javascript" src="/path/to/ParameterHashStore.js"></script>

Then, before calling Manager.init(), add the next two lines:

Manager.setStore(new AjaxSolr.ParameterHashStore());

You must list the parameters that your widgets allow the user to change under the store’s exposed property, for example:

Manager.store.exposed = [ 'fq', 'q', 'start' ];

Extending the ParameterStore

The ParameterStore init abstract method is called by the Manager init method. If extending the ParameterStore class, you may implement its init method to perform any one-time initializations.

Any parameters that your widgets allow the user to change, directly or indirectly, should be listed by name under the exposed property. exposedString returns these parameters as a query string.

save is an abstract method, which is called by the Manager in its doRequest method; in other words, it is called once before each request is sent to Solr. The save method should store the values of exposed parameters (the application’s current state), such that the user may bookmark and move between states. ParameterHashStore implements the save method to store the state in the URL hash.

storedString returns the string representation of the application’s current state. ParameterHashStore implements the storedString method to return the URL hash.

If, instead of using ParameterHashStore, you implement your own storage method for exposed parameters, you should only need to implement the save and storedString abstract methods. You may choose to implement load, which, by default, resets the exposed parameters (by calling exposedReset) and calls parseString on the string returned by storedString.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.