diff --git a/app/controllers/datacite_dois_controller.rb b/app/controllers/datacite_dois_controller.rb index b0ae13d7f..7ada8acb5 100644 --- a/app/controllers/datacite_dois_controller.rb +++ b/app/controllers/datacite_dois_controller.rb @@ -68,8 +68,8 @@ def index params[:state] = "findable" end - # default number of facets - facet_count = (params[:facet_count] || 10).to_i + # facets are enabled by default + disable_facets = params[:disable_facets] if params[:id].present? response = DataciteDoi.find_by_id(params[:id]) @@ -125,7 +125,7 @@ def index sample_size: params[:sample], source: params[:source], scroll_id: params[:scroll_id], - facet_count: facet_count, + disable_facets: disable_facets, page: page, sort: sort, random: params[:random], @@ -210,7 +210,7 @@ def index status: :ok end else - if total.positive? && facet_count.positive? + if total.positive? && !disable_facets states = facet_by_key(response.aggregations.states.buckets) resource_types = facet_by_combined_key(response.aggregations.resource_types.buckets) published = facet_by_range(response.aggregations.published.buckets) @@ -328,7 +328,7 @@ def index "has-person" => params[:has_person], "has-affiliation" => params[:has_affiliation], "has-funder" => params[:has_funder], - facet_count: params[:facet_count], + "disable-facets" => params[:disable_facets], detail: params[:detail], composite: params[:composite], affiliation: params[:affiliation], diff --git a/app/models/doi.rb b/app/models/doi.rb index dfd36501c..4d7b69fd7 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -585,10 +585,10 @@ def self.gql_query_aggregations(facet_count: 10) end end - def self.query_aggregations(facet_count: 10) - if facet_count.to_i.positive? + def self.query_aggregations(disable_facets: false) + if !disable_facets { - resource_types: { terms: { field: "resource_type_id_and_name", size: facet_count, min_doc_count: 1 } }, + resource_types: { terms: { field: "resource_type_id_and_name", size: 16, min_doc_count: 1 } }, states: { terms: { field: "aasm_state", size: 3, min_doc_count: 1 } }, published: { date_histogram: { @@ -601,60 +601,60 @@ def self.query_aggregations(facet_count: 10) min_doc_count: 1, }, }, - registration_agencies: { terms: { field: "agency", size: facet_count, min_doc_count: 1 } }, + registration_agencies: { terms: { field: "agency", size: 10, min_doc_count: 1 } }, created: { date_histogram: { field: "created", interval: "year", format: "year", order: { _key: "desc" }, min_doc_count: 1 }, - aggs: { bucket_truncate: { bucket_sort: { size: facet_count } } } }, + aggs: { bucket_truncate: { bucket_sort: { size: 10 } } } }, registered: { date_histogram: { field: "registered", interval: "year", format: "year", order: { _key: "desc" }, min_doc_count: 1 }, - aggs: { bucket_truncate: { bucket_sort: { size: facet_count } } } }, - providers: { terms: { field: "provider_id_and_name", size: facet_count, min_doc_count: 1 } }, + aggs: { bucket_truncate: { bucket_sort: { size: 10 } } } }, + providers: { terms: { field: "provider_id_and_name", size: 10, min_doc_count: 1 } }, clients: { terms: { field: "client_id_and_name", size: 10, min_doc_count: 1 } }, - affiliations: { terms: { field: "affiliation_id_and_name", size: facet_count, min_doc_count: 1 } }, - prefixes: { terms: { field: "prefix", size: facet_count, min_doc_count: 1 } }, - schema_versions: { terms: { field: "schema_version", size: facet_count, min_doc_count: 1 } }, - link_checks_status: { terms: { field: "landing_page.status", size: facet_count, min_doc_count: 1 } }, + affiliations: { terms: { field: "affiliation_id_and_name", size: 10, min_doc_count: 1 } }, + prefixes: { terms: { field: "prefix", size: 10, min_doc_count: 1 } }, + schema_versions: { terms: { field: "schema_version", size: 10, min_doc_count: 1 } }, + link_checks_status: { terms: { field: "landing_page.status", size: 10, min_doc_count: 1 } }, # link_checks_has_schema_org: { terms: { field: 'landing_page.hasSchemaOrg', size: 2, min_doc_count: 1 } }, # link_checks_schema_org_id: { value_count: { field: "landing_page.schemaOrgId" } }, # link_checks_dc_identifier: { value_count: { field: "landing_page.dcIdentifier" } }, # link_checks_citation_doi: { value_count: { field: "landing_page.citationDoi" } }, # links_checked: { value_count: { field: "landing_page.checked" } }, # sources: { terms: { field: 'source', size: 15, min_doc_count: 1 } }, - subjects: { terms: { field: "subjects.subject", size: facet_count, min_doc_count: 1 } }, + subjects: { terms: { field: "subjects.subject", size: 10, min_doc_count: 1 } }, pid_entities: { filter: { term: { "subjects.subjectScheme": "PidEntity" } }, aggs: { - subject: { terms: { field: "subjects.subject", size: facet_count, min_doc_count: 1, + subject: { terms: { field: "subjects.subject", size: 10, min_doc_count: 1, include: %w(Dataset Publication Software Organization Funder Person Grant Sample Instrument Repository Project) } }, }, }, fields_of_science: { filter: { term: { "subjects.subjectScheme": "Fields of Science and Technology (FOS)" } }, aggs: { - subject: { terms: { field: "subjects.subject", size: facet_count, min_doc_count: 1, + subject: { terms: { field: "subjects.subject", size: 10, min_doc_count: 1, include: "FOS:.*" } }, }, }, - licenses: { terms: { field: "rights_list.rightsIdentifier", size: facet_count, min_doc_count: 1 } }, - languages: { terms: { field: "language", size: facet_count, min_doc_count: 1 } }, - certificates: { terms: { field: "client.certificate", size: facet_count, min_doc_count: 1 } }, + licenses: { terms: { field: "rights_list.rightsIdentifier", size: 10, min_doc_count: 1 } }, + languages: { terms: { field: "language", size: 10, min_doc_count: 1 } }, + certificates: { terms: { field: "client.certificate", size: 10, min_doc_count: 1 } }, views: { date_histogram: { field: "publication_year", interval: "year", format: "year", order: { _key: "desc" }, min_doc_count: 1 }, aggs: { metric_count: { sum: { field: "view_count" } }, - bucket_truncate: { bucket_sort: { size: facet_count } }, + bucket_truncate: { bucket_sort: { size: 10 } }, }, }, downloads: { date_histogram: { field: "publication_year", interval: "year", format: "year", order: { _key: "desc" }, min_doc_count: 1 }, aggs: { metric_count: { sum: { field: "download_count" } }, - bucket_truncate: { bucket_sort: { size: facet_count } }, + bucket_truncate: { bucket_sort: { size: 10 } }, }, }, citations: { date_histogram: { field: "publication_year", interval: "year", format: "year", order: { _key: "desc" }, min_doc_count: 1 }, aggs: { metric_count: { sum: { field: "citation_count" } }, - bucket_truncate: { bucket_sort: { size: facet_count } }, + bucket_truncate: { bucket_sort: { size: 10 } }, }, }, } @@ -722,7 +722,7 @@ def self.find_by_ids(ids, options = {}) must: must, }, }, - aggregations: query_aggregations(facet_count: options[:facet_count]), + aggregations: query_aggregations(disable_facets: options[:disable_facets]), ) end @@ -954,7 +954,7 @@ def self.query(query, options = {}) elsif options[:totals_agg] == "prefix" prefix_aggregations else - query_aggregations(facet_count: options[:facet_count]) + query_aggregations(disable_facets: options[:disable_facets]) end # Cursor nav uses search_after, this should always be an array of values that match the sort. diff --git a/spec/requests/datacite_dois_spec.rb b/spec/requests/datacite_dois_spec.rb index 465ab0574..f9ca0faa7 100644 --- a/spec/requests/datacite_dois_spec.rb +++ b/spec/requests/datacite_dois_spec.rb @@ -443,7 +443,7 @@ end it "filter for interactive resources no facets" do - get "/dois?resource-type-id=interactive-resource&facet-count=0", nil, headers + get "/dois?resource-type-id=interactive-resource&disable-facets=true", nil, headers expect(last_response.status).to eq(200) expect(json["data"].size).to eq(3)