* provided their number does not exceed the given limit and that this index has a {@link #prefixMap}.
*/
public IndexIterator documents( final CharSequence prefix, final int limit ) throws IOException, TooManyTermsException {
if ( prefixMap != null ) {
final Interval interval = prefixMap.rangeMap().get( prefix );
if ( interval == Intervals.EMPTY_INTERVAL ) return new Index.EmptyIndexIterator();
final IndexIterator result;
if ( interval.length() > limit ) throw new TooManyTermsException( interval.length() );
if ( interval.length() == 1 ) result = documents( interval.left );
else {
IndexIterator[] baseIterator = new IndexIterator[ interval.length()];
int k = 0;
for( IntIterator i = interval.iterator(); i.hasNext(); ) baseIterator[ k++ ] = documents( i.nextInt() );
result = MultiTermIndexIterator.getInstance( this, baseIterator );
}
result.term( prefix + "*" );
return result;