def get_starting_id(): solr = Solr('http://localhost:8983/solr/BD2K') result = solr.select(('q', '*:*'), ('rows', str(to_fetch)), ('wt', 'json'), ('fl', 'id, publicationDOI')) for doc in result.docs: if 'id' in doc and 'publicationDOI' in doc: id_doi[doc['publicationDOI']] = doc['id'] return len(result.docs) + 1
def main(json_data): global solr solr = Solr('http://localhost:8983/solr/BD2K') if not json_data: # Update the usual stuff for all documents in the database result = solr.select( ('q', '*:*'), ('rows', str(to_fetch)), ('wt', 'json'), ('fl', 'id,publicationDOI,lastUpdatedMilliseconds,repo,toolName')) get_documents(result) for doc in documents: if doc.doiNumber is not None and doc.shouldUpdate: doc.citations = get_citations(doc.doiNumber) print "Unformatted DOI is " + doc.uDoi print "Extracted DOI is " + doc.doiNumber print "Citations found are " + doc.citations if doc.repo is not None: update_metadata(doc) else: data = '{"id":"' + str( doc.id) + '", "citations":{"set":' + str( doc.citations ) + '},"lastUpdatedMilliseconds":{"set":' + str( millis) + '}}' push_to_solr(json.loads(data)) else: print "Json data is " print json_data json_data = json.loads(json_data) result = solr.select(('q', 'id:' + json_data['id']), ('wt', 'json')) doc = result.docs[0] solr_data = dict() for key, value in doc.iteritems(): if 'suggest' in key: # These fields are automatically set based on others continue solr_data[key] = value for key, value in json_data.iteritems(): if key == 'id': continue solr_data[key] = {"set": value} push_to_solr(solr_data) # return Success to flask server return "Success"
def setUp(self): self.solr = Solr('http://localhost:8080/solr/collection1') self.solr.update( { 'id': str(uuid4()), 'name': 'Mona Lisa', 'type': 'painting' }, { 'id': str(uuid4()), 'name': 'Mona Lisa', 'type': 'painting' }, { 'id': str(uuid4()), 'name': 'Mona Lisa', 'type': 'painting' }, { 'id': str(uuid4()), 'name': 'Mona Lisa', 'type': 'painting' }, { 'id': str(uuid4()), 'name': 'American Gothic', 'type': 'painting' }, { 'id': str(uuid4()), 'name': 'American Gothic', 'type': 'painting' }, { 'id': str(uuid4()), 'name': 'Starry Night', 'type': 'painting' }, { 'id': str(uuid4()), 'name': 'The Scream', 'type': 'painting' }).commit()
def setUp(self): self.solr = Solr('http://localhost:8080/solr/collection1') self.solr.update({'id': 1}, {'id': 2}, {'id': 3}, {'id': 4}).commit()