Creating a Full-Text Search Enabled Blog in Flask Using Flask-WhooshAlchemy

Поділитися
Вставка
  • Опубліковано 15 вер 2024
  • Learn how to add full text search to a basic blog app in this video. I'll build a simple blog app, and then I'll add in search functionality using Flask-WhooshAlchemy. Many apps can use full text search, so if you have one, check out this video to learn how to integrate it in your app.
    Need one-on-one help with your project? I can help through my coaching program. Learn more here: prettyprinted....
    Join my free course on the basics of Flask-SQLAlchemy: prettyprinted....
    Watch the intro video here: • How to Add Full Text S...
    To get the Flask cheat sheet, visit prettyprinted.c...
    Flask-WhooshAlchemy: github.com/gyl...

КОМЕНТАРІ • 106

  • @prettyprinted
    @prettyprinted  4 роки тому

    Join my free course on the basics of Flask-SQLAlchemy: prettyprinted.com/flasksql

    • @Kennethlumor
      @Kennethlumor 2 роки тому

      Sir please please and any time I want to run the program then I will get this error (No module named 'flaskext

  • @trax4085
    @trax4085 4 роки тому

    I rarely post a comment on UA-cam but your videos are golden, really.

  • @bekbull
    @bekbull 4 роки тому

    Thank you, bro. The best tutorial I have ever seen. Just continue to help dummies.

  • @imad54321
    @imad54321 7 років тому

    Just perfect. I've seen many framework tutorials before trying them out, but yours by far stand head and shoulders above all i've seen! thanks!!!!!!!!!!!

    • @prettyprinted
      @prettyprinted  7 років тому

      I'm glad you feel that way. Thanks for watching!

  • @shubhamrathi1532
    @shubhamrathi1532 7 років тому +1

    Good Tutorial. One of the best channel for flask and python beginners. Thanks Pretty Printed

    • @prettyprinted
      @prettyprinted  7 років тому

      Thanks. That's an amazing compliment.
      Thanks for supporting my videos!

  • @lewishousten5455
    @lewishousten5455 4 роки тому +5

    This doesn't work in Python 3 for anyone wondering

  • @master1982
    @master1982 4 роки тому +1

    Thank you, it is very straightforward!

  • @richardjimenez7819
    @richardjimenez7819 6 років тому

    This is the better tutorial to learn flask

  • @jhicinternational
    @jhicinternational 8 років тому

    The best Whoosh tutorial. Thanks !!!

  • @unclekim86
    @unclekim86 3 роки тому

    Hi, I just found you out of google search for doing my project. I just liked, subscribed, set alarms. Thank universe I found you. Clear, straight, best voice to focus. Thank you for existing. You are my boss/full-time watch list from now. As a beginner in web-coding world, just had 2 weeks of chaos after the end of basic online class but now I see a very bright light. In one of the comments, I see someone saying "whoosh-search has been abandoned" and use "flask-msearch", is that right? Is there any big difference to the contents of this video due to this replacement issue?

  • @regbarnard2866
    @regbarnard2866 5 років тому

    Thanks Antony, another of your informative videos... Cheers

  • @marktwain3083
    @marktwain3083 3 роки тому +2

    For those of you wondering, whoosh-search has been abandoned so I highly recommend not using it, especially if you are using Python 3.
    Alternatively, you could try flask-msearch, which is actually what whoosh's developer suggests.
    It's almost similar to whoosh in terms of use and functionality, if you have any problem setting it up just reply to my comment and I'll do my best to help you.
    Have fun coding!

    • @lameckotieno5837
      @lameckotieno5837 3 роки тому +1

      Thanks for this ....I have been struggling

    • @memeplay7142
      @memeplay7142 2 роки тому

      Please help me to use msearch I can't find any official documentation of msearch you tube just showing the video of elastic search

    • @abdullahiowosunkanmiakanbi6470
      @abdullahiowosunkanmiakanbi6470 2 роки тому

      I want to know if this replacement for whoosh can be used for peewee. I am a newbie and I am trying to do a search API but I am not using alchemy as explained in this video

  • @AyushVerma-cw6om
    @AyushVerma-cw6om 4 роки тому +1

    Does it work well with python3? I have seen that there is an issue

  • @gurucode.studio
    @gurucode.studio 8 років тому

    Very helpful as all your tutorials, thanks a tons :) .

    • @prettyprinted
      @prettyprinted  8 років тому

      You're welcome, and thanks for watching as always.

  • @betulciftci1930
    @betulciftci1930 5 років тому +1

    Thank you so much for the tutorial! I am having trouble displaying the data after searching. Would you mind including the index.html file to your rep?

  • @hallsaga9719
    @hallsaga9719 3 роки тому

    greate video. Iam having errors using whooshalchemy on my sqlite database. Does it work on a sqlite database?

  • @LinkstaRuViews
    @LinkstaRuViews 4 роки тому

    This don't work on Python 3. No .search_index, no update search request. Where new video with update info?

  • @satishgupta48
    @satishgupta48 4 роки тому +1

    I am getting this error
    Textual sql expression 'null' should be explicitly declared as text('null')

  • @desmondadefon6116
    @desmondadefon6116 7 років тому +2

    Thank you so much

  • @Leon-xg7zj
    @Leon-xg7zj 4 роки тому

    Thanks for the video! Is the search case sensitive or not?

  • @rana9903
    @rana9903 4 роки тому

    Hi Anthony, Could you please make one for python3. Apparently this does not work with python 3 and seeing error.

  • @pratikt007
    @pratikt007 5 років тому +1

    It's give me error no module named flaskext

    • @iaashu98
      @iaashu98 4 роки тому

      Refer this link pypi.org/project/WhooshAlchemy

    • @MrStreamer
      @MrStreamer 4 роки тому

      Use *flask-whooshalchemyplus*
      Instead

  • @anouartouil3645
    @anouartouil3645 4 роки тому

    can i use this on tables ? to get only the username i am searching for!!

  • @ShampooWow
    @ShampooWow 8 років тому

    Nice video! I like it

  • @nah0221
    @nah0221 2 роки тому

    Hello from 2022. Flask_whooshalchemy is no longer supported and does not work with python 3.0+.

    • @solobloke8116
      @solobloke8116 2 роки тому

      There is a project called MSEARCH, which is supposed to continue development, It is pretty much a whoosh migrated to python3+. I have it running, the only problem is - I can't make it case insensitive.

  • @grgersh
    @grgersh 6 років тому +1

    How do I get all results for a substring? For instance, if I want to search for "testing123"
    users = User.query.whoosh_search("test").all()
    will return "testing123"?
    Right now, it only returns "testing123" if I input exactly "testing123".

    • @grgersh
      @grgersh 6 років тому +1

      Nevermind, I discovered you can use "users = User.query.whoosh_search("*test*").all()"
      '*' is for zero or more characters.

    • @prettyprinted
      @prettyprinted  6 років тому +1

      Glad you figured it out! It's been a while since I've used this.

  • @desmondadefon6116
    @desmondadefon6116 7 років тому +1

    nice video

  • @mxd8
    @mxd8 5 років тому

    I like this video!

  • @naveenshetty2891
    @naveenshetty2891 4 роки тому

    Pretty Nice tutorial, well described. but now i am stuck . whenever i am trying to run the WHoosh seacrh query . it throws out this message " sqlalchemy.exc.ArgumentError: Textual SQL expression 'null' should be explicitly declared as text('null')"
    Couldn't figure out what is it , my app route and Item class below. Can you help me out
    class Item(db.Model):
    __tablename__ = 'item'
    __searchable__ =['id','item','description', 'barcode','cross_ref_type' ]
    id = db.Column('id', db.Integer, primary_key=True)
    item = db.Column('item', db.Unicode)
    description = db.Column('description', db.Unicode)
    barcode = db.Column('barcode', db.Unicode)
    cross_ref_type = db.Column('cross_ref_type', db.Unicode)
    @app.route('/search', methods=['GET', 'POST'])
    def search():
    test=request.args.get('query')
    print(test)
    ilist=Item.query.whoosh_search(request.args.get('query')).all()
    return render_template('index.html', ilist=ilist )

    • @MrStreamer
      @MrStreamer 4 роки тому

      I am facing the same problem bro

  • @tonywu5314
    @tonywu5314 4 роки тому

    You just saved my ass.

  • @iimb-inventorsinventingmac4338
    @iimb-inventorsinventingmac4338 3 роки тому

    Does this rank the search results too or just displays them?

  • @aneeshdalvi528
    @aneeshdalvi528 6 років тому

    In the video you use Sqlalchemy. Can we use MySQL db with Whoosh?

    • @prettyprinted
      @prettyprinted  5 років тому

      You can use MySQL through SQLAlchemy, yes.

  • @blacksailorx168
    @blacksailorx168 7 років тому

    I keep getting this error:Textual SQL expression 'null' should be explicitly declared as text('null').You know anything about it?

    • @prettyprinted
      @prettyprinted  7 років тому

      I haven't seen that error. Are you using the exact code I have here?

    • @blacksailorx168
      @blacksailorx168 7 років тому

      Yes I used the exact same code,I had to re index all the records in db because as far as I understood the old records are not indexed automatically when you first install Whoosh so I managed to solve the problem with this:
      from flask_whooshalchemyplus import index_all
      index_all(app)
      Thanks!

    • @satishgupta48
      @satishgupta48 4 роки тому

      @@blacksailorx168 buddy i need your help in solving this problem

  • @shashankgupta4634
    @shashankgupta4634 6 років тому

    Hi!! Is using whoosh_search better than using SQLAlchemy-Searchable? Looking at the video I think its better to use whoosh.

    • @prettyprinted
      @prettyprinted  5 років тому

      I haven't tried Searchable, but once I do I'll make a comparison between the two.

    • @josephsowah1678
      @josephsowah1678 5 років тому

      Hello, I'm trying to use the request.args.get('') but I don't know what query parameter to pass in it seem he didn't show us how to create the query string he passed in or am I missing something.

  • @desmondadefon6116
    @desmondadefon6116 7 років тому

    -1
    down vote
    favorite

    i have a database in this manner, i want to ask if i can first
    commit data to email and password and login user before requesting and
    commiting data to the other table fields ? or i should used 2 separate database
    class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(100),unique=True)
    password = db.Column(db.String(70))
    repeat_password = db.Column(db.String(70))
    country = db.Column(db.String(100), index=True)
    store_name = db.Column(db.String(100), index=True)
    store_number = db.Column(db.Integer(), index=True)
    contact_number = db.Column(db.BigInteger())
    store_description = db.Column(db.Text(), index=True)
    store_location = db.Column(db.Text(), index=True)
    search_tag = db.Column(db.String(500), index=True)

    • @prettyprinted
      @prettyprinted  7 років тому +1

      It's normal to not have all the data ready at once. So yes, you can commit the email and password first and supply the rest of the data later. You don't have to create another table.

  • @richardjimenez7819
    @richardjimenez7819 6 років тому

    Thank you

    • @prettyprinted
      @prettyprinted  6 років тому +1

      You're welcome! Thanks for watching.

  • @desmondadefon6116
    @desmondadefon6116 7 років тому

    Nice Video Pretty Printed but please what version of python are you using ?

    • @prettyprinted
      @prettyprinted  7 років тому

      In this video, the version is 2.7. In recent videos, I use 3.4.

    • @mxd8
      @mxd8 5 років тому

      Breakage in this video using python3: (AttributeError: 'dict' object has no attribute 'iteritems'

  • @anilreddy6510
    @anilreddy6510 7 років тому

    Nice One

  • @vatsalaykhobragade
    @vatsalaykhobragade 5 років тому

    i get an error while importing db from my application. it says: " ModuleNotFoundError: No module named 'flask.ext' " Please Help!!

    • @prettyprinted
      @prettyprinted  5 років тому

      Can you show me what your import code is?

    • @vatsalaykhobragade
      @vatsalaykhobragade 5 років тому

      here's the code:
      from flask import Flask, render_template
      from flask_sqlalchemy import SQLAlchemy
      import flask_whooshalchemy as wa
      app = Flask(__name__)
      app.config['SQALCHEMY_DATABASE_URI'] = r'sqlite:///D:\\blog\\mydb.db'
      app.config['SQLALCHEMY_TRACK_MODIFICATIONS']=True
      app.config['WHOOSH_BASE'] = 'whoosh'
      db = SQLAlchemy(app)
      class Post(db.Model):
      __searchable__ = ['title', 'content']
      id = db.Column(db.Integer, primary_key=True)
      title = db.Column(db.String(100))
      content = db.Column(db.Stiring(100))
      wa.whoosh_index(app, Post)
      @app.route('/')
      @app.route('/home')
      def index():
      return render_template('index.html')
      if __name__ == '__main__':
      app.run(debug=True)
      so, when i say " from fulltext import db " in my cmd. it gives me an error " ModuleNotFoundError: No module named ' flask.ext' ".

    • @mrfekmefrjk
      @mrfekmefrjk 5 років тому

      @@prettyprinted I am also getting the same error. also when i import all in cmd it gives "ModuleNotFoundError: No module named 'flask_whooshalchemy". I have installed flask_whooshalchemy in project using pip.

    • @prettyprinted
      @prettyprinted  5 років тому

      @@mrfekmefrjk When I have a chance, I'll look into what's causing this problem. I'm not sure if Whoosh Alchemy is still being developed.

    • @Blazephoenix
      @Blazephoenix 5 років тому

      @@vatsalaykhobragade Import it as flask.ext.whooshalchemy

  • @kaanacar3570
    @kaanacar3570 5 років тому

    good video thx

  • @fredski6900
    @fredski6900 5 років тому

    flask whoosh doesn't support python 3 please consider making a video about including a search feature in python 3

    • @iaashu98
      @iaashu98 4 роки тому

      yes and they changed their whole module

  • @brunokd2
    @brunokd2 7 років тому

    Does WhooshAlchemy work with sqlite?

    • @prettyprinted
      @prettyprinted  7 років тому

      Yes, the database doesn't matter (for the most part).

    • @brunokd2
      @brunokd2 7 років тому

      I don't know what I am doing wrong
      When I write "Post.query.whoosh_search(request.args.get('query')).all()" it returns
      "
      Traceback (most recent call last):
      File "", line 1, in
      AttributeError: type object 'Post' has no attribute 'query'
      "
      When I write "session.query(Post).whoosh_search(request.args.get('query')).all()" it returns
      "
      Traceback (most recent call last):
      File "", line 1, in
      AttributeError: 'Query' object has no attribute 'whoosh_search'
      "
      I am using sqlalchemy "create_engine" to access the database, a bit different from the way you did it
      "
      engine = create_engine(
      'postgresql:///xxx')
      Base.metadata.bind = engine
      DBSession = sessionmaker(bind = engine)
      session = DBSession()
      "
      do you think my problem is related to that? do you have any idea on how I could fix it?
      thanks

    • @prettyprinted
      @prettyprinted  7 років тому

      That could be an issue. If you aren't using the typical way querying, then that may be the issue.

  • @gurucode.studio
    @gurucode.studio 7 років тому

    Dude, why am getting this error inside the shell every time am trying to search a post (" 'BaseQuery' object has no attribute 'whooshy_search' ") ??, infact, the configuration is ok and i have more than 20 post inside my database !! .

    • @prettyprinted
      @prettyprinted  7 років тому

      Did you add the posts before or after configuring WooshAlchemy? It only indexes posts added after.

    • @gurucode.studio
      @gurucode.studio 7 років тому

      after that , why is that the problem ??

    • @gurucode.studio
      @gurucode.studio 7 років тому

      actually, i added another post after i configured WooshAlchemy, but without avail !

    • @prettyprinted
      @prettyprinted  7 років тому

      I'm just thinking of the issues I had when I was using Whoosh. That was one of them.
      The other thing I can think of is a missing whoosh_index call on your class.

    • @gurucode.studio
      @gurucode.studio 7 років тому

      Here is the code that am having inside my models.py:
      from flask import current_app, Flask
      def whooshy(current_app):
      with current_app.app_context():
      whooshy.whoosh_index(current_app, Course)

  • @vatsalaykhobragade
    @vatsalaykhobragade 5 років тому

    amazing (: