我有一个奇怪的问题
我从烧瓶开始.哇哦炼金术。我知道Whoosh只对新索引的项工作,而不对预先存在的项工作,所以我将所有东西重新导入到我的数据库中。这不起作用,所以我从堆栈溢出问题上运行了gist代码:如何手工导入烧瓶-炼金术指数数据?。
我对他的代码做了一个小小的改动。由于model.query对我不起作用(我认为这种类型的查询是不可取的,但这只是猜测),所以我连接了一个引擎,并以这种方式调用它。在这两种情况下,它似乎都奏效了,我生成了一个健康大小的呜什指数。
我已经完成了将其放置在schema.py文件底部的步骤(有些人称之为models.py):
whooshalchemy.whoosh_index(app, Restaurant)我在类定义中列出了可搜索的项。我还发现这个链接描述了开发人员所做的“查询”重载方面的一些缺点:http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvi-debugging-testing-and-profiling/page/3。他写了一些修复bug的代码-- whooshalchemy.py--我也试过安装它,但是当它没有帮助的时候,我就恢复了。
这是回溯:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/<omitted>/App/api/app/views.py", line 96, in instant
result = q.whoosh_search(query).all()
AttributeError: 'Query' object has no attribute 'whoosh_search'我试着用烧瓶--哇,它看起来非常非常相似,而且我也收到了同样的错误。
下面是有问题的代码(切换到烧瓶-呜呜,但我留下了烧瓶-乌什炼金术代码注释掉):
views.py:
@app.route('/search')
def search():
query = request.args.get('query', '', type=str)
q = session.query()
result = q.whooshee_search(query).all()
#result = q.whoosh_search(query).all()
return Response(json.dumps(result), mimetype='text/json')schema.py:
from app import app
from flask.ext.whooshee import Whooshee
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, Float, String, Date
# import flask.ext.whooshalchemy as whooshalchemy
from settings import WHOOSH_BASE
Base = declarative_base()
whooshee = Whooshee(app)
@whooshee.register_model('db_name', 'db_addr', 'google_name', 'yelp_name',
'yelp_address')
class Restaurant(Base):
__tablename__ = 'restaurant_indexed'
#__searchable__ = ['db_name', 'db_addr',
# 'google_name', 'yelp_name', 'yelp_address']
restaurant_id = Column(Integer, primary_key=True)
google_id = Column(String)
db_name = Column(String)
db_addr = Column(String)
# whooshalchemy.whoosh_index(app, Restaurant)我注释掉了以前在该代码的版本中使用的行。
我的init.py如下所示:
from flask import Flask
app = Flask(__name__)
app.config['WHOOSH_BASE'] = '/home/me/path/to/whoosh/dir'
from app import views发布于 2016-09-06 22:46:53
我得到了同样的错误,然后当我重新读取文档时,我注意到创建一个post是实现whoosh_search的步骤之一:
例如,表需要通过whoosh (文档)进行索引:
Let’s create a post:
db.session.add(
BlogPost(title='My cool title', content='This is the first post.')
); db.session.commit()在提交会话之后,我们的新BlogPost将被索引。同样,如果删除该帖子,则将其从Whoosh索引中删除。
有办法将现有的db.table添加到whoosh索引中吗?一种解决方案是重新插入所有行;这个帖子似乎给出了方向,但也声称没有维护整个炼金术。
发布于 2014-07-12 21:24:51
我一直只是使用,而不是直接使用SQLAlchemy。
使用Flask-SQLAlchemy,我将查询Restaurant表,如下所示:
Restaurant.query.whoosh_search('foo')从SQLAlchemy文档上看,您似乎需要这样做:
q = session.query(Restaurant)
result = q.whooshee_search(query).all()https://stackoverflow.com/questions/24552415
复制相似问题