In this post I will demonstrate how to apply a search to our application described in previous posts, in which we read the JSON from Domino Access Service and parse it with the Jackson library to display it thereafter with a Repeat control.
Since I am using in our application the Application Layout control with a responsive Bootstrap UI (shameless pitch to glory the persons who delivered this great functionality to XPages) which includes a searchBar section and scrolling through 40K of person records is not something you want to anguish your thumb with, a search functionality gives the advantage to skip scrolling through unnecessary documents.
Here is how I set up the searchBar section in the Application Layout control:
As you can see I have defined a result page for the search, called search.xsp.
Here is how the search bar will look like for the user:
The beforePageLoad event has slightly changed compared with event in our initial XPage. This time we search for the search parameter defined in the searchBar section:
var query = context.getUrlParameter(“search”);
var persons = new Array();
persons = personsBean.getPersons(“http://dev1/fakenames40k.nsf/api/data/collections/name/people?count=25&search=” + query);
Next is the result list. I have added an additional list item and added the active class:
This item will display the search query we have provided:
The Repeat control has also changed slighty. The rows property has been adjusted. We calculate the number of documents returned by the full text search.
var query:string = context.getUrlParameter(“search”);
var vw:NotesView = database.getView(“people”);
var totNums:Integer = vw.FTSearch(query).toFixed();
Also the text that indicates where we are in the result set has been modified:
Tip: since we are actually performing FT searches here perhaps it is better to put the counted results already from our initial call in a scope variable and re-use it =(
The button in our infinite scroll function/custom control has also been adapted. Here is the code:
Here is what the end result looks like after a search: