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

  Install pip flask_whooshalchemy   

Quickstart < / P>

  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)   

Create a post

  db.session.add ( Blog post (title = 'my cool title', content = 'this is the first post.')); Db.session.commit ()   

Text Search

  Result = BlogPost.query.whoosh_search ('Quiet') < / Code>  

We can limit the results:

  # Get two best results: Results = BlogPost.query.whoosh_search ( 'Cool', border = 2)   

source:

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -