def register_model(self, *index_fields, **kw):
<EOL>class ModelWhoosheer(AbstractWhoosheerMeta):<EOL><INDENT>@classmethod<EOL>def _assign_primary(cls, primary, primary_is_numeric, attrs, model):<EOL><INDENT>attrs[primary] = getattr(model, primary)<EOL>if not primary_is_numeric:<EOL><INDENT>if sys.version < '<STR_LIT:3>':<EOL><INDENT>attrs[primary] = unicode(attrs[primary])<EOL><DEDENT>else:<EOL><INDENT>attrs[primary] = str(attrs[primary])<EOL><DEDENT><DEDENT><DEDENT><DEDENT>mwh = ModelWhoosheer<EOL>def inner(model):<EOL><INDENT>mwh.index_subdir = model.__tablename__<EOL>mwh.models = [model]<EOL>schema_attrs = {}<EOL>for field in model.__table__.columns:<EOL><INDENT>if field.primary_key:<EOL><INDENT>primary = field.name<EOL>primary_is_numeric = True<EOL>if isinstance(field.type, SQLInteger):<EOL><INDENT>schema_attrs[field.name] = whoosh.fields.NUMERIC(stored=True, unique=True)<EOL><DEDENT>else:<EOL><INDENT>primary_is_numeric = False<EOL>schema_attrs[field.name] = whoosh.fields.ID(stored=True, unique=True)<EOL><DEDENT><DEDENT>elif field.name in index_fields:<EOL><INDENT>schema_attrs[field.name] = whoosh.fields.TEXT(**kw)<EOL><DEDENT><DEDENT>mwh.schema = whoosh.fields.Schema(**schema_attrs)<EOL>mwh._is_model_whoosheer = True<EOL>@classmethod<EOL>def update_model(cls, writer, model):<EOL><INDENT>attrs = {}<EOL>cls._assign_primary(primary, primary_is_numeric, attrs, model)<EOL>for f in index_fields:<EOL><INDENT>attrs[f] = getattr(model, f)<EOL>if not isinstance(attrs[f], int):<EOL><INDENT>if sys.version < '<STR_LIT:3>':<EOL><INDENT>attrs[f] = unicode(attrs[f])<EOL><DEDENT>else:<EOL><INDENT>attrs[f] = str(attrs[f])<EOL><DEDENT><DEDENT><DEDENT>writer.update_document(**attrs)<EOL><DEDENT>@classmethod<EOL>def insert_model(cls, writer, model):<EOL><INDENT>attrs = {}<EOL>cls._assign_primary(primary, primary_is_numeric, attrs, model)<EOL>for f in index_fields:<EOL><INDENT>attrs[f] = getattr(model, f)<EOL>if not isinstance(attrs[f], int):<EOL><INDENT>if sys.version < '<STR_LIT:3>':<EOL><INDENT>attrs[f] = unicode(attrs[f])<EOL><DEDENT>else:<EOL><INDENT>attrs[f] = str(attrs[f])<EOL><DEDENT><DEDENT><DEDENT>writer.add_document(**attrs)<EOL><DEDENT>@classmethod<EOL>def delete_model(cls, writer, model):<EOL><INDENT>writer.delete_by_term(primary, getattr(model, primary))<EOL><DEDENT>setattr(mwh, '<STR_LIT>'.format(UPDATE_KWD, model.__name__.lower()), update_model)<EOL>setattr(mwh, '<STR_LIT>'.format(INSERT_KWD, model.__name__.lower()), insert_model)<EOL>setattr(mwh, '<STR_LIT>'.format(DELETE_KWD, model.__name__.lower()), delete_model)<EOL>model._whoosheer_ = mwh<EOL>model.whoosh_search = mwh.search<EOL>self.register_whoosheer(mwh)<EOL>return model<EOL><DEDENT>return inner<EOL>
Registers a single model for fulltext search. This basically creates
        a simple Whoosheer for the model and calls :func:`register_whoosheer`
        on it.