def search_iter(db, query, limit=None, batch=100):
 count = search_count(db, query)
 if (not count):
  raise StopIteration
 remain = count
 if (limit is not None):
  remain = min(remain, limit)
 offset = 1
 prev_ids = []
 while remain:
  batch = min(batch, remain)
  ids = search(db, query, offset, batch).read().strip().split()
  assert (len(ids) == batch), ('Got %i, expected %i' % (len(ids), batch))
  if (ids == prev_ids):
   raise RuntimeError('Same search results for previous offset')
  for identifier in ids:
   if (identifier in prev_ids):
    raise RuntimeError(('Result %s was in previous batch' % identifier))
   (yield identifier)
  offset += batch
  remain -= batch
  prev_ids = ids

def search_iter ( db , query , limit = None , batch = 100 ) : count = search_count ( db , query ) if ( not count ) : raise StopIteration remain = count if ( limit is not None ) : remain = min ( remain , limit ) offset = 1 prev_ids = [ ] while remain : batch = min ( batch , remain ) ids = search ( db , query , offset , batch ) . read ( ) . strip ( ) . split ( ) assert ( len ( ids ) == batch ) , ( 'Got %i, expected %i' % ( len ( ids ) , batch ) ) if ( ids == prev_ids ) : raise RuntimeError ( 'Same search results for previous offset' ) for identifier in ids : if ( identifier in prev_ids ) : raise RuntimeError ( ( 'Result %s was in previous batch' % identifier ) ) ( yield identifier ) offset += batch remain -= batch prev_ids = ids
togows search iteratating over the results .