More Facets Integration And The Panl Response Object
Where the number of available facets in the Solr search index is greater than the number of facets that Panl is configured to return (this is configured with the property solr.facet.limit in the <panl_collecton_url>.panl.properties file), this handler allows you to retrieve an arbitrary number of facet values.
URL bindings
The Panl JSON responses are bound to the Panl URL path in the form of
http://localhost:8181/panl-more-facets/<panl_collection>/<fieldset>/<lpse_path>/<lpse_codes>/?code=<lpse_code>&limit=<limit>
For example, the mechanical-pencils Panl collection is bound to
http://localhost:8181/panl-more-facets/mechanical-pencils/
It requires additional URL information and query parameters to work
Building the Request URL
To request more facet values for a specific LPSE code, the url would look like the following - the initial request:
http://localhost:8181/panl-results-viewer/mechanical-pencils-more/brandandname/Clutch/m/
Is searching for mechanical pencils which have a 'Clutch' mechanism. The limit for the facets for this CaFUP configuration is set to 10 - i.e. solr.facet.limit=4. The image below shows the returned facets with the See all... link appearing at the bottom of the facets.
|
Note: This above request URL is for the CaFUP binding in the sample/panl/mechanical-pencils/mechanical-pencils-more.panl.properties file which is not included in the default mechanical pencils panl.properties file and will have to be enabled. |
Image: The 'brand' facet with a limited number of facets and the 'See all...' link
Upon clicking on the See all... link a request is made to the URL
|
Note: The ONLY change to the URL is swapping the panl-results-viewer part to panl-more-facets, and appending the code and limit query parameters. |
The code query parameter is the LPSE code for the facet that you are requesting - in this case 'b' for 'brand' and the limit query parameter is set to -1 - this will tell Solr to return ALL facet results. Alternatively the limit parameter could be set to any positive integer value and Solr will return up to that exact number of facet results (if they are available).
Determining The Facet Limit
Within the available.facets JSON array, for each of the objects contained within this array, there is a key of facet_limit which is the maximum number of facets that Solr has been configured to return. In the case of the mechanical-pencils-more CaFUP, it is set to 10, and the available facet object returned is as follows:
01 02 03 04 05 06 07 08 09 10 11 |
{ "facet_limit":10, "uris":{ "before":"/", "after":"/Clutch/bm/" }, "values":[ ... ], "facet_name":"brand", "name":"Brand", "panl_code":"b" } |
To determine whether more facets are available, the logic is as follows:
If
facet_limit == -1
OR
facet_limit <= values.length
Then more facets are available.
Note: there is a case where the number of available facets are equal to the number of values that are returned, however there is no way for Solr to return the exact number of facets that are available. In this case the call to the Panl more facets service will not return any new results.
The logic in the Panl Results Viewer is
01 02 03 |
if(facet.facet_limit !== -1 && facet.facet_limit <= facet.values.length) { // show the 'See all...' link } |
And the Panl Results Viewer always requests all remaining facets so that the call of:
Returns the following JSON
01 02 03 04 05 06 07 08 09 10 11 |
{ "facet_limit":-1, "uris":{ "before":"/", "after":"/Clutch/bm/" }, "values":[ ... ], "facet_name":"brand", "name":"Brand", "panl_code":"b" } |
Error Responses
There will ALWAYS be an error key (with a boolean value of either true or false) on all responses which makes it easy to determine the best course of action. If there is an error (either 404, or 500), then the error key will be set to true, an integer status code keyed on status, and keyed on message, a human readable response.
Success Responses
Unlike the Panl Results Viewer and Explainer, this is a separate response with no Solr JSON response included.
The JSON response object has the following form:
01 02 03 04 05 06 07 08 09 10 11 12 13 |
{ "error": "false", "panl": { "facet": { "facet_limit":10, "uris":{ ... }, "values":[ ... ], "facet_name":"brand", "name":"Brand", "panl_code":"b" } } } |
The Panl response only has two keys, namely a boolean valued key of error, and a JSON object keyed on panl to the root object.
|
Note: The error key will __ALWAYS__ be false for a successful return of the Panl Response object. |
Within the panl JSON Object key, there is only one key - facet which is detailed below.
The "facet" JSON Object
This JSON object is identical to the items in the "available.facets" JSON Array - see The "available.facets" JSON Array for implementation details.
To generate the URL for the more facets service, use the facet_limit JSON key to determine whether there are any more facets.
Implementation notes
- You MUST send through the current query (i.e. LPSE path and LPSE codes) that the user is currently searching on. This will ensure that the additional facet values that are returned will be correct for this query.
- This functionality is only available on Regular and OR facets.
- Solr does not allow returning a subset of the facet values, it will always return the maximum number. For example, if the initial number of facets to return is set at 20, only 20 will be returned. When you request 40, all 40 will be returned - not the 21st to 40th result which means you should replace all of the values with the values returned by this query.
- If you want to return all facets, then set the limit query parameter to -1.
~ ~ ~ * ~ ~ ~