本文整理汇总了Python中pysolr.Solr方法的典型用法代码示例。如果您正苦于以下问题:Python pysolr.Solr方法的具体用法?Python pysolr.Solr怎么用?Python pysolr.Solr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysolr
的用法示例。
在下文中一共展示了pysolr.Solr方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import pysolr [as 别名]
# 或者: from pysolr import Solr [as 别名]
def __init__(self, params):
self.collection_name = params["collection_name"]
self.solr_address = params["solr_address"]
self.solr = pysolr.Solr(
"{}/solr/{}".format(self.solr_address, self.collection_name),
always_commit=True,
timeout=100,
)
self.rows = params["rows"]
self.query_data = params["query_data"]
self.c = 0
self.query_arguments = {
"fl": "* score",
"rows": self.rows,
"defType": "edismax",
}
if params["boosting"] is not None:
self.query_arguments["bf"] = params["boosting"]
示例2: __init__
# 需要导入模块: import pysolr [as 别名]
# 或者: from pysolr import Solr [as 别名]
def __init__(self, params):
self.solr_address = params["solr_address"]
self.raw_solr_fields = params["raw_solr_fields"]
self.solr = pysolr.Solr(self.solr_address, always_commit=True, timeout=100)
self.rows = params["rows"]
self.query = params["query"]
self.keys = [k.strip() for k in params["keys"].split(",")]
self.c = 0
self.query_arguments = {
"fl": "* score",
"rows": self.rows,
"defType": "edismax",
}
if params["boosting"] is not None:
self.query_arguments["bf"] = params["boosting"]
示例3: search_associations_go
# 需要导入模块: import pysolr [as 别名]
# 或者: from pysolr import Solr [as 别名]
def search_associations_go(
subject_category=None,
object_category=None,
relation=None,
subject=None,
**kwargs):
"""
Perform association search using Monarch golr
"""
go_golr_url = "http://golr.geneontology.org/solr/"
go_solr = pysolr.Solr(go_golr_url, timeout=5)
go_solr.get_session().headers['User-Agent'] = get_user_agent(caller_name=__name__)
return search_associations(subject_category,
object_category,
relation,
subject,
solr=go_solr,
field_mapping=goassoc_fieldmap(),
**kwargs)
示例4: map_id
# 需要导入模块: import pysolr [as 别名]
# 或者: from pysolr import Solr [as 别名]
def map_id(self,id, prefix, closure_list):
"""
Map identifiers based on an equivalence closure list.
"""
prefixc = prefix + ':'
ids = [eid for eid in closure_list if eid.startswith(prefixc)]
# TODO: add option to fail if no mapping, or if >1 mapping
if len(ids) == 0:
# default to input
return id
return ids[0]
### This may quite possibly be a temporary code, but it looks a lot simpler than the above for more customizable Solr queries
示例5: test_clinical_modifiers
# 需要导入模块: import pysolr [as 别名]
# 或者: from pysolr import Solr [as 别名]
def test_clinical_modifiers():
"""
Test that clinical modifiers show up in the GolrAssociationQuery.exec() object
when present in the input solr document
"""
manager = GolrAssociationQuery()
manager.solr = pysolr.Solr(url="mock_solr", timeout=10)
input_fh = os.path.join(os.path.dirname(__file__),
'resources/solr/input/clinical-mod-doc.json')
input_docs = json.load(open(input_fh))
expected_fh = os.path.join(os.path.dirname(__file__),
'resources/solr/expected/clinical-mod.json')
expected_obj = json.load(open(expected_fh))
manager.solr.search = MagicMock(return_value=pysolr.Results(input_docs))
results = manager.exec()
assert json.dumps(expected_obj, sort_keys=True) == \
json.dumps(results,
default=lambda obj: getattr(obj, '__dict__', str(obj)),
sort_keys=True)
示例6: download_and_extract
# 需要导入模块: import pysolr [as 别名]
# 或者: from pysolr import Solr [as 别名]
def download_and_extract(resource_url):
"""
Download resource and extract metadata using Solr.
The extracted metadata is cleaned and returned.
"""
session = Session()
request = Request('GET', resource_url).prepare()
for plugin in PluginImplementations(IExtractorRequest):
request = plugin.extractor_before_request(request)
with tempfile.NamedTemporaryFile() as f:
r = session.send(request, stream=True)
r.raise_for_status()
for chunk in r.iter_content(chunk_size=1024):
f.write(chunk)
f.flush()
f.seek(0)
data = pysolr.Solr(config['solr_url']).extract(f, extractFormat='text')
data['metadata']['fulltext'] = data['contents']
return dict(clean_metadatum(*x) for x in data['metadata'].iteritems())
示例7: is_available
# 需要导入模块: import pysolr [as 别名]
# 或者: from pysolr import Solr [as 别名]
def is_available():
"""
Return true if we can successfully connect to Solr.
"""
try:
conn = make_connection()
conn.search(q="*:*", rows=1)
except Exception, e:
log.exception(e)
return False
示例8: make_connection
# 需要导入模块: import pysolr [as 别名]
# 或者: from pysolr import Solr [as 别名]
def make_connection(decode_dates=True):
solr_url, solr_user, solr_password = SolrSettings.get()
if decode_dates:
decoder = simplejson.JSONDecoder(object_hook=solr_datetime_decoder)
return pysolr.Solr(solr_url, decoder=decoder)
else:
return pysolr.Solr(solr_url)
示例9: _set_solr
# 需要导入模块: import pysolr [as 别名]
# 或者: from pysolr import Solr [as 别名]
def _set_solr(self, url, timeout=2):
self.solr = pysolr.Solr(url=url, timeout=timeout)
return self.solr
示例10: __init__
# 需要导入模块: import pysolr [as 别名]
# 或者: from pysolr import Solr [as 别名]
def __init__(self, config):
self.solrUrl = config.get("solr", "host")
self.solrCore = config.get("solr", "core")
self.logger = logging.getLogger('nexus')
with SOLR_CON_LOCK:
solrcon = getattr(thread_local, 'solrcon', None)
if solrcon is None:
solrcon = pysolr.Solr('http://%s/solr/%s' % (self.solrUrl, self.solrCore))
thread_local.solrcon = solrcon
self.solrcon = solrcon
示例11: make_solr_from_config
# 需要导入模块: import pysolr [as 别名]
# 或者: from pysolr import Solr [as 别名]
def make_solr_from_config(push_servers, query_server=None, **kwargs):
"""
Make a :class:`Solr <Solr>` instance from config defaults. Use
`**kwargs` to override any value
"""
solr_kwargs = dict(
commit=asbool(config.get('solr.commit', True)),
commitWithin=config.get('solr.commitWithin'),
timeout=int(config.get('solr.long_timeout', 60)),
)
solr_kwargs.update(kwargs)
return Solr(push_servers, query_server, **solr_kwargs)
示例12: __init__
# 需要导入模块: import pysolr [as 别名]
# 或者: from pysolr import Solr [as 别名]
def __init__(self, push_servers, query_server=None,
commit=True, commitWithin=None, **kw):
self.push_pool = [pysolr.Solr(s, **kw) for s in push_servers]
if query_server:
self.query_server = pysolr.Solr(query_server, **kw)
else:
self.query_server = self.push_pool[0]
self._commit = commit
self.commitWithin = commitWithin
示例13: index
# 需要导入模块: import pysolr [as 别名]
# 或者: from pysolr import Solr [as 别名]
def index(self):
"""send csv to Solr index"""
self.logger.info('Setting up Solr index...')
solr = Solr("http://{0}:{1}/solr/travel/".format(self.host, self.port), timeout=10000)
self.logger.info('Indexing %s...' % self.file)
act = [self.format(passage, cid=cid) for cid, passage in self.csv_generator()]
solr.add(act)
solr.optimize()
示例14: _merge_kwargs
# 需要导入模块: import pysolr [as 别名]
# 或者: from pysolr import Solr [as 别名]
def _merge_kwargs(additionalparams, **kwargs):
# Only Solr-specific kwargs are parsed
# And the special 'limit'
try:
additionalparams['limit'] = kwargs['limit']
except KeyError:
pass
try:
additionalparams['_route_'] = kwargs['_route_']
except KeyError:
pass
try:
additionalparams['rows'] = kwargs['rows']
except KeyError:
pass
try:
additionalparams['start'] = kwargs['start']
except KeyError:
pass
try:
kwfq = kwargs['fq'] if isinstance(kwargs['fq'], list) else list(kwargs['fq'])
except KeyError:
kwfq = []
try:
additionalparams['fq'].extend(kwfq)
except KeyError:
additionalparams['fq'] = kwfq
try:
kwfl = kwargs['fl'] if isinstance(kwargs['fl'], list) else [kwargs['fl']]
except KeyError:
kwfl = []
try:
additionalparams['fl'].extend(kwfl)
except KeyError:
additionalparams['fl'] = kwfl
try:
s = kwargs['sort'] if isinstance(kwargs['sort'], list) else [kwargs['sort']]
except KeyError:
s = None
try:
additionalparams['sort'].extend(s)
except KeyError:
if s is not None:
additionalparams['sort'] = s