def get_institution_people_datatables_rows(recid): """ Datatable rows to render people working in an institution. :param recid: id of the institution. :type recid: string """ query = LiteratureSearch().query("term", authors__affiliations__recid=recid) # FIXME: search_type=count is deprecated, but the whole function doesn't work anymore query = query.params(search_type="count") query.aggs.bucket("authors", "nested", path="authors")\ .bucket("affiliated", "filter", term={ "authors.affiliations.recid": recid })\ .bucket('byrecid', 'terms', field='authors.recid') records_from_es = query.execute().to_dict() # Extract all the record ids from the aggregation papers_per_author = records_from_es['aggregations']['authors'][ 'affiliated']['byrecid']['buckets'] recids = [int(paper['key']) for paper in papers_per_author] # Generate query to retrieve records from author index query = "" for i, recid in enumerate(recids): query += "recid:{}".format(recid) if i != len(recids) - 1: query += " OR " results = AuthorsSearch().query_from_iq(query).params( size=9999, _source=['control_number', 'name']).execute() recid_map = dict([(result.control_number, result.name) for result in results]) result = [] author_html_link = u"<a href='/authors/{recid}'>{name}</a>" for author in papers_per_author: row = [] try: row.append( author_html_link.format( recid=author['key'], name=recid_map[author['key']].preferred_name)) except Exception: # No preferred name, use value row.append( author_html_link.format(recid=author['key'], name=recid_map[author['key']].value)) row.append(author['doc_count']) result.append(row) return result
def get_experiment_publications(experiment_name): """ Get paper count for a given experiment. :param experiment_name: canonical name of the experiment. :type experiment_name: string """ query = {"term": {"accelerator_experiments.experiment": experiment_name}} search = LiteratureSearch().query(query) search = search.params(search_type="count") return search.execute().hits.total
def get_experiment_publications(experiment_name): """ Get paper count for a given experiment. :param experiment_name: canonical name of the experiment. :type experiment_name: string """ query = {"term": {"accelerator_experiments.experiment": experiment_name}} search = LiteratureSearch().query(query) # FIXME: search_type=count is deprecated, but the whole function doesn't work anymore search = search.params(search_type="count") return search.execute().hits.total
def get_experiment_publications(experiment_name): """ Get paper count for a given experiment. :param experiment_name: canonical name of the experiment. :type experiment_name: string """ query = { "term": {"accelerator_experiments.experiment": experiment_name} } search = LiteratureSearch().query(query) search = search.params(search_type="count") return search.execute().hits.total
def get_experiment_publications(experiment_name): """ Get paper count for a given experiment. :param experiment_name: canonical name of the experiment. :type experiment_name: string """ query = { "term": {"accelerator_experiments.experiment": experiment_name} } search = LiteratureSearch().query(query) # FIXME: search_type=count is deprecated, but the whole function doesn't work anymore search = search.params(search_type="count") return search.execute().hits.total
def get_institution_people_datatables_rows(recid): """ Datatable rows to render people working in an institution. :param recid: id of the institution. :type recid: string """ query = LiteratureSearch().query( "term", authors__affiliations__recid=recid ) # FIXME: search_type=count is deprecated, but the whole function doesn't work anymore query = query.params(search_type="count") query.aggs.bucket("authors", "nested", path="authors")\ .bucket("affiliated", "filter", term={ "authors.affiliations.recid": recid })\ .bucket('byrecid', 'terms', field='authors.recid') records_from_es = query.execute().to_dict() # Extract all the record ids from the aggregation papers_per_author = records_from_es[ 'aggregations' ]['authors']['affiliated']['byrecid']['buckets'] recids = [int(paper['key']) for paper in papers_per_author] # Generate query to retrieve records from author index query = "" for i, recid in enumerate(recids): query += "recid:{}".format(recid) if i != len(recids) - 1: query += " OR " results = AuthorsSearch().query_from_iq( query ).params( size=9999, _source=['control_number', 'name'] ).execute() recid_map = dict( [(result.control_number, result.name) for result in results] ) result = [] author_html_link = u"<a href='/authors/{recid}'>{name}</a>" for author in papers_per_author: row = [] try: row.append( author_html_link.format( recid=author['key'], name=recid_map[author['key']].preferred_name ) ) except Exception: # No preferred name, use value row.append( author_html_link.format( recid=author['key'], name=recid_map[author['key']].value ) ) row.append(author['doc_count']) result.append(row) return result