final String sentence = phraseContext.getSentence();
try {
Reader reader = new StringReader( sentence );
stream = queryContext.getQueryAnalyzer().reusableTokenStream( fieldName, reader);
CharTermAttribute termAttribute = stream.addAttribute( CharTermAttribute.class );
PositionIncrementAttribute positionAttribute = stream.addAttribute( PositionIncrementAttribute.class );
stream.reset();
int position = -1; //start at -1 since we apply at least one increment
List<Term> termsAtSamePosition = null;
while ( stream.incrementToken() ) {
int positionIncrement = 1;
if ( positionAttribute != null ) {
positionIncrement = positionAttribute.getPositionIncrement();
}
if ( positionIncrement > 0 ) {
position += positionIncrement;
termsAtSamePosition = termsPerPosition.get( position );
}
if ( termsAtSamePosition == null ) {
termsAtSamePosition = new ArrayList<Term>();
termsPerPosition.put( position, termsAtSamePosition );
}
String termString = new String( termAttribute.buffer(), 0, termAttribute.length() );
termsAtSamePosition.add( new Term( fieldName, termString ) );
if ( termsAtSamePosition.size() > 1 ) {
isMultiPhrase = true;
}
}