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
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 test_hep_doc_type_aggregation_and_filter(inspire_app, override_config): config = { "RECORDS_REST_FACETS": { "records-hep": { "filters": hep_filters(), "aggs": { **hep_doc_type_aggregation(1) }, } } } with override_config(**config): data = {"document_type": ["article"]} expected_record = create_record("lit", data) data = {"document_type": ["conference paper"]} create_record("lit", data) with inspire_app.test_client() as client: response = client.get("/literature/facets").json earliest_date_aggregation = { "meta": { "bucket_help": { "published": { "link": "https://inspirehep.net/help/knowledge-base/faq/#faq-published", "text": "Published papers are believed to have undergone rigorous peer review.", } }, "title": "Document Type", "type": "checkbox", "order": 1, }, "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "article", "doc_count": 1 }, { "key": "conference paper", "doc_count": 1 }, ], } assert response["aggregations"][ "doc_type"] == earliest_date_aggregation with inspire_app.test_client() as client: response = client.get("/literature?doc_type=article").json assert len(response["hits"]["hits"]) == 1 assert (response["hits"]["hits"][0]["metadata"]["control_number"] == expected_record["control_number"])
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)), }, }
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)), }, }
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), }, }
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