烧瓶的whoosh扩展/sqlalchemy
Flask-WhooshAlchemy-Redux的Python项目详细描述
欢迎来到烧瓶大炼金术!
==
==
[![构建状态](https://travis-ci.org/dhamaniasad/flask-whooshalchemy.svg?branch=master)“(https://travis-ci.org/dhamanisad/flask-whooshalchemy)[![图片](https://circleci.com/gh/dhamanisad/flask-whooshalchemy/tree/master.svg?style=shield)(https://circleci.com/gh/dhamaniasad/flask-whooshalchemy/tree/master)[![图像](https://img.shields.io/pypi/v/flask whooshalmy redux.svg)(https://pypi.python.org/pypi/flask whooshalmy redux)
flask whooshalmy是一个烧瓶扩展,它集成了[whoosh]的文本搜索功能(https://bitbucket.org/mchaput/whoosh/wiki/home),用于[烧瓶](http://flask.pocoo.org/)应用程序。
克隆https://github.com/dhmaniasad/flask-whooshalchemy.git
quickstart
-
>
quickstart
->>
>
``python
``` python
``导入flask.ext.whooshalchemy-whooshalchemy-whooshalchemy
` `设置whoosh索引的位置
app.config['whoosh‘whoosh‘whoosh’base']='path/to/whoosh/whoosh/base/base'/path/to/whoosh/base'//>类blogpost(db.model):
主键=真)
title=app.db.column(app.db.unicode)索引字段可以是字符串,
content=app.db.column(app.db.text)Unicode,也可以是text
created=db.column(db.datetime,default=datetime.datetime.utcnow)
whooshalchemy.whoosh\u索引(app,blogpost)
```
如果未设置,则默认为运行应用程序的目录中名为“whoosh”的目录。
2)将“可搜索”字段添加到指定要索引的字段(如“str”)的模型中。
让我们创建一篇文章:
``python
db.session.add(
blogpost(title=”My Cool Title',content=”这是第一篇文章')
);db.session.commit()
```
提交会话后,我们的新“blogpost”被编入索引。类似地,如果帖子被删除,它将从whoosh索引中删除。
“title”或“content”)是与查询匹配的文本。结果
根据相关性得分进行排序,最佳匹配
在迭代时首先出现。此调用的结果是sqlalchemy.orm.query.query对象(子类
),因此可以链接其他sql
操作。例如:
`` python
两天前=datetime.date.today()-datetime.timedelta(2)
最近的匹配项=blogpost.query.whoosh\u search('first').filter(
blogpost.created>;=两天前)
```
另一种(可能更慢)顺序是:
``python
recent\u matches=blogppost.query.query.filter(
blogppost.created>;=两天前)。whoosh搜索('first')
````
我们可以限制搜索结果:
``python
``python
``获取2个最佳结果:
results=blogppost.query.whoosh搜索('cool',limit=2)
```
`
默认情况下,搜索作为or
连接在所有索引字段上执行。例如,如果模型具有“title”和“content”指示
为“可搜索”,将对两个字段检查查询,
返回其标题或内容与查询内容匹配的任何实例。要指定要检查的特定字段,请使用所需字段填充
`fields`参数:
``python
results=blogpost.query.whoosh_search('cool',fields=('title',)
````
若要切换到“或”分组,请将“或”参数
设置为“true”:
``python
results=blogpost.query.whoosh\u search('cool',或_u=true)
```
==
==
[![构建状态](https://travis-ci.org/dhamaniasad/flask-whooshalchemy.svg?branch=master)“(https://travis-ci.org/dhamanisad/flask-whooshalchemy)[![图片](https://circleci.com/gh/dhamanisad/flask-whooshalchemy/tree/master.svg?style=shield)(https://circleci.com/gh/dhamaniasad/flask-whooshalchemy/tree/master)[![图像](https://img.shields.io/pypi/v/flask whooshalmy redux.svg)(https://pypi.python.org/pypi/flask whooshalmy redux)
flask whooshalmy是一个烧瓶扩展,它集成了[whoosh]的文本搜索功能(https://bitbucket.org/mchaput/whoosh/wiki/home),用于[烧瓶](http://flask.pocoo.org/)应用程序。
克隆https://github.com/dhmaniasad/flask-whooshalchemy.git
quickstart
-
>
quickstart
->>
>
``python
``` python
``导入flask.ext.whooshalchemy-whooshalchemy-whooshalchemy
` `设置whoosh索引的位置
app.config['whoosh‘whoosh‘whoosh’base']='path/to/whoosh/whoosh/base/base'/path/to/whoosh/base'//>类blogpost(db.model):
主键=真)
title=app.db.column(app.db.unicode)索引字段可以是字符串,
content=app.db.column(app.db.text)Unicode,也可以是text
created=db.column(db.datetime,default=datetime.datetime.utcnow)
whooshalchemy.whoosh\u索引(app,blogpost)
```
如果未设置,则默认为运行应用程序的目录中名为“whoosh”的目录。
2)将“可搜索”字段添加到指定要索引的字段(如“str”)的模型中。
让我们创建一篇文章:
``python
db.session.add(
blogpost(title=”My Cool Title',content=”这是第一篇文章')
);db.session.commit()
```
提交会话后,我们的新“blogpost”被编入索引。类似地,如果帖子被删除,它将从whoosh索引中删除。
“title”或“content”)是与查询匹配的文本。结果
根据相关性得分进行排序,最佳匹配
在迭代时首先出现。此调用的结果是sqlalchemy.orm.query.query对象(子类
),因此可以链接其他sql
操作。例如:
`` python
两天前=datetime.date.today()-datetime.timedelta(2)
最近的匹配项=blogpost.query.whoosh\u search('first').filter(
blogpost.created>;=两天前)
```
另一种(可能更慢)顺序是:
``python
recent\u matches=blogppost.query.query.filter(
blogppost.created>;=两天前)。whoosh搜索('first')
````
我们可以限制搜索结果:
``python
``python
``获取2个最佳结果:
results=blogppost.query.whoosh搜索('cool',limit=2)
```
`
默认情况下,搜索作为or
连接在所有索引字段上执行。例如,如果模型具有“title”和“content”指示
为“可搜索”,将对两个字段检查查询,
返回其标题或内容与查询内容匹配的任何实例。要指定要检查的特定字段,请使用所需字段填充
`fields`参数:
``python
results=blogpost.query.whoosh_search('cool',fields=('title',)
````
若要切换到“或”分组,请将“或”参数
设置为“true”:
``python
results=blogpost.query.whoosh\u search('cool',或_u=true)
```