Git Product home page Git Product logo

flask-whooshalchemy's People

Contributors

alekzvik avatar gyllstromk avatar huxuan avatar jfinkels avatar jrast avatar kerneltravel avatar miguelgrinberg avatar rdthree avatar rlam3 avatar ssherar avatar tonet666p avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-whooshalchemy's Issues

whoosh_seach multi words??

now I can search with
results = BlogPost.query.whoosh_search('cool')

but what if I want to search multi words at the same time??? like
results = BlogPost.query.whoosh_search('cool', 'happy', 'smile')

Is this supported??

'AttributeError' when runserver restart

hi:
model/epo.py:
from cscsearch.extensions import db
import flask.ext.whooshalchemy
import datetime

class Epo(db.Model):
tablename = 'epo'
searchable = ['title', 'doc']

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200))
    doc = db.Column(db.Text())
    tag = db.Column(db.String(120))
    date = db.Column(db.DateTime(),default = datetime.datetime.now())

    def __repr__(self):
            return '{0}(title={1})'.format(self.__class__.__name__, self.title)
            #return self.title,self.doc

    def __unicode__(self):
            return self.title

    def store_to_db(self):
            db.session.add(self)
            db.session.commit()

    def delete_from_db(self):
            db.session.delete(self)
            db.session.commit()

views/epo.py:

from cscsearch.models import Anonymous, User, LoginUser, Log, Epo

epo = Blueprint("epo", name)

@epo.route('/', methods=['GET','POST'])
def index():
if request.method == 'POST':
se = request.form['se']
if se:
art = Epo.query.whoosh_search(se)
else:
art = Epo.query.all()
else:
art = Epo.query.all()

return render_template("epodoc.html",art=art)

when add some new content, it will work well. But when Flask runserver restart, it will show "AttributeError: 'BaseQuery' object has no attribute 'whoosh_search'".

Project abandoned - please use alternatives

Recommended Alternative: flask-msearch

Hello everyone!

Flask-WhooshAlchemy has for a long time been one of the de-facto full-text search libraries for Flask, but I think it is time that baton is passed on to another project.

I had long ago forked this package, and incorporated some long-standing PRs and released it on PyPI as flask_whooshalchemy_redux.

This project has not seen active development on the master branch for 4 years now, and the latest release on PyPI is 6 years old. Even some of the fixed bugs have not made their way to PyPI.

I would like to thank @gyllstromk for his contributions to the Flask ecosystem. Flask-WhooshAlchemy has played an important role in giving Flask the reputation for simplicity that it has come to be known for.

Open source is hard, and it is very real, hard work for creators of open source projects to support them over time. We cannot fault @gyllstromk for not being able to keep this project going anymore, whatever the reason. He has made a very important contribution to the Flask community during the projects infancy, which I am sure has been responsible for getting more people to consider and use Flask. Thanks Karl for all the hard work you have put into this project, it is very much appreciated and we are grateful.

As a collaborator on this project, and as a member of the Flask community, I think it is time newer libraries with more active development have the baton passed to them.

After reviewing the state of the current Flask search library ecosystem, I recommend Flask-msearch as a successor to this library, for these reasons:

  • Support for Whoosh
  • Support for Elasticsearch
  • Active, ongoing development (last commit is from 15 days ago)

There are undoubtedly other libraries which should also be considered, so feel free to check out the awesome-flask link and do your own research as well.

As the creator of the project, @gyllstromk has the ultimate say in if he wants to officially recommend people to switch to other libraries, if so, I urge him to update the README to redirect people to alternatives.

whoosh_search returns empty

Tutorial at http://pythonhosted.org/Flask-WhooshAlchemy/ works for me.

Here's my setup

class Post(db.Model):
    __tablename__ = 'post'
    __searchable__ = ['body']

    id = db.Column(db.Integer, primary_key=True)
    body = db.Column(db.String)

Results:

  • If I do not put whoosh_index() before whoosh_search(), I get the error:
    AttributeError: 'BaseQuery' object has no attribute 'whoosh_search'
  • db.session.query(Post).filter(Post.body=='hi') returns the correct output with my data.
    Post.query.whooshee_search('hi') returns empty

I did leave some code out, like additional columns and backrefs, but that should not affect anything.

There are a few things to note:

  • Tutorial worked fine without whoosh_index(), but my code threw error when I did not include it.
  • db.session.query(Post).filter() code worked fine, indicating my model is at least somewhat correct, and there is something wrong with whoosh/my whoosh setup

I welcome any feedback, thanks

Flask mailing list announce

You should announce your extension on Flask mailing list. It can draw you some more attention from community.

NameError: File '_MAIN_0.toc' exists

Hello, I install Flask-WhooshAlchemy and config according to your QuickStart,
but when I use docker to deploy my app, run it and visit my route,it raise the error:

File "/usr/local/lib/python2.7/site-packages/whoosh/filedb/filestore.py", line 552, in rename_file
  raise NameError("File %r exists" % newname)
NameError: File '_MAIN_0.toc' exists

My code:

app/Init.py:

import flask_whooshalchemy as whooshalchemy

def create_app(config_name=None, main=True):
    if config_name is None:
        config_name = 'default'
    app = Flask(__name__)
    app.config.from_object(config[config_name])

    config[config_name].init_app(app)
    db.init_app(app)
    moment.init_app(app)
    toolbar.init_app(app)
    login_manager.init_app(app)

    from .models import BlogPost
    whooshalchemy.whoosh_index(app, BlogPost)

    return app

app = create_app(config_name = 'default')

app/models.py:

class BlogPost(db.Model):
    __tablename__ = 'blogpost'
    __searchable__ = ['title', 'content'] 

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String)  
    content = app.db.Column(db.Text)  

config.py

class Config:
    WHOOSH_BASE = os.path.join(basedir,"whoosh_index")

Do not support the model which inherit from another

For example,

from app import db

class PostBase(db.Model):
    __tablename__ = 'post_base'
    __searchable__ = ['title', 'detail']

    title = db.Column(db.String())
    detail = db.Column(db.String())

class FilePost(PostBase):
    __tablename__ = 'file_post'

    file_path = db.Column(db.String())

when save object from FilePost, it would throw an error:no field 'title' in <Schema: id>

Error when import the module

When i following this tutorial, i have error when importing the module.

>>> import flask_whooshalchemy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/flask_whooshalchemy.py", line 18, in <module>                                 
import flask.ext.sqlalchemy as flask_sqlalchemy                    
ModuleNotFoundError: No module named 'flask.ext'                       
>>>

I running my script on termux

AttributeError: 'result' object has no attribute 'id'

Traceback (most recent call last):
File "/Users/Tyler/Desktop/cookie/env/lib/python2.7/site-packages/flask/app.py", line 1836, in call
return self.wsgi_app(environ, start_response)
File "/Users/Tyler/Desktop/cookie/env/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/Tyler/Desktop/cookie/env/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/Tyler/Desktop/cookie/env/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/Users/Tyler/Desktop/cookie/env/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/Tyler/Desktop/cookie/env/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/Tyler/Desktop/cookie/env/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/Tyler/Desktop/cookie/env/lib/python2.7/site-packages/flask_debugtoolbar/init.py", line 124, in dispatch_request
return view_func(*_req.view_args)
File "/Users/Tyler/Desktop/cookie/env/lib/python2.7/site-packages/flask_login.py", line 758, in decorated_view
return func(_args, *_kwargs)
File "/Users/Tyler/Desktop/cookie/env/lib/python2.7/site-packages/flask_security/decorators.py", line 194, in decorated_view
return fn(_args, kwargs)
File "/Users/Tyler/Desktop/cookie/recruit_app/recruit_app/recruit/views.py", line 49, in application_queue
recruiter_queue = HrApplication.query.whoosh_search('
' + str(search_form.search.data) + '
').paginate(page, current_app.config['MAX_NUMBER_PER_PAGE'], False)
File "/Users/Tyler/Desktop/cookie/env/lib/python2.7/site-packages/flask_sqlalchemy/init.py", line 440, in paginate
total = self.order_by(None).count()
File "/Users/Tyler/Desktop/cookie/env/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2734, in count
return self.from_self(col).scalar()
File "/Users/Tyler/Desktop/cookie/env/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2513, in scalar
ret = self.one()
File "/Users/Tyler/Desktop/cookie/env/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2482, in one
ret = list(self)
File "/Users/Tyler/Desktop/cookie/env/lib/python2.7/site-packages/flask_whooshalchemy.py", line 75, in iter
self._primary_key_name))], row))
AttributeError: 'result' object has no attribute 'id'

relevant models found at https://github.com/tyler274/Recruitment-App/blob/master/recruit_app/user/models.py

Rebuild index

What's a good way to manually rebuild the Whoosh index from an existing database after manually importing data into the database (outside of SQLAlchemy) or to ensure consistency of a database for example.

Thanks

Whoosh requirements

I believe that Whoosh 2.6.0 is on pypi by mistake so consider lowering your requirements for whoosh (==2.6.0 -> >= 2.5.7)

https://pypi.python.org/pypi/Whoosh redirects to 2.5.7

https://whoosh.readthedocs.org/en/latest/releases/2_0.html shows latest release 2.5

https://bitbucket.org/mchaput/whoosh/src latests tag is 2.5.7

and

> $ diff -ur Whoosh-2.6.0 Whoosh-2.5.7                                                                         
diff -ur Whoosh-2.6.0/PKG-INFO Whoosh-2.5.7/PKG-INFO
--- Whoosh-2.6.0/PKG-INFO        2014-02-14 16:20:46.000000000 +0100
+++ Whoosh-2.5.7/PKG-INFO        2014-02-14 16:24:44.000000000 +0100
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: Whoosh
-Version: 2.6.0
+Version: 2.5.7
Summary: Fast, pure-Python full text indexing, search, and spell checking library.
Home-page: http://bitbucket.org/mchaput/whoosh
Author: Matt Chaput
diff -ur Whoosh-2.6.0/src/whoosh/__init__.py Whoosh-2.5.7/src/whoosh/__init__.py
--- Whoosh-2.6.0/src/whoosh/__init__.py        2014-01-30 16:54:40.000000000 +0100
+++ Whoosh-2.5.7/src/whoosh/__init__.py        2014-02-14 16:23:52.000000000 +0100
@@ -25,7 +25,7 @@
# those of the authors and should not be interpreted as representing official
# policies, either expressed or implied, of Matt Chaput.

-__version__ = (2, 6, 0)
+__version__ = (2, 5, 7)


def versionstring(build=True, extra=True):
diff -ur Whoosh-2.6.0/src/Whoosh.egg-info/PKG-INFO Whoosh-2.5.7/src/Whoosh.egg-info/PKG-INFO
--- Whoosh-2.6.0/src/Whoosh.egg-info/PKG-INFO        2014-02-14 16:20:46.000000000 +0100
+++ Whoosh-2.5.7/src/Whoosh.egg-info/PKG-INFO        2014-02-14 16:24:44.000000000 +0100
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: Whoosh
-Version: 2.6.0
+Version: 2.5.7
Summary: Fast, pure-Python full text indexing, search, and spell checking library.
Home-page: http://bitbucket.org/mchaput/whoosh
Author: Matt Chaput
diff -ur Whoosh-2.6.0/tests/test_searching.py Whoosh-2.5.7/tests/test_searching.py
--- Whoosh-2.6.0/tests/test_searching.py        2014-01-30 18:06:36.000000000 +0100
+++ Whoosh-2.5.7/tests/test_searching.py        2014-02-14 16:22:16.000000000 +0100
@@ -1742,5 +1742,3 @@
        assert names == "delta foxtrot"


-
-

ExtDeprecationWarning

lib/python2.7/site-packages/flask/exthook.py:66: ExtDeprecationWarning: Importing flask.ext.sqlalchemy is deprecated, use flask_sqlalchemy instead.
  if fullname in sys.modules:

For those who are getting the following warning with the less up-to-date package pypi, you may use this:

pip uninstall flask-whooshalchemy
pip install git+git://github.com/rlam3/flask-whooshalchemy.git

But, I'd still highly suggest moving over to elasticsearch than using whoosh. Its just good to know. :) Cheers!

The version should be updated to 0.80 instead of 0.8

This package is great! We'd love to use this to help build a website for a research project.

We noticed one small issue. The latest version isn't installing from PyPI because the latest version number 0.8 (0, 8) is less than that of the previous release 0.56 (0, 56). To fix this, can you please update the version to 0.80 and please post the new version to PyPI?

Does flask-whooshalchemy support BufferedWriter?

Hi
For parallel database access it is necessary to handle database locks... how is that best done with this package? In whoosh BufferedWriter or AsyncWriter seem to do the job. Are these available in this package? Would it be possible to put an example usage in the readme or docs?
thanks

Deprecation warning

Hi,

I was receiving the following deprecation warning when using Flask-WhooshAlchemy:

ExtDeprecationWarning: Importing flask.ext.sqlalchemy is deprecated, use flask_sqlalchemy instead.

I was able to fix this by updating the line import flask.ext.sqlalchemy as flask_sqlalchemy in flask_whooshalchemy.py to import flask_sqlachemy, in order to accommodate the new extension import form.

python3 unicode

results = Post.query.whoosh_search('hi')

NameError Traceback (most recent call last)
in ()
----> 1 results = Post.query.whoosh_search('hi')
python3.3/site-packages/Flask_WhooshAlchemy-0.55-py3.3.egg/flask_whooshalchemy.py in whoosh_search(self, query, limit, fields, or_)
104 '''
105
--> 106 if not isinstance(query, unicode):
107 query = unicode(query)
108

NameError: global name 'unicode' is not defined

Requirements

Why don't you split requirements on two lists - one for testing, another for extension itself?

AttributeError when giving a column name in the model

There's my model:

class Document(BaseModel):
    __tablename__ = 'dcm_documents'
    __searchable__ = ['title', 'description', 'document']

    id = db.Column('dcm_id', db.Integer, primary_key=True)
    title = db.Column('dcm_title', db.String, unique=True)
    description = db.Column('dcm_description', db.String)

This will trigger an AttributeError because Flask-WhooshAlchemy tries to access the model attributes by their names in the table not in the model class:

AttributeError: 'Document' object has no attribute 'dcm_id'

Does Flask-WhooshAlchemy not support Chinese?

I have setup Flask-WhooshAlchemy in my project.

I try to use Flask-WhooshAlchemy to query database with some English character information. It is fine.

But I use Chinese to query database, I alway get a empty array.
Please help me.

It is my models:

class Post(db.Model):
    __tablename__ = 'posts'
    __searchable__ = ['title']  # these fields will be indexed by whoosh

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.Text)

It is what I do and what it show to me:

>>> p = Post(title='my third and last post 失意时行不行')
>>> db.session.add(p)
>>> db.session.commit()
>>> Post.query.whoosh_search('my').all()
[<app.models.Post object at 0x10629f630>]
>>> Post.query.whoosh_search('行不行').all()
[]

ModuleNotFoundError: No module named 'flask.ext'

I'm trying to build via docker-compose and this is my error:

> web_1  |   File "/logrr/logrr/models.py", line 6, in <module>
> web_1  |     import flask_whooshalchemy as whooshalchemy
> web_1  |   File "/usr/local/lib/python3.7/site-packages/flask_whooshalchemy.py", line 18, in <module>
> web_1  |     import flask.ext.sqlalchemy as flask_sqlalchemy
> web_1  | ModuleNotFoundError: No module named 'flask.ext'

In my requirements.txt I have flask_whooshalchemy and am using import flask_whooshalchemy as whooshalchemy in my models.py file.

Is the error my end or a bug? I can't really tell

Flask-SQLAlchemy version requirements 1.0

Hi.
Installing from pip3, with currently installed version of Flask-SQLAlchemy at v2.0:
Installation fails with:
"No distributions matching the version for Flask-SQLAlchemy==1.0 (from Flask-WhooshAlchemy==0.6)"

Do we have to downgrade from Flask-SQLAlchemy 2.0 to v 1.0?

output from: pip3 show Flask-SQLAlchemy
Name: Flask-SQLAlchemy
Version: 2.0
Location: /usr/local/lib/python3.4/dist-packages
Requires: Flask, SQLAlchemy

Thanks!

Can't install on windows

I'm trying to install this extension through pip on windows. But I'm getting this error:

Could not find a version that satisfies the requirement flask-whooshalchemy (f
rom versions: v0.52a, 0.3a.macosx-10.6-x86_64, 0.5a, 0.54a, 0.2a, 0.55a, 0.51a,
0.4a, 0.1a, 0.53a)
Cleaning up...
No distributions matching the version for flask-whooshalchemy
Storing complete log in C:\Users\Riyad\pip\pip.log

Finding popular searches?

How to obtain popular searches from a particular type of object. Specifically say for example the search is supposed to return a list of Car objects. What would the query look like to return the top searches?

x = Car.pure_whoosh('Aud*')

print x
<Top 1 Results for Or([Prefix('display_name', u'au'), Prefix('description', u'au'), Prefix('name', u'au')]) runtime=0.00333499908447>

x

x.collector             x.extend                x.has_exact_length      x.order                 x.searcher
x.copy                  x.facet_names           x.has_matched_terms     x.q                     x.top_n
x.docnum                x.fields                x.highlighter           x.query_terms           x.upgrade
x.docs                  x.filter                x.is_empty              x.runtime               x.upgrade_and_extend
x.docset                x.formatter             x.items                 x.score                 
x.estimated_length      x.fragmenter            x.key_terms             x.scored_length         
x.estimated_min_length  x.groups                x.matched_terms         x.scorer                

I cannot find how how to get the Car primary key or the top search results back or the car objects from x variable. Any suggestions would help

Strong requirements

At the moment requirements are strong, e.g. SQLAlchemy==0.7.7. Can we make them like SQLAlchemy>=0.7 or similar? It will make extension easier to combine with others.

Should support app.run(threaded=True)

whoosh may raise LockError on index.writer() if another thread is using the writer. Note that whoosh's BufferedWriter and AsyncWriter are both broken when used with a lot of threads. BufferedWriter doesn't hold it's internal lock for it's whole critical section for example. A simple lock for index.writer() would probably work for this.

Something to include in the documentation.

Primary column name from the table must match the attribute name of the object model. Otherwise they will run into the following primary key error. Is this correct?

Column name of table: userid
User object attribute for primary key: id

class User(db.Model):
id = Column('userid'...

def _after_flush(app, changes):
...
primary_field = values[0][1].pure_whoosh.primary_key_name 

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This line will see user.userid. When adding/saving objects into the database an attribute error will occur for whoosh.

Is there a way to specify the primary key or should migrate our tables to:

class User(db.Model):
id = Column('id'...

Thanks :)

always get where null in whoosh_search

I create Copmay Class like this:

from mysite import db
from .city import City
from .user import User

class Company(db.Model):
    __tablename__ = "Company"
    __searchable__ = ["name", "manager", "brief"]

    id        = db.Column(db.Integer, primary_key=True)
    #profile
    name      = db.Column(db.String(16), default="")    
    manager   = db.Column(db.String(8), default="")
    brief     = db.Column(db.String(140), default="")

    def __init__(self, *args, **kwargs):
        super(Company, self).__init__(*args, **kwargs)

import flask.ext.whooshalchemy as whooshalchemy
from mysite import app
whooshalchemy.whoosh_index(app, Company)

create company and then query with whoosh_search

c = Company.query.whoosh_search("example")
s = c.all()

I print c, but it show like "SELECT "Company".id AS "Company_id", ...... FROM "Company" WHERE null" and get s is [].

I think something was missing from my use of flask-whooshalchemy, althogh I followed the tutorial. please figure it out for me and thanks.

Cannot index multiple tables

I have a models.py file that has three models defined within. I am trying to index two of these. When I call whoosh_index on the two Classes, only the second one is indexed. It appears that the second whoosh_index call overwrites the first.

Here is the relevant section of code:

from interface import app, db
import flask.ext.whooshalchemy as whooshalchemy

class Client(db.Model):
    __tablename__ = 'client'
    __searchable__ = ['client_name']

    id = db.Column(db.Integer, primary_key=True)
    client_name = db.Column(db.String(120))

class Condo(db.Model):
    __tablename__ = 'condo'
    __searchable__ = ['condo_name']

    id = db.Column(db.Integer, primary_key=True)
    condo_name = db.Column(db.String(120))

whooshalchemy.whoosh_index(app, Condo)
whooshalchemy.whoosh_index(app, Client)

Here is the result:

>>> from interface.models import *
>>> Client.query.whoosh_search('*').first()
<Client: u'Miss Alize Harber'>
>>> Condo.query.whoosh_search('*').first()
>>> 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.