Esempio n. 1
0
def hepnames():
    """View for authors collection landing page."""
    number_of_records = AuthorsSearch().count()

    return render_template(
        'inspirehep_theme/search/collection_authors.html',
        collection='authors',
        number_of_records=number_of_records,
    )
Esempio n. 2
0
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
Esempio n. 3
0
def get_author_collection_records_from_valid_authors(authors_refs):
    """ Queries elasticsearch for the author-records of the given authors references.
    """
    es_query = {
        "bool": {
            "must": [
                {"terms": {
                    "self.$ref": authors_refs
                }}, {"match": {
                    "ids.type": "ORCID"
                }}
            ]
        }
    }
    authors = AuthorsSearch().filter(es_query).execute().hits

    return authors
Esempio n. 4
0
def experiment_people_from_es(experiment_name):
    """Query ES for conferences in the same series."""
    query = 'experiments.name:"{}"'.format(experiment_name)
    return AuthorsSearch().query_from_iq(
        query
    ).execute().hits