Skip to content

Instantly share code, notes, and snippets.

@ethe
Last active November 17, 2015 02:48
Show Gist options
  • Select an option

  • Save ethe/7be6968a033cba532e41 to your computer and use it in GitHub Desktop.

Select an option

Save ethe/7be6968a033cba532e41 to your computer and use it in GitHub Desktop.
mongey patch for flask-whooshsqlalchemy
def _get_whoosh_schema_and_primary_key(model, analyzer):
schema = {}
primary = None
searchable = set(model.__searchable__)
for field in model.__table__.columns:
if field.primary_key:
schema[field.name] = whoosh.fields.ID(stored=True, unique=True)
primary = field.name
if field.name in searchable and isinstance(field.type,
(sqlalchemy.types.Text, sqlalchemy.types.String,
sqlalchemy.types.Unicode)):
schema[field.name] = whoosh.fields.TEXT(analyzer=analyzer)
for parent_class in model.__bases__:
for i in searchable:
if hasattr(parent_class, i):
schema[i] = whoosh.fields.TEXT(analyzer=analyzer)
return Schema(**schema), primary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment