@SuppressWarnings("unchecked") public List<NGramModel> find(String[] aToken){
  BooleanQuery q=new BooleanQuery();
  PhraseQuery pq=new PhraseQuery();
  pq.setSlop((5 - aToken.length) >= 0 ? (5 - aToken.length) : 0);
  for (  String t : aToken) {
    pq.add(new Term("gram",t.toLowerCase()));
  }
  q.add(pq,Occur.MUST);
  String cacheKey=q.toString();
  if (ngramCache.containsKey(cacheKey)) {
    List<NGramModel> list=(List<NGramModel>)ngramCache.get(cacheKey);
    return list;
  }
  try {
    NGramCollector collector=new NGramCollector();
    searcher.search(q,collector);
    List<NGramModel> ngrams=collector.getNgrams();
    ngramCache.put(cacheKey,ngrams);
    return ngrams;
  }
 catch (  IOException e) {
    throw new IllegalStateException(e);
  }
}

@ SuppressWarnings ( "unchecked" ) public List < NGramModel > find ( String [ ] aToken ) { BooleanQuery q = new BooleanQuery ( ) ; PhraseQuery pq = new PhraseQuery ( ) ; pq . setSlop ( ( 5 - aToken . length ) >= 0 ? ( 5 - aToken . length ) : 0 ) ; for ( String t : aToken ) { pq . add ( new Term ( "gram" , t . toLowerCase ( ) ) ) ; } q . add ( pq , Occur . MUST ) ; String cacheKey = q . toString ( ) ; if ( ngramCache . containsKey ( cacheKey ) ) { List < NGramModel > list = ( List < NGramModel > ) ngramCache . get ( cacheKey ) ; return list ; } try { NGramCollector collector = new NGramCollector ( ) ; searcher . search ( q , collector ) ; List < NGramModel > ngrams = collector . getNgrams ( ) ; ngramCache . put ( cacheKey , ngrams ) ; return ngrams ; } catch ( IOException e ) { throw new IllegalStateException ( e ) ; } }
find all n - grams containing these tokens in order but optionally with words between them .
