January 2012 Archives

Stupid Lucene Tricks: Exact Match, Starts With, Ends With

Out of the box, Lucene does not provide exact field matches, like matching "Acer Negundo Ab" and only "Acer Negundo Ab" (not also "Acer Negundo Ab IgG" ). Neither does Lucene provide "Starts With" or "Ends With" functionality.

The trick is in the indexing. When indexing a field in Lucene, you can enclose a field's value with known delimiters, for example "lucenematch Acer Negundo Ab lucenematch" (where "lucenematch" is the delimiter string). As long as the delimiter appears only as a delimiter, you can safely assume that a search using "luceā€¦

About Mark Leighton Fisher

user-pic Perl/CPAN user since 1992.