try (TokenStream source = getAnalyzer().tokenStream(field, termStr)) {
source.reset();
// Use the analyzer to get all the tokens, and then build a TermQuery,
// PhraseQuery, or nothing based on the term count
CachingTokenFilter buffer = new CachingTokenFilter(source);
buffer.reset();
TermToBytesRefAttribute termAtt = null;
int numTokens = 0;
boolean hasMoreTokens = false;
termAtt = buffer.getAttribute(TermToBytesRefAttribute.class);