Getting information from matching records

The fetch method

The Module class fetch method is used to get information from the matching records once the search of a module has been run. The server maintains the set of matching records in a list and the fetch method can be used to retrieve any information from any contiguous block of records in the list.

Specifying columns

This section specifies the values that can be included or used as the columns arguments to the Module class fetch method.

A Simple example

In this example we build a simple JSP web page to search the Parties module by last name and display the full set of results.

First build the search page, which is a plain HTML form:

<head>
  <title>Party Search</title>
</head>
<body>
  <form action="a-simple-example.jsp">
    <p>Enter a last name to search for (e.g. Smith):</p>
    <input type="text" name="name"/>
    <input type="submit" value="Search"/>
  </form>
</body>

Next build the results page (source code), which runs the search and displays the results:

<%@ page import="com.kesoftware.imu.*" %>
<%
    String name = request.getParameter("name");
    if (name == null || name.isEmpty())
        throw new Exception("missing 'name' parameter");

    Terms terms = new Terms();
    terms.add("NamLast", name);

    Session imuSession = new Session("imu.mel.kesoftware.com", 40136);
    Module module = new Module("eparties", imuSession);
    module.findTerms(terms);

    String[] columns =
    {
        "NamFirst",
        "NamLast"
    };
    ModuleFetchResult results = module.fetch("start", 0, -1, columns);
    long hits = results.getHits();
    Map[] rows = results.getRows();%><!DOCTYPE html>
<html>
<head>
<title>IMu Java API - A Simple Example</title>
</head>
<body>
<p>Number of matches: <% out.print(hits); %></p>
<table><%for (int i = 0; i < rows.length; i++)
    {
        Map row = rows[i];
        long rowNum = row.getLong("rownum");
        String first = row.getString("NamFirst");
        String last = row.getString("NamLast");
       %>
        <tr>
        <td><% out.print(rowNum); %></td>
        <td><% out.print(first); out.print(" "); out.print(last); %></td>
        </tr>
        <%
    }%>
</table>
</body>
</html>

In this example the name parameter entered via the HTML search page is submitted to the JSP script. The script searches for parties records that have the entered value as a last name and display the parties first and last names in an HTML table.

Note: To deploy and run JSP, a compatible web server with a servlet container, such as Apache Tomcat or Jetty, is required. The request object used to retrieve the name parameter is supplied by the servlet container.