Rev 20592 | Blame | Compare with Previous | Last modification | View Log | RSS feed
import pymongoimport osimport jsonfrom xml.etree.ElementTree import parse, Elementfrom xml import etreecon=NonefilePath="/var/lib/tomcat6/webapps/export/javascripts/autosuggesthotspot.json"solrPath = "/var/lib/tomcat6/webapps/export/solr/"def get_mongo_connection(host='localhost', port=27017):global conif con is None:print "Establishing connection %s host and port %d" %(host,port)try:con = pymongo.MongoClient(host, port)except Exception, e:print ereturn Nonereturn condef generate_auto_suggest():PATH = os.path.expanduser(filePath)if os.path.isfile(PATH):try:os.remove(os.path.expanduser(filePath))except OSError:passoutput = open(filePath, 'ab+')all = get_mongo_connection().Hotspot.HotspotEntity.find()autoSuggestMap = {}for a in all:autoSuggestMap[a['title']] = [a['title']]json.dump(autoSuggestMap, output)def alter_solr_xml():all = get_mongo_connection().Hotspot.HotspotEntity.find()for a in all:fileName = str(a['_id'])+"_irdata_solr.xml"doc = parse(solrPath+fileName)root = doc.find('doc')co = Element("field", name="P_120537")co.text="Yes"root.append(co)doc.write(solrPath+fileName)def main():generate_auto_suggest()alter_solr_xml()if __name__ == '__main__':main()