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 test_hep_author_count_aggregation_and_filter(inspire_app, override_config): config = { "RECORDS_REST_FACETS": { "records-hep": { "filters": hep_filters(), "aggs": {**hep_author_count_aggregation(1)}, } } } with override_config(**config): data = {"authors": [{"full_name": "John Doe"}]} expected_record = create_record("lit", data) data = {"authors": [{"full_name": "John Doe"}, {"full_name": "Jane Doe"}]} create_record("lit", data) with inspire_app.test_client() as client: response = client.get("/literature/facets").json expected_aggregation = { "meta": {"title": "Number of authors", "type": "checkbox", "order": 1}, "buckets": [ {"key": "Single author", "from": 1.0, "to": 2.0, "doc_count": 1}, {"key": "10 authors or less", "from": 1.0, "to": 11.0, "doc_count": 2}, ], } assert response["aggregations"]["author_count"] == expected_aggregation with inspire_app.test_client() as client: response = client.get("/literature?author_count=Single%20author").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