def MERGE_SQUARES(writer, segments):
 from whoosh.filedb.filereading import SegmentReader
 sizedsegs = [(s.doc_count_all(), s) for s in segments]
 tomerge = []
 for size in (10, 100, 1000, 10000, 100000):
  smaller = [seg for (segsize, seg) in sizedsegs if ((segsize < (size - 1)) and (segsize >= (size // 10)))]
  if (len(smaller) >= 10):
   tomerge.extend(smaller)
   for seg in smaller:
    segments.remove(seg)
 for seg in tomerge:
  reader = SegmentReader(writer.storage, writer.schema, seg)
  writer.add_reader(reader)
  reader.close()
 return segments

def MERGE_SQUARES ( writer , segments ) : from whoosh . filedb . filereading import SegmentReader sizedsegs = [ ( s . doc_count_all ( ) , s ) for s in segments ] tomerge = [ ] for size in ( 10 , 100 , 1000 , 10000 , 100000 ) : smaller = [ seg for ( segsize , seg ) in sizedsegs if ( ( segsize < ( size - 1 ) ) and ( segsize >= ( size // 10 ) ) ) ] if ( len ( smaller ) >= 10 ) : tomerge . extend ( smaller ) for seg in smaller : segments . remove ( seg ) for seg in tomerge : reader = SegmentReader ( writer . storage , writer . schema , seg ) writer . add_reader ( reader ) reader . close ( ) return segments
this is an alternative merge policy similar to lucenes .