__init__.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:Flask-WhooshAlchemy3 作者: blakev 项目源码 文件源码
def get_schema(model, analyzer):
    schema = {}
    primary = None
    searchable = set(getattr(model, '__searchable__', []))

    for field in model.__table__.columns:
        # primary key id
        if field.primary_key:
            schema[field.name] = whoosh_fields.ID(
                stored=True, unique=True, sortable=True)
            primary = field.name

        if field.name not in searchable:
            continue

        # text types
        if isinstance(field.type, TEXT_TYPES):
            schema[field.name] = whoosh_fields.TEXT(analyzer=analyzer)

        elif isinstance(field.type, DATE_TYPES):
            is_unique = getattr(field, 'unique', False)
            schema[field.name] = whoosh_fields.DATETIME(unique=is_unique)

        elif isinstance(field.type, sql_types.Boolean):
            schema[field.name] = whoosh_fields.BOOLEAN()

        else:
            raise WhooshAlchemyError(
                'cannot index column of type %s' % field.type)

    return whoosh_fields.Schema(**schema), primary
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号