zoukankan      html  css  js  c++  java
  • flask——全文检索

    全文检索插件flask-msearch

    一、安装

    pip3 install flask-msearch

    二、修改表结构

    from flask_msearch import Search
    
    search = Search()  # 可以使用jieba中文分词
    search.init_app(app)
    
    # models.py
    class Post(db.Model):
        __tablename__ = 'post'
        __searchable__ = ['title', 'content']  # 检索字段

    三、添加检索的视图函数

    # views.py
    @app.route("/search")
    def w_search():
        keyword = request.args.get('keyword')
        results = search.whoosh_search(Post,query=keyword,fields=['title'],limit=20)  # 返回字段+最大返回数量
        return ''
    

    四、创建更新删除索引

    # 创建
    search.create_index()
    # 更新
    search.create_index(update=True)
    # 删除
    search.create_index(delete=True)
    # 为执行表添加索引
    search.create_index(Model)

    五、自定义分词系统

    from jieba.analyse import ChineseAnalyzer
    
    search = Search(analyzer=ChineseAnalyzer())
    

    六、配置文件  

    WHOOSH_BASE = 'whoosh_index'
    WHOOSH_ENABLE = True

    参考于:这里

  • 相关阅读:
    poj 2996 模拟
    poj 2965 BFS
    poj 1068 模拟
    poj 3295 前缀表达式求值
    常用的十七大学术搜索引擎
    Why,Unix or Linux ?
    匈牙利命名法
    微调控件(CSpinButtonCtrl)
    美国免费邮箱
    ASP常用的代码
  • 原文地址:https://www.cnblogs.com/x54256/p/8404181.html
Copyright © 2011-2022 走看看