#NEWLINE# def appendtextindex( table , index_or_dirname , indexname = None , merge = True , optimize = False ) : #NEWLINE# #INDENT# '\n    Load all rows from `table` into a Whoosh index, adding them to any existing\n    data in the index.\n\n    Keyword arguments:\n\n    table\n        A table container with the data to be loaded.\n    index_or_dirname\n        Either an instance of `whoosh.index.Index` or a string containing the\n        directory path where the index is to be stored.\n    indexname\n        String containing the name of the index, if multiple indexes are stored\n        in the same directory.\n    merge\n        Merge small segments during commit?\n    optimize\n        Merge all segments together?\n\n    ' #NEWLINE# import whoosh.index #NEWLINE# if isinstance ( index_or_dirname , string_types ) : #NEWLINE# #INDENT# dirname = index_or_dirname #NEWLINE# index = whoosh . index . open_dir ( dirname , indexname = indexname , readonly = False ) #NEWLINE# needs_closing = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( index_or_dirname , whoosh . index . Index ) : #NEWLINE# #INDENT# index = index_or_dirname #NEWLINE# needs_closing = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ArgumentError ( ( 'expected string or index, found %r' % index_or_dirname ) ) #NEWLINE# #UNINDENT# #UNINDENT# writer = index . writer ( ) #NEWLINE# try : #NEWLINE# #INDENT# for d in dicts ( table ) : #NEWLINE# #INDENT# writer . add_document ( ** d ) #NEWLINE# #UNINDENT# writer . commit ( merge = merge , optimize = optimize ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# writer . cancel ( ) #NEWLINE# raise #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# if needs_closing : #NEWLINE# #INDENT# index . close ( )