def add_spelling(ix, fieldnames, commit=True): """Adds spelling files to an existing index that was created without them, and modifies the schema so the given fields have the ``spelling`` attribute. Only works on filedb indexes. >>> ix = index.open_dir("testindex") >>> add_spelling(ix, ["content", "tags"]) :param ix: a :class:`whoosh.filedb.fileindex.FileIndex` object. :param fieldnames: a list of field names to create word graphs for. :param force: if True, overwrites existing word graph files. This is only useful for debugging. """ from whoosh.automata import fst from whoosh.reading import SegmentReader writer = ix.writer() storage = writer.storage schema = writer.schema segments = writer.segments for segment in segments: ext = segment.codec().FST_EXT r = SegmentReader(storage, schema, segment) f = segment.create_file(storage, ext) gw = fst.GraphWriter(f) for fieldname in fieldnames: gw.start_field(fieldname) for word in r.lexicon(fieldname): gw.insert(word) gw.finish_field() gw.close() for fieldname in fieldnames: schema[fieldname].spelling = True if commit: writer.commit(merge=False)