Looking for advice on handling ampersands and the word "and" in Lucene queries. My test queries are (including quotes):
- "oil and gas field" (complete phrase)
- "research and development" (complete phrase)
- "r&d" (complete phrase)
Ideally, I'd like to use the QueryParser
as the input is coming from the user.
During testing and doc reading, I found that using the StandardAnalyzer
doesn't work for what I want. For the first two queries, a QueryParser.Parse
converts them to:
contents:"oil gas field"
contents:"research development"
Which isn't what I want. If I use a PhraseQuery
instead, I get no results (presumably because "and" isn't indexed.
If I use a SimpleAnalyzer
, then I can find the phrases but QueryParser.Parse
converts the last term to:
contents:"r d"
Which again, isn't quite what I'm looking for.
Any advice?