Pysolr Solr 轻量的 Python 应用开源项目

我要开发同款
匿名用户2016年09月07日
101阅读
开发技术Python
所属分类程序开发、搜索引擎
授权协议BSD

作品详情

Pysolr,是基于Python的ApacheSolr轻量级封装。它提供了服务器查询并返回基于查询的结果接口。

特性:

基本功能,选择、更新和删除

索引优化

超时支持

使用环境:

Python2.7-3.5

Requests2.0+

Optional-simplejson

Optional-kazooforSolrCloudmode

示例代码:

# If on Python 2.Xfrom __future__ import print_functionimport pysolr# Setup a Solr instance. The timeout is optional.solr = pysolr.Solr('https://localhost:8983/solr/', timeout=10)# How you'd index data.solr.add([    {        "id": "doc_1",        "title": "A test document",    },    {        "id": "doc_2",        "title": "The Banana: Tasty or Dangerous?",    },])# Later, searching is easy. In the simple case, just a plain Lucene-style# query is fine.results = solr.search('bananas')# The ``Results`` object stores total results found, by default the top# ten most relevant results and any additional data like# facets/highlighting/spelling/etc.print("Saw {0} result(s).".format(len(results)))# Just loop over it to access the results.for result in results:    print("The title is '{0}'.".format(result['title']))# For a more advanced query, say involving highlighting, you can pass# additional options to Solr.results = solr.search('bananas', **{    'hl': 'true',    'hl.fragsize': 10,})# You can also perform More Like This searches, if your Solr is configured# correctly.similar = solr.more_like_this(q='id:doc_2', mltfl='text')# Finally, you can delete either individual documents...solr.delete(id='doc_1')# ...or all documents.solr.delete(q='*:*')# For SolrCloud mode, initialize your Solr like this:zookeeper = pysolr.Zookeeper("zkhost1:2181,zkhost2:2181,zkhost3:2181")solr = pysolr.SolrCloud(zookeeper, "collection1")
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论