def neessearch(offset=0, limit=100, query_string='', limit_fields=True, *args): nees_pi_query = Q({ "nested": { "path": "pis", "ignore_unmapped": True, "query": { "query_string": { "query": query_string, "fields": ["pis.firstName", "pis.lastName"], "lenient": True } } } }) nees_query_string_query = Q('query_string', query=query_string, default_operator='and') pub_query = IndexedPublicationLegacy.search().filter( nees_pi_query | nees_query_string_query) pub_query = pub_query.extra(from_=offset, size=limit) if limit_fields: pub_query = pub_query.source( includes=['project', 'pis', 'title', 'startDate', 'path']) pub_query = pub_query.sort( {'created': { 'order': 'desc', 'unmapped_type': 'long' }}) res = pub_query.execute() hits = list(map(lambda h: h.to_dict(), res.hits)) return {'listing': hits}
def reindex_nees_projects(*args): try: srch = IndexedPublicationLegacy.search() res = srch.execute() if res.hits.total > 0: return search = PublicProjectIndexed.search() res = search.execute() esrch = PublicExperimentIndexed.search() for pub in search.scan(): pub_dict = pub.to_dict() pub_dict['path'] = pub_dict['projectPath'] pub_dict.pop('projectPath', '') pub_dict['system'] = pub_dict['systemId'] pub_dict.pop('systemId', '') pub_doc = IndexedPublicationLegacy(**pub_dict) esrch.query = Q('bool', must=Q({'term': { 'project._exact': pub.name }})) esrch.execute() experiments = [] for exp in esrch.scan(): exp_dict = exp.to_dict() exp_dict['path'] = exp_dict['experimentPath'] exp_dict.pop('systemId') exp_dict.pop('experimentPath', '') exp_dict.pop('project') experiments.append(exp_dict) pub_doc.experiments = experiments pub_doc.save() except TransportError as exc: if exc.status_code != 404: raise
def neeslisting(offset=0, limit=100, limit_fields=True, *args): pub_query = IndexedPublicationLegacy.search() pub_query = pub_query.extra(from_=offset, size=limit) if limit_fields: pub_query = pub_query.source( includes=['project', 'pis', 'title', 'startDate', 'path']) pub_query = pub_query.sort( {'created': { 'order': 'desc', 'unmapped_type': 'long' }}) res = pub_query.execute() hits = list(map(lambda h: h.to_dict(), res.hits)) return {'listing': hits}
def neesdescription(project_id, *args): pub_query = IndexedPublicationLegacy.search()\ .filter(Q({'term': {'project._exact': project_id}}))\ .source(includes=['description']) desc = next(hit.description for hit in pub_query.execute().hits) return {'description': desc}