Searching In Multiple Indexes
JBStrap's ElasticSearch plugin allows you to search for multiple indexes at the same time. The plugin's specific component serves this purpose. The component is a search component where you can specify an index. Implementing the ESSearchHandler interface enables you to process the search results.
The component also makes it possible to sort the search hits (developers can disable the sorting feature). If the sorting option is enabled, users can sort a column in ascending/descending order. To sort a column, users have to click on the column selector dropdown menu on the right side.
Let's take a look at an example with an ESSearch component being placed on a page:
Features included in the ESSearchHandler interface
If you implement the ESSearchHandler interface, you have to use two methods. (This is what you can see in the above example.) Both methods are for handling the search hits. The first method to use is the onFilter() method, which accepts the contents of the search hits list as a parameter. If the search did not return any results, the method receives an empty list. Use the PAGE_SIZE parameter of the parameterSettings() method in the Startup class to specify the number of hits on a page.
The second method to use is the onNextPage() method that is executed only if users scroll through all of the previous pages and a search result still remains. The method now receives in a parameter the items from the next page. These items are displayed.
Additionally, the interface allows you to modify the search results or the search itself. The interface provides the following methods:
beforeFiltering
The method is execute before an ElasticSearch search operation is initiated. The method receives the search expression in a parameter. This search expression cannot be modified afterwards. The method returns a boolean value (true if the search proceeds and false if the search is interrupted).
Implement this method so that the search starts only if users have entered a search expression at least 3 characters in length:
afterFiltering
The method is executed after the search has been completed. The method receives in a parameter the search results. The search results can be freely modified within the method. The method returns the modified search results. Use this solution if you want to recalculate values or to hide certain search results.
Implement the method so that you recalculate the total payable amount by adding up the amount and the applicable tax: