使用python+whoosh实现全文检索-创新互联

whoosh的官方介绍:http://whoosh.readthedocs.io/en/latest/quickstart.html

成都创新互联公司是一家专注于做网站、成都网站设计与策划设计,厦门网站建设哪家好?成都创新互联公司做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:厦门等地区。厦门做网站价格咨询:18982081108

因为做的是中文的全文检索需要导入jieba工具包以及whoosh工具包

直接上代码吧

from whoosh.qparser import QueryParser 
from whoosh.index import create_in 
from whoosh.index import open_dir 
from whoosh.fields import * 
from jieba.analyse import ChineseAnalyzer 
from get_comment import SQL 
from whoosh.sorting import FieldFacet 
 
analyser = ChineseAnalyzer()  #导入中文分词工具 
schema = Schema(phone_name=TEXT(stored=True, analyzer=analyser), price=NUMERIC(stored=True), 
          phoneid=ID(stored=True))# 创建索引结构 
ix = create_in("path", schema=schema, indexname='indexname') #path 为索引创建的地址,indexname为索引名称 
writer = ix.writer() 
writer.add_document(phone_name='name',price ="price",phoneid ="id") # 此处为添加的内容  
print("建立完成一个索引") 
writer.commit() 
# 以上为建立索引的过程 
new_list = [] 
index = open_dir("indexpath", indexname='comment') #读取建立好的索引 
with index.searcher() as searcher: 
  parser = QueryParser("要搜索的项目,比如“phone_name", index.schema) 
  myquery = parser.parse("搜索的关键字") 
  facet = FieldFacet("price", reverse=True) #按序排列搜索结果 
  results = searcher.search(myquery, limit=None, sortedby=facet) #limit为搜索结果的限制,默认为10,详见博客开头的官方文档 
  for result1 in results: 
    print(dict(result1)) 
    new_list.append(dict(result1))

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

当前题目:使用python+whoosh实现全文检索-创新互联
本文来源:https://www.cdcxhl.com/article38/dhphsp.html

成都网站建设公司_创新互联,为您提供虚拟主机网站建设微信小程序Google搜索引擎优化品牌网站制作

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都app开发公司