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

    with override_config(**config):
        data = {"titles": [{"title": "This is my title"}]}
        expected_record = create_record("lit", data)
        data = {"titles": [{"title": "RPP"}]}
        create_record("lit", data)
        with inspire_app.test_client() as client:
            response = client.get("/literature/facets").json
        expected_aggregation = {
            "meta": {
                "title": "Exclude RPP",
                "type": "checkbox",
                "order": 1,
                "is_filter_aggregation": True,
            },
            "buckets": [{"doc_count": 1, "key": "Exclude Review of Particle Physics"}],
        }
        assert response["aggregations"]["rpp"] == expected_aggregation

        with inspire_app.test_client() as client:
            response = client.get(
                "/literature?rpp=Exclude%20Review%20of%20Particle%20Physics"
            ).json
        assert len(response["hits"]["hits"]) == 1
        assert (
            response["hits"]["hits"][0]["metadata"]["control_number"]
            == expected_record["control_number"]
        )
Example #2
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 #5
0
def test_hep_author_citations_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",
            "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 citing paper"),
            **hep_author_count_aggregation(order=2),
            **hep_rpp(order=3),
            **hep_doc_type_aggregation(order=4),
            **hep_author_aggregation(order=5),
            **hep_collaboration_aggregation(order=6),
            **hep_author_affiliations_aggregation(order=7),
            **hep_subject_aggregation(order=8),
            **hep_arxiv_categories_aggregation(order=9),
            **hep_collection_aggregation(order=10),
        }

        filters = current_app.config["CATALOGER_RECORDS_REST_FACETS"][
            "hep-author-citations"]()["filters"].keys()
        aggregations = current_app.config["CATALOGER_RECORDS_REST_FACETS"][
            "hep-author-citations"]()["aggs"]
        assert filters == expected_filters
        assert aggregations == expected_aggregations
Example #6
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 #7
0
HEP_FILTERS = {
    "author": must_match_all_filter("facet_author_name"),
    "author_count": range_author_count_filter("author_count"),
    "doc_type": must_match_all_filter("facet_inspire_doc_type"),
    "earliest_date": range_filter("earliest_date", format="yyyy", end_date_math="/y"),
    "citation_count": range_filter("citation_count"),
    "citation_count_without_self_citations": range_filter(
        "citation_count_without_self_citations"
    ),
    "collaboration": must_match_all_filter("facet_collaborations"),
    "refereed": must_match_all_filter("refereed"),
    "citeable": must_match_all_filter("citeable"),
    "collection": must_match_all_filter("_collections"),
    "subject": must_match_all_filter("facet_inspire_categories"),
    "arxiv_categories": must_match_all_filter("facet_arxiv_categories"),
    "rpp": filter_from_filters_aggregation(hep_rpp(order=1)),
}

JOBS_FILTERS = {
    "field_of_interest": terms_filter("arxiv_categories"),
    "rank": terms_filter("ranks"),
    "region": terms_filter("regions"),
    "status": terms_filter("status"),
}

CONFERENCES_FILTERS = {
    "subject": must_match_all_filter("inspire_categories.term"),
    "start_date": conferences_start_date_range_filter(),
    "contains": conferences_date_range_contains_other_conferences(),
}