本文整理汇总了Python中solr.SolrConnection.escapeKey方法的典型用法代码示例。如果您正苦于以下问题:Python SolrConnection.escapeKey方法的具体用法?Python SolrConnection.escapeKey怎么用?Python SolrConnection.escapeKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类solr.SolrConnection
的用法示例。
在下文中一共展示了SolrConnection.escapeKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _send_update
# 需要导入模块: from solr import SolrConnection [as 别名]
# 或者: from solr.SolrConnection import escapeKey [as 别名]
def _send_update(self, *args, **kwargs):
"""Send an update request to Solr.
Solr commits are made only on deletion.
Takes a single argument: the AMQP message that was received.
"""
try:
log.info("Processing update request")
msg = args[0]
updates = json.loads(msg.body)
solr = SolrConnection(self.solr_uri)
if updates["type"] == "updated":
add = ET.Element("add")
for update in updates["data"]:
doc = ET.SubElement(add, "doc")
for fields in update:
# There should only be one pair
# FIXME: move to a dictionary structure
for k, v in fields.items():
SolrUpdater.xml_field(doc, solr.escapeKey(k), solr.escapeVal(v))
log.debug("Sending update to Solr: " + ET.tostring(add))
solr.doUpdateXML(ET.tostring(add))
elif updates["type"] == "deleted":
for id in updates["data"]:
log.debug("Deleting document with id '%s'" % id)
solr.delete(id)
solr.commit()
elif updates["type"] == "deleted_db":
db_name = updates["data"]
log.info("Deleting indexes for database '%s'" % db_name)
solr.deleteByQuery("_db:%s" % db_name)
solr.commit()
else:
log.warning("Unrecognized update type: '%s'" % updates["type"])
except Exception:
log.exception("Unexpected exception")