def parseRetRenewal(dbRenewal): if len(dbRenewal.registrations) == 0: return [MultiResponse.parseRenewal(dbRenewal)] registrations = [] for reg in dbRenewal.registrations: registrations.append(MultiResponse.parseEntry(reg.cce)) return registrations
def regQuery(regnum): page, perPage = MultiResponse.parsePaging(request.args) sourceReturn = request.args.get('source', False) matchingDocs = elastic.query_regnum(regnum, page=page, perPage=perPage) regResponse = MultiResponse('number', matchingDocs.hits.total, request.base_url, regnum, page, perPage) qManager = QueryManager(db.session) for entry in matchingDocs: dbEntry = qManager.registrationQuery(entry.uuid) regResponse.addResult( MultiResponse.parseEntry(dbEntry, xml=sourceReturn)) regResponse.createDataBlock() return jsonify(regResponse.createResponse(200))
def renQuery(rennum): page, perPage = MultiResponse.parsePaging(request.args) sourceReturn = request.args.get('source', False) matchingDocs = elastic.query_rennum(rennum, page=page, perPage=perPage) renResponse = MultiResponse('number', matchingDocs.hits.total, request.base_url, rennum, page, perPage) qManager = QueryManager(db.session) for entry in matchingDocs: dbRenewal = qManager.renewalQuery(entry.uuid) renResponse.extendResults(parseRetRenewal(dbRenewal)) renResponse.createDataBlock() return jsonify(renResponse.createResponse(200))
def fullTextQuery(): queryText = request.args.get('query', '') sourceReturn = request.args.get('source', False) page, perPage = MultiResponse.parsePaging(request.args) matchingDocs = elastic.query_fulltext(queryText, page=page, perPage=perPage) textResponse = MultiResponse('text', matchingDocs.hits.total, request.base_url, queryText, page, perPage) qManager = QueryManager(db.session) for entry in matchingDocs: if entry.meta.index == 'cce': dbEntry = qManager.registrationQuery(entry.uuid) textResponse.addResult( MultiResponse.parseEntry(dbEntry, xml=sourceReturn)) else: try: dbRenewal = qManager.renewalQuery(entry.uuid) textResponse.addResult( MultiResponse.parseRenewal(dbRenewal, source=sourceReturn)) except NoResultFound: dbRenewal = qManager.orphanRenewalQuery(entry.uuid) textResponse.addResult( MultiResponse.parseRenewal(dbRenewal, source=sourceReturn)) textResponse.createDataBlock() return jsonify(textResponse.createResponse(200))
def multiQuery(): title = request.args.get('title', '') authors = request.args.get('authors', '') publishers = request.args.get('publishers', '') sourceReturn = request.args.get('source', False) page, perPage = MultiResponse.parsePaging(request.args) queries = {} if title != "*" and title != "": queries["title"] = title if authors != "*" and authors != "": queries["authors"] = authors if publishers != "*" and publishers != "": queries["publishers"] = publishers matchingDocs = elastic.query_multifields(queries, page=page, perPage=perPage) textResponse = MultiResponse('text', matchingDocs.hits.total, request.base_url, queries, page, perPage) qManager = QueryManager(db.session) for entry in matchingDocs: if entry.meta.index == 'cce': dbEntry = qManager.registrationQuery(entry.uuid) textResponse.addResult( MultiResponse.parseEntry(dbEntry, xml=sourceReturn)) else: try: dbRenewal = qManager.renewalQuery(entry.uuid) textResponse.addResult( MultiResponse.parseRenewal(dbRenewal, source=sourceReturn)) except NoResultFound: dbRenewal = qManager.orphanRenewalQuery(entry.uuid) textResponse.addResult( MultiResponse.parseRenewal(dbRenewal, source=sourceReturn)) textResponse.createDataBlock() return jsonify(textResponse.createResponse(200))