Functional Programming and Lucene Query Expansion
Monday, January 17th, 2005Last week I had a programming problem, I had to do a query expansion in Lucene. This particular expansion was to convert term and phrase queries into span queries to provide higher relevancy scores for results when the search terms were closer together.
I simplified the problem by only considering terms and phrases and boolean combinations of them. Basically:
- TermQuery becomes SpanTermQuery
- PhraseQuery becomes SpanNearQuery
- All those result span queries are combined into a SpanNearQuery
BooleanQueries would be handled recursive following the above convention. A BooleanQuery is essentially a list of BooleanClauses, so at this point those functional programming classes from school popped in my head. I have lists, recursion, base cases, it should be straightforward to jot down a solution in Haskell then I’ll translate it to Java. After a while I gave up and wrote a long piece of procedural code in Java, I just didn’t know Haskell well enough to write out anything more than trivial code.
