Blog

Lucene Query Syntax for SQL

Aug 02 2011

Lucene provides a rich query syntax allowing users to easily create simple queries and scale up to complex ones. A number of search back-ends are built on top of Lucene nowadays such as ElasticSearch and Solr. In this article we will explore using Lucene’s query syntax against relational databases. We used Groovy here, but it […]

Handling Date Parameters in Grails

Mar 28 2011

Grails generally makes it very easy to bind request parameters to domain objects or command objects with properties of varying types. For most request parameters, a simple call to a controller’s bindData() method is all you need to handle property binding and type conversion. Unfortunately, the default Date binder is very rigid and only handles […]

Highlight text using Lucene

Mar 06 2011

The following code illustrates how to use the Lucene highlighter to highlight text in any String. import java.io.InputStream; import java.net.URI; import java.net.URL; import org.apache.commons.io.IOUtils; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.search.highlight.Highlighter; import org.apache.lucene.search.highlight.NullFragmenter; import org.apache.lucene.search.highlight.QueryScorer; import org.apache.lucene.util.Version; public class LuceneHighlighter { public static String highlight(String pText, String pQuery) throws Exception { Analyzer analyzer = […]

Scale an Image in Java

Mar 06 2011

Java has a rich Image manipulation layer. The following code shows how you can scale an input BufferedImage. import java.awt.AlphaComposite; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.io.File; import java.net.URI; import java.net.URL; import javax.imageio.ImageIO; public class ImageUtil { public static BufferedImage scale(BufferedImage pImage, int pWidth, int pHeight) { int type = pImage.getType() == 0 ? […]