Debug Template

From DBSight Full-Text Search Engine/Platform Wiki

Compare Template with Java Search API

Java Search API

+ Java Only, although other languages can theoretically be supported by generating interface via Google Protocol Buffer

+ Well documented

+ Stable, and the typed language can prevent many subtle spelling mistakes

+ Requires another layer in front of DBSight, which is more flexible, but more work.


+ The FreeMarker templates are really flexible and easily customizable. It's equal to JSP, which you can modify it as you want.

+ Actually, you can use also JSP to render the results.

+ FreeMarker Templates can scaffold up very quickly.

+ Since you can get the rendering done on DBSight side, it may trim out unnecessary data, which may or may not affect the result size, depending on the actual template rendering.

Choose Between Java Search API and Template

It depends on how much data you need to transmit and how complicated the result page is.

In general, Java Search API is flexible, and the API is very stable and has public Java doc. But demands additional effort to generate the HTML results on the application server side, since there are many different renderings, for pagination, highlighting, etc.

If you want to play it safe, you can start with template. But of course, if your developers are more familiar with JSP and javadoc, you can have them code up the templates in JSP.

And if you need use data only available on your application server when rendering the JSPs, you can fall back to the Java Search API.

Template FAQ

Table of contents


How to get attributes with multiple values?

Columns from Subsequent Queries can have several values, especially for one-to-many releationships. But during rendering, how to get those values?

You can use


which return a list of attribute values, instead of the normal way:


which only get one attribute value.

You can check for more details from the java doc for

How do I ... ?

FreeMarker can use any java objects. So basically you can do anything in it. Here are some examples:

How to decode base64 encoded strings?

 <#assign base64= new("org.apache.commons.codec.binary.Base64")>
 <#assign util= new("org.apache.commons.codec.binary.StringUtils")>

How to include contents from other url?

This is a good way to include contents from other urls, which could be produced via PHP, Perl, etc.

<#assign httpUtil = new("net.javacoding.xsearch.utility.HttpUtil")>

JSP template

Specifying JSP rendering

If Velocity is not your cup of tea, you can use JSP. In normal url, you can add one more parameter


Then DBSight will look for templating file


Objects You can use

All objects for rendering should come from SearchResult class,

Pay some attention to

<%@ page import="" %>
<% SearchResult searchResult = request.getAttribute("searchResult") %>

For JSP, to loop through the "$docs" object as in Velocity would be like

<%@ page import="" %>
<%@ page import="java.util.*" %>
<% ArrayList<HitDocument> docs = (ArrayList<HitDocument>) searchResult.getDocs();
for(HitDocument doc : docs ){ %>
 <%= doc.get("id") %>
<% } %>