Example #1
0
def test_hep_earliest_date_aggregation_and_filter(inspire_app, override_config):
    config = {
        "RECORDS_REST_FACETS": {
            "records-hep": {
                "filters": hep_filters(),
                "aggs": {**hep_earliest_date_aggregation(1)},
            }
        }
    }

    with override_config(**config):
        data = {"preprint_date": "2019-06-28"}
        expected_record = create_record("lit", data)
        data = {"preprint_date": "2015-06-28"}
        create_record("lit", data)

        with inspire_app.test_client() as client:
            response = client.get("/literature/facets").json
        earliest_date_aggregation = {
            "meta": {"title": "Papers per year", "type": "range", "order": 1},
            "buckets": [
                {"doc_count": 1, "key": 1420070400000, "key_as_string": "2015"},
                {"doc_count": 1, "key": 1546300800000, "key_as_string": "2019"},
            ],
        }
        assert response["aggregations"]["earliest_date"] == earliest_date_aggregation

        with inspire_app.test_client() as client:
            response = client.get("/literature?earliest_date=2018--2019").json
        assert len(response["hits"]["hits"]) == 1
        assert (
            response["hits"]["hits"][0]["metadata"]["control_number"]
            == expected_record["control_number"]
        )
def test_hep_experiment_papers_cataloger_facets(inspire_app):
    with current_app.test_request_context():
        expected_filters = {
            "author",
            "author_count",
            "doc_type",
            "earliest_date",
            "citation_count",
            "citation_count_without_self_citations",
            "collaboration",
            "refereed",
            "citeable",
            "collection",
            "subject",
            "arxiv_categories",
            "self_affiliations",
            "self_author_names",
            "rpp",
            "affiliations",
            "self_curated_relation",
        }
        expected_aggregations = {
            **hep_earliest_date_aggregation(order=1),
            **hep_author_count_aggregation(order=2),
            **hep_doc_type_aggregation(order=3),
            **hep_subject_aggregation(order=4),
            **hep_collection_aggregation(order=5),
        }

        filters = current_app.config["CATALOGER_RECORDS_REST_FACETS"][
            "hep-experiment-papers"]()["filters"].keys()
        aggregations = current_app.config["CATALOGER_RECORDS_REST_FACETS"][
            "hep-experiment-papers"]()["aggs"]
        assert filters == expected_filters
        assert aggregations == expected_aggregations
Example #3
0
def hep_institution_papers(order=None):
    if order is None:
        order = count(start=1)
    return {
        "filters": hep_filters(),
        "aggs": {
            **hep_earliest_date_aggregation(order=next(order)),
            **hep_doc_type_aggregation(order=next(order)),
        },
    }
def hep_experiment_papers(order=None):
    if order is None:
        order = count(start=1)
    return {
        "filters": hep_filters(),
        "aggs": {
            **hep_earliest_date_aggregation(order=next(order)),
            **hep_author_count_aggregation(order=next(order)),
            **hep_doc_type_aggregation(order=next(order)),
            **hep_subject_aggregation(order=next(order)),
        },
    }
Example #5
0
def test_hep_author_publications_cataloger_facets(inspire_app):
    author = "1111_Jones"
    author_recid = "1111"
    with current_app.test_request_context(f"?author={author}"):
        expected_filters = {
            "author",
            "author_count",
            "doc_type",
            "earliest_date",
            "citation_count",
            "citation_count_without_self_citations",
            "collaboration",
            "refereed",
            "citeable",
            "collection",
            "curation_collection",
            "subject",
            "arxiv_categories",
            "self_affiliations",
            "affiliations",
            "self_author_names",
            "self_curated_relation",
            "rpp",
            "experiments",
        }
        expected_aggregations = {
            **hep_earliest_date_aggregation(order=1, title="Date of paper"),
            **hep_author_count_aggregation(order=2),
            **hep_rpp(order=3),
            **hep_doc_type_aggregation(order=4),
            **hep_author_aggregation(order=5,
                                     author=author,
                                     title="Collaborators"),
            **hep_collaboration_aggregation(order=6),
            **hep_self_author_affiliations_aggregation(order=7,
                                                       author_recid=author_recid),
            **hep_subject_aggregation(order=8),
            **hep_arxiv_categories_aggregation(order=9),
            **hep_self_author_names_aggregation(order=10,
                                                author_recid=author_recid),
            **hep_collection_aggregation(order=11),
            **hep_self_author_claimed_papers_aggregation(order=12,
                                                         author_recid=author_recid),
            **hep_experiments_aggregation(order=13),
        }

        filters = set(current_app.config["CATALOGER_RECORDS_REST_FACETS"]
                      ["hep-author-publication"]()["filters"].keys())
        aggregations = current_app.config["CATALOGER_RECORDS_REST_FACETS"][
            "hep-author-publication"]()["aggs"]
        assert filters == expected_filters
        assert aggregations == expected_aggregations
def hep_author_citations(order=None):
    if order is None:
        order = count(start=1)
    return {
        "filters": hep_filters(),
        "aggs": {
            **hep_earliest_date_aggregation(order=next(order),
                                            title="Date of citing paper"),
            **hep_author_count_aggregation(order=next(order)),
            **hep_rpp(order=next(order)),
            **hep_doc_type_aggregation(order=next(order)),
            **hep_author_aggregation(order=next(order)),
            **hep_collaboration_aggregation(order=next(order)),
            **hep_author_affiliations_aggregation(order=next(order)),
        },
    }
def records_hep(order=None):
    if order is None:
        order = count(start=1)
    return {
        "filters": hep_filters(),
        "aggs": {
            **hep_earliest_date_aggregation(order=next(order),
                                            title="Date of paper"),
            **hep_author_count_aggregation(order=next(order)),
            **hep_rpp(order=next(order)),
            **hep_doc_type_aggregation(order=next(order)),
            **hep_author_aggregation(order=next(order)),
            **hep_subject_aggregation(order=next(order)),
            **hep_arxiv_categories_aggregation(order=next(order)),
            **hep_collaboration_aggregation(order=next(order)),
        },
    }
Example #8
0
def hep_author_publications(order=None):
    if order is None:
        order = count(start=1)
    author = request.values.get("author", "", type=str)
    author_recid = author.split("_")[0]
    return {
        "filters": hep_filters(),
        "aggs": {
            **hep_earliest_date_aggregation(order=next(order)),
            **hep_author_count_aggregation(order=next(order)),
            **hep_rpp(order=next(order)),
            **hep_doc_type_aggregation(order=next(order)),
            **hep_author_aggregation(order=next(order),
                                     author=author,
                                     title="Collaborators"),
            **hep_collaboration_aggregation(order=next(order)),
            **hep_self_author_affiliations_aggregation(order=next(order),
                                                       author_recid=author_recid),
        },
    }
Example #9
0
def test_records_hep_facets(inspire_app):
    with current_app.test_request_context():
        expected_filters = {
            "author",
            "author_count",
            "doc_type",
            "earliest_date",
            "citation_count",
            "citation_count_without_self_citations",
            "collaboration",
            "refereed",
            "citeable",
            "collection",
            "curation_collection",
            "subject",
            "arxiv_categories",
            "self_affiliations",
            "affiliations",
            "self_author_names",
            "rpp",
            "self_curated_relation",
            "experiments",
        }
        expected_aggregations = {
            **hep_earliest_date_aggregation(order=1, title="Date of paper"),
            **hep_author_count_aggregation(order=2),
            **hep_rpp(order=3),
            **hep_doc_type_aggregation(order=4),
            **hep_author_aggregation(order=5),
            **hep_subject_aggregation(order=6),
            **hep_arxiv_categories_aggregation(order=7),
            **hep_collaboration_aggregation(order=8),
        }
        filters = current_app.config["RECORDS_REST_FACETS"]["records-hep"](
        )["filters"].keys()
        aggregations = current_app.config["RECORDS_REST_FACETS"][
            "records-hep"]()["aggs"]
        assert filters == expected_filters
        assert aggregations == expected_aggregations