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...
Join my free course on the basics of Flask-SQLAlchemy: prettyprinted.com/flasksql
Sir please please and any time I want to run the program then I will get this error (No module named 'flaskext
I rarely post a comment on UA-cam but your videos are golden, really.
Thank you, bro. The best tutorial I have ever seen. Just continue to help dummies.
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!!!!!!!!!!!
I'm glad you feel that way. Thanks for watching!
Good Tutorial. One of the best channel for flask and python beginners. Thanks Pretty Printed
Thanks. That's an amazing compliment.
Thanks for supporting my videos!
This doesn't work in Python 3 for anyone wondering
Thank you, it is very straightforward!
This is the better tutorial to learn flask
The best Whoosh tutorial. Thanks !!!
Thanks for the compliment!
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?
Thanks Antony, another of your informative videos... Cheers
Thanks for watching!
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!
Thanks for this ....I have been struggling
Please help me to use msearch I can't find any official documentation of msearch you tube just showing the video of elastic search
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
Does it work well with python3? I have seen that there is an issue
Very helpful as all your tutorials, thanks a tons :) .
You're welcome, and thanks for watching as always.
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?
greate video. Iam having errors using whooshalchemy on my sqlite database. Does it work on a sqlite database?
This don't work on Python 3. No .search_index, no update search request. Where new video with update info?
I am getting this error
Textual sql expression 'null' should be explicitly declared as text('null')
ya, same
Same here
Thank you so much
Thanks for the video! Is the search case sensitive or not?
Hi Anthony, Could you please make one for python3. Apparently this does not work with python 3 and seeing error.
It's give me error no module named flaskext
Refer this link pypi.org/project/WhooshAlchemy
Use *flask-whooshalchemyplus*
Instead
can i use this on tables ? to get only the username i am searching for!!
Nice video! I like it
Thanks for watching!
Hello from 2022. Flask_whooshalchemy is no longer supported and does not work with python 3.0+.
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.
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".
Nevermind, I discovered you can use "users = User.query.whoosh_search("*test*").all()"
'*' is for zero or more characters.
Glad you figured it out! It's been a while since I've used this.
nice video
I like this video!
Thanks for watching!
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 )
I am facing the same problem bro
You just saved my ass.
Does this rank the search results too or just displays them?
no
@@abdechafielamraoui2840 Oh ok...Thank You :-)
In the video you use Sqlalchemy. Can we use MySQL db with Whoosh?
You can use MySQL through SQLAlchemy, yes.
I keep getting this error:Textual SQL expression 'null' should be explicitly declared as text('null').You know anything about it?
I haven't seen that error. Are you using the exact code I have here?
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!
@@blacksailorx168 buddy i need your help in solving this problem
Hi!! Is using whoosh_search better than using SQLAlchemy-Searchable? Looking at the video I think its better to use whoosh.
I haven't tried Searchable, but once I do I'll make a comparison between the two.
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.
-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)
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.
Thank you
You're welcome! Thanks for watching.
Nice Video Pretty Printed but please what version of python are you using ?
In this video, the version is 2.7. In recent videos, I use 3.4.
Breakage in this video using python3: (AttributeError: 'dict' object has no attribute 'iteritems'
Nice One
Thanks!
i get an error while importing db from my application. it says: " ModuleNotFoundError: No module named 'flask.ext' " Please Help!!
Can you show me what your import code is?
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' ".
@@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.
@@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.
@@vatsalaykhobragade Import it as flask.ext.whooshalchemy
good video thx
Thanks for watching!
flask whoosh doesn't support python 3 please consider making a video about including a search feature in python 3
yes and they changed their whole module
Does WhooshAlchemy work with sqlite?
Yes, the database doesn't matter (for the most part).
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
That could be an issue. If you aren't using the typical way querying, then that may be the issue.
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 !! .
Did you add the posts before or after configuring WooshAlchemy? It only indexes posts added after.
after that , why is that the problem ??
actually, i added another post after i configured WooshAlchemy, but without avail !
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.
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)
amazing (:
Thanks!