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

query search select columns from registered model #56

Open
henryorton opened this issue Jul 3, 2020 · 1 comment
Open

query search select columns from registered model #56

henryorton opened this issue Jul 3, 2020 · 1 comment

Comments

@henryorton
Copy link

Is it possible to search only within select columns of the registered model. Say you have:

@whooshee.register_model('title', 'content')
class Entry(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String)
    content = db.Column(db.Text)

It would be great if I could only search content column by:

Entry.query.whooshee_search('chuck norris', fields=('content',)).all()

Or is it possible to do this by registering a custom woosheer? I can't quite figure out how to be able to search both 'title' and 'content', while also being able to search only 'title' or 'content' separately.

@henryorton
Copy link
Author

So I found that I can make a custom whoosheer to only search the 'content' column as below. However this seems to create a separate index from the original registered model. This seems a little inefficient or is that how these full text searches work? Is there something I'm missing?

@whooshee.register_whoosheer
class ContentWhoosheer(AbstractWhoosheer):
    schema = whoosh.fields.Schema(
        entry_id = whoosh.fields.NUMERIC(stored=True, unique=True),
        content = whoosh.fields.TEXT())

    models = [Entry]

    @classmethod
    def update_entry(cls, writer, entry):
        writer.update_document(entry_id=entry.id,
                               content=entry.content)

    @classmethod
    def insert_entry(cls, writer, entry):
        writer.add_document(review_id=review.id,
                               content=entry.content)

    @classmethod
    def delete_entry(cls, writer, entry):
        writer.delete_by_term('entry_id', entry.id)

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

No branches or pull requests

1 participant