This is not at all ready for prime-time but I'm inviting comments on the approach. It turns out that all the hard work has already been done, see QueryParserBase. The attached patch is almost all tests...
But I greatly fear that I'm grossly misusing
QueryParserBase.lowercaseExpandedTerms, which looks like it's for parameters on the query line? Where did that come from anyway? Or what the heck is it supposed to be used for, anyone know?
A couple of thing make me nervous about this approach. It depends in a pretty hard-coded way on detecting LowerCaseFilterFactory and LowerCaseTokenizerFactory, if anyone adds anything else in there it'll have to be re-coded. Is there a better way? It almost seems like a flag on the <field> definition as Peter suggested is a more robust way of going about things.
Anyway, I'm getting way past the point of diminishing returns tonight, so I thought I'd at least throw this out for comment.
Ignore everything with the ASCIIFoldingFilterFactory, I detect it but don't do anything with it yet.
And I can't seem to make the reversed test work, even without the casing switch. Which means I should put it down for the evening, I'm obviously fried. Anybody feeling kind can uncomment the line that starts:
// make me work
and get the test class to work. It's probably trivial but I'm not seeing it.