Debug Template

From DBSight Full-Text Search Engine/Platform Wiki

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

 doc.getValues("attribute_name")

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

 doc.get("attribute_name")

which only get one attribute value.

You can check for more details from the java doc for

net.javacoding.xsearch.search.HitDocument

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")>
 ${util.newStringUtf8(base64.decode("RGVzY2jDqm5lcw=="))}

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")>
${httpUtil.open("http://www.google.com")}


JSP template

Specifying JSP rendering

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

indexName=my_index_name&templateName=my_template&fileName=main.jsp

Then DBSight will look for templating file

/templates/<indexName>/<templateName>/main.jsp

Objects You can use

All objects for rendering should come from SearchResult class,

net.javacoding.xsearch.search.result.SearchResult.java

Pay some attention to

<%@ page import="net.javacoding.xsearch.search.result.SearchResult" %>
<% SearchResult searchResult = request.getAttribute("searchResult") %>

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

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