A short time ago, I started a side project to learn the latest version of Antlr. I decided to do something that has always interested me, a sql parser for the Lucene search engine. Even though the parser is a learning exercise, I thought someone else could find this useful. This post will cover the functionality of the
LuceneQueryParser. Building the parser using Antlr4 will be coming in later posts.
Introduction and Examples
LuceneSqlParser supports a subset of standard sql. Here are some examples:
1 2 3 4 5 6 7 8 9
LuceneSqlParser returns a BooleanQuery. The
BooleanQuery will contain different types of lucene query objects depending on the predicates used. There is a class
Searcher avaiable for use with the
Searcher abstracts away the opening of a lucene IndexSearcher, iterating over the ScoreDoc array and extracting results. Next, we’ll take a look at the rules used to parse the sql.