python - Search Index for user articles -
I am creating a note in which users can create notes, add photos, add tags to create applications And can share with friends. I am using Python Flask Framework to make tools.
I want to provide a feature in which a user can search through his notes. How do I go about creating an index, is there a library that can do it fast?
I am using Mongodi as a backend DB
You have tried to use flask-violet alkki.
Flask-VioletAlky is a flask extension that integrates Wooth's text-search functionality with SORKK ORM's in Flask applications.
Install Quickstart < / P> Create a post Text Search We can limit the results: source:
Install pip flask_whooshalchemy
import flask.ext.whooshalchemy # whoosh index app.config ['WHOOSH_BASE'] = 'Set path for the path / in / whoosh / base' category BlogPost (db.Model): __tablename__ = 'blogpost' __searchable__ = ['title', 'content'] # this area will be indexed by whoosh id = app.db.Column (app.db.Integer, primary_key = true) title = app.db. Column (app.db.Text) content = app.db.Column (app.db.Text) created = db.Column (db.DateTime, default = datetime.datetime.utcnow) def __repr __ (auto): r Aturn ' {0} (title = {1}) ' Format (self.__ class __.__name__, sevital)
db.session.add ( Blog post (title = 'my cool title', content = 'this is the first post.')); Db.session.commit ()
Result = BlogPost.query.whoosh_search ('Quiet') < / Code>
# Get two best results: Results = BlogPost.query.whoosh_search ( 'Cool', border = 2)
Comments
Post a Comment