コード例 #1
0
ファイル: views.py プロジェクト: reve99/inspire-next
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
コード例 #2
0
ファイル: views.py プロジェクト: bavaria95/inspire-next
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
コード例 #3
0
ファイル: views.py プロジェクト: reve99/inspire-next
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
コード例 #4
0
ファイル: views.py プロジェクト: fschwenn/inspire-next
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
コード例 #5
0
ファイル: views.py プロジェクト: harunurhan/inspire-next
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
コード例 #6
0
ファイル: views.py プロジェクト: harunurhan/inspire-next
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