Last active
November 17, 2015 02:48
-
-
Save ethe/7be6968a033cba532e41 to your computer and use it in GitHub Desktop.
mongey patch for flask-whooshsqlalchemy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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