Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I use flask-whooshee to search but I got UnknownFieldError returned #46

Open
yyz1018tt opened this issue Mar 31, 2019 · 2 comments
Open
Labels

Comments

@yyz1018tt
Copy link

I register the column 'title' like:

@whooshee.register_model('body', 'title')
class Post(db.Model):
    __tablename__ = 'posts'
    id = db.Column(db.Integer, primary_key=True)
    body = db.Column(db.Text)
    title = db.Column(db.String(60))

there are other two models:

@whooshee.register_model('name')
class Category(db.Model):
    __tablename__ = 'categories'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), unique=True)
    posts = db.relationship('Post', back_populates='category')
@whooshee.register_model('username', 'name')
class User(UserMixin, db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(64), unique=True, index=True)
    username = db.Column(db.String(64), unique=True, index=True)
    role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
    password_hash = db.Column(db.String(128))
    confirmed = db.Column(db.Boolean, default=False)
    name = db.Column(db.String(64))

but I got

UnknownFieldError:No field named 'title' in <Schema: ['body', 'id']>

when I do the search, I do not know how to deal with it, the model User and Category are correct but the Post.

@yyz1018tt
Copy link
Author

Here is the traceback, dont know if it helps.

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/yangyuze/Documents/Sample/venv/lib/python2.7/site-packages/flask_whooshee.py", line 469, in reindex
    getattr(wh, method_name)(writer, item)
  File "/Users/yangyuze/Documents/Sample/venv/lib/python2.7/site-packages/flask_whooshee.py", line 345, in update_model
    writer.update_document(**attrs)
  File "/Users/yangyuze/Documents/Sample/venv/lib/python2.7/site-packages/whoosh/writing.py", line 490, in update_document
    self.add_document(**fields)
  File "/Users/yangyuze/Documents/Sample/venv/lib/python2.7/site-packages/whoosh/writing.py", line 730, in add_document
    self._check_fields(schema, fieldnames)
  File "/Users/yangyuze/Documents/Sample/venv/lib/python2.7/site-packages/whoosh/writing.py", line 718, in _check_fields
    % (name, schema))

@bkabrda
Copy link
Collaborator

bkabrda commented Apr 2, 2019

Thanks for the bug report!
Did you have a previous version of the code that used just @whooshee.register_model('body')? If so, you'd need to do reindexing [1].
What you're seeing is a Whoosh error that says the schema only has id and body, so that would suggest it was created before you also added title in your code. If you can confirm this and reindex will work for you, I'll make this clear in the documentation.
If this is not the case, please let me know flask-whooshee version you're using and we'll come up with a reproducer and a fix.

[1] https://flask-whooshee.readthedocs.io/en/latest/#reindexing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants