private Query analyzeMultiPhrase(String field,TokenStream stream,int slop) throws IOException {
  MultiPhraseQuery.Builder mpqb=newMultiPhraseQueryBuilder();
  mpqb.setSlop(slop);
  TermToBytesRefAttribute termAtt=stream.getAttribute(TermToBytesRefAttribute.class);
  PositionIncrementAttribute posIncrAtt=stream.getAttribute(PositionIncrementAttribute.class);
  int position=-1;
  List<Term> multiTerms=new ArrayList<>();
  stream.reset();
  while (stream.incrementToken()) {
    int positionIncrement=posIncrAtt.getPositionIncrement();
    if (positionIncrement > 0 && multiTerms.size() > 0) {
      if (enablePositionIncrements) {
        mpqb.add(multiTerms.toArray(new Term[0]),position);
      }
 else {
        mpqb.add(multiTerms.toArray(new Term[0]));
      }
      multiTerms.clear();
    }
    position+=positionIncrement;
    multiTerms.add(new Term(field,termAtt.getBytesRef()));
  }
  if (enablePositionIncrements) {
    mpqb.add(multiTerms.toArray(new Term[0]),position);
  }
 else {
    mpqb.add(multiTerms.toArray(new Term[0]));
  }
  return mpqb.build();
}

private Query analyzeMultiPhrase ( String field , TokenStream stream , int slop ) throws IOException { MultiPhraseQuery . Builder mpqb = newMultiPhraseQueryBuilder ( ) ; mpqb . setSlop ( slop ) ; TermToBytesRefAttribute termAtt = stream . getAttribute ( TermToBytesRefAttribute . class ) ; PositionIncrementAttribute posIncrAtt = stream . getAttribute ( PositionIncrementAttribute . class ) ; int position = - 1 ; List < Term > multiTerms = new ArrayList < > ( ) ; stream . reset ( ) ; while ( stream . incrementToken ( ) ) { int positionIncrement = posIncrAtt . getPositionIncrement ( ) ; if ( positionIncrement > 0 && multiTerms . size ( ) > 0 ) { if ( enablePositionIncrements ) { mpqb . add ( multiTerms . toArray ( new Term [ 0 ] ) , position ) ; } else { mpqb . add ( multiTerms . toArray ( new Term [ 0 ] ) ) ; } multiTerms . clear ( ) ; } position += positionIncrement ; multiTerms . add ( new Term ( field , termAtt . getBytesRef ( ) ) ) ; } if ( enablePositionIncrements ) { mpqb . add ( multiTerms . toArray ( new Term [ 0 ] ) , position ) ; } else { mpqb . add ( multiTerms . toArray ( new Term [ 0 ] ) ) ; } return mpqb . build ( ) ; }
creates complex phrase query from the cached tokenstream contents
