Lookahead Integration And The Panl Response Object
Lookahead (or type-ahead) is common on many sites, allowing a user to instantly see returned results as they type in the search box.
The number of documents that are returned by the Lookahead binding is set by the property solr.numrows.lookahead in the <panl_collecton_url>.panl.properties file which, by default is 5.
Where the 'More Facets' Panl URL binding will return facets, but no documents, the inverse is true of the 'Lookahead' Panl URL binding in that it will return no facets, but will return documents.
|
|
IMPORTANT: In the in-built Panl results viewer, the lookahead fields are hard coded to retrieve the brand and name of the document result, consequently other Solr collections will return values of undefined undefined for the results. |
URL bindings
The Panl JSON responses are bound to the Panl URL path in the form of
http://localhost:8181/panl-lookahead/<panl_collection>/<fieldset>
For example, the mechanical-pencils Panl collection is bound to
http://localhost:8181/panl-lookahead/mechanical-pencils/*
It requires additional URL information and query parameters to work, the query parameter MUST be the same as the panl.form.query.respondto as set in the <panl_collecton_url>.panl.properties file and will return the defined fieldset. Consequently the URL that is generated should have the form of:
http://localhost:8181/panl-lookahead/mechanical-pencils/brandandname/?search=hexagonal
Which would perform a keyword search on hexagonal and would return 5 results as per the configuration of the solr.numrows.lookahead property.
|
|
Tip: You may wish to define a new CaFUP with a specific FieldSet that just returns the data required for the Lookahead functionality. |
Building the Request URL
To request a lookahead search from the URL, 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/brandandname/
Image: The 'Lookahead' implementation on the in-built Panl Results Viewer
When implementing the lookahead function send a request to the panl-lookahead URL handler with the correct collection and fieldSet with the data keyed on search (which is the value configured by the panl.form.query.respondto property) and handle the results.
The in-built Panl Results Viewer web app uses the jQuery UI autocomplete plugin and the implementation is as follows:
|
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
$("#searchfield").autocomplete({ source: function (request, response) { $.ajax({ url: "http://localhost:8181/panl-lookahead/" + collection + "/" + fieldset, data: { "search": request.term }, success: function (data) { // the data that we receive we shall need to do some re-work var responseDocs = data.response.docs; var autocompleteDocs = []; for (const doc of responseDocs) { autocompleteDocs.push(doc.brand + " " + doc.name); } response(autocompleteDocs); }, error: function (data) { response([]); } }); }, minLength: 3 }); |
|
|
Note: In the Panl Results View Web App, the lookahead functionality is only triggered when greater than three (3) characters are entered and returns the fields from the JSON Response of brand and name. The in-built implementation functionality ONLY supports the mechanical pencils Solr collection. |
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 minimal Solr JSON response information included.
The JSON response object has the following form:
|
01 02 03 04 05 06 07 08 09 10 11 12 13 |
{ "response": { "docs": [ ... ] "numFound": 45, "start": 0, "maxScore": 0.17629748582839966, "numFoundExact": true }, "panl": { "timings": { ... } } } |
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 - timings showing the details of the request and response timings .



