diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index 27a66da69..87e496529 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -313,7 +313,7 @@ def query(query, options = {}) filter << { term: { region: options[:region].upcase } } end if options[:consortium_id].present? - filter << { term: { "consortium_id.raw" => options[:consortium_id] } } + filter << { term: { "consortium_id": { value: options[:consortium_id], case_insensitive: true } } } end if options[:member_type].present? filter << { terms: { member_type: options[:member_type].split(",") } } @@ -377,7 +377,10 @@ def query(query, options = {}) { range: { updated: { lte: "#{options[:until_date]}||/d" } } } end if options[:provider_id].present? - filter << { terms: { provider_id: options[:provider_id].split(",") } } + options[:provider_id].split(",").each { |id| + should << { term: { "provider_id": { value: id, case_insensitive: true } } } + } + minimum_should_match = 1 end if options[:software].present? filter << @@ -391,7 +394,7 @@ def query(query, options = {}) { terms: { repository_type: options[:repository_type].split(",") } } end if options[:consortium_id].present? - filter << { term: { consortium_id: options[:consortium_id] } } + filter << { term: { consortium_id: { value: options[:consortium_id], case_insensitive: true } } } end if options[:re3data_id].present? filter << @@ -515,8 +518,10 @@ def query(query, options = {}) { terms: { registrant_id: options[:registrant_id].split(",") } } end if options[:provider_id].present? - filter << - { terms: { registrant_id: options[:provider_id].split(",") } } + options[:provider_id].split(",").each { |id| + should << { term: { "provider_ids": { value: id, case_insensitive: true } } } + } + minimum_should_match = 1 end if options[:issn].present? filter << { terms: { issn: options[:issn].split(",") } } @@ -542,12 +547,16 @@ def query(query, options = {}) } end if options[:provider_id].present? - filter << - { terms: { provider_ids: options[:provider_id].split(",") } } + options[:provider_id].split(",").each { |id| + should << { term: { "provider_ids": { value: id, case_insensitive: true } } } + } + minimum_should_match = 1 end if options[:client_id].present? - filter << - { terms: { client_ids: options[:client_id].to_s.split(",") } } + options[:client_id].split(",").each { |id| + should << { term: { "client_ids": { value: id, case_insensitive: true } } } + } + minimum_should_match = 1 end if options[:state].present? filter << { terms: { state: options[:state].to_s.split(",") } } @@ -573,18 +582,19 @@ def query(query, options = {}) } end if options[:provider_id].present? - filter << { terms: { provider_id: options[:provider_id].split(",") } } + options[:provider_id].split(",").each { |id| + should << { term: { "provider_id": { value: id, case_insensitive: true } } } + } + minimum_should_match = 1 end if options[:consortium_organization_id].present? - filter << - { - terms: { - provider_id: options[:consortium_organization_id].split(","), - }, - } + options[:consortium_organization_id].split(",").each { |id| + should << { term: { "provider_id": { value: id, case_insensitive: true } } } + } + minimum_should_match = 1 end if options[:consortium_id].present? - filter << { term: { consortium_id: options[:consortium_id] } } + filter << { term: { consortium_id: { value: options[:consortium_id], case_insensitive: true } } } end if options[:prefix_id].present? filter << { term: { prefix_id: options[:prefix_id] } } @@ -616,10 +626,13 @@ def query(query, options = {}) } end if options[:client_id].present? - filter << { terms: { client_id: options[:client_id].split(",") } } + options[:client_id].split(",").each { |id| + should << { term: { "client_id": { value: id, case_insensitive: true } } } + } + minimum_should_match = 1 end if options[:prefix_id].present? - filter << { term: { prefix_id: options[:prefix_id] } } + filter << { term: { "prefix_id": { value: options[:prefix_id], case_insensitive: true } } } end elsif name == "Activity" must = if query.present? @@ -655,13 +668,13 @@ def query(query, options = {}) end if options[:provider_id].present? - filter << { term: { provider_id: options[:provider_id] } } + filter << { term: { "provider_id": { value: options[:provider_id], case_insensitive: true } } } end # match either consortium_id or provider_id if options[:consortium_id].present? - should << { term: { provider_id: options[:consortium_id] } } - should << { term: { consortium_id: options[:consortium_id] } } + should << { term: { provider_id: { value: options[:consortium_id], case_insensitive: true } } } + should << { term: { consortium_id: { value: options[:consortium_id], case_insensitive: true } } } minimum_should_match = 1 end diff --git a/app/models/doi.rb b/app/models/doi.rb index fde297282..f5ed52a02 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -804,9 +804,9 @@ def self.find_by_id(id) def self.stats_query(options = {}) filter = [] - filter << { term: { provider_id: options[:provider_id] } } if options[:provider_id].present? - filter << { term: { client_id: options[:client_id] } } if options[:client_id].present? - filter << { term: { consortium_id: options[:consortium_id] } } if options[:consortium_id].present? + filter << { term: { provider_id: { value: options[:provider_id], case_insensitive: true } } } if options[:provider_id].present? + filter << { term: { client_id: { value: options[:client_id], case_insensitive: true } } } if options[:client_id].present? + filter << { term: { consortium_id: { value: options[:consortium_id], case_insensitive: true } } } if options[:consortium_id].present? filter << { term: { "creators.nameIdentifiers.nameIdentifier" => "https://orcid.org/#{orcid_from_url(options[:user_id])}" } } if options[:user_id].present? aggregations = { @@ -930,8 +930,18 @@ def self.query(query, options = {}) filter << { terms: { doi: options[:ids].map(&:upcase) } } if options[:ids].present? filter << { term: { "types.resourceTypeGeneral": options[:resource_type_id].underscore.camelize } } if options[:resource_type_id].present? filter << { terms: { "types.resourceType": options[:resource_type].split(",") } } if options[:resource_type].present? - filter << { terms: { provider_id: options[:provider_id].split(",") } } if options[:provider_id].present? - filter << { terms: { client_id: options[:client_id].to_s.split(",") } } if options[:client_id].present? + if options[:provider_id].present? + options[:provider_id].split(",").each { |id| + should << { term: { "provider_id": { value: id, case_insensitive: true } } } + } + minimum_should_match = 1 + end + if options[:client_id].present? + options[:client_id].split(",").each { |id| + should << { term: { "client_id": { value: id, case_insensitive: true } } } + } + minimum_should_match = 1 + end filter << { terms: { agency: options[:agency].split(",").map(&:downcase) } } if options[:agency].present? filter << { terms: { prefix: options[:prefix].to_s.split(",") } } if options[:prefix].present? filter << { terms: { language: options[:language].to_s.split(",").map(&:downcase) } } if options[:language].present? @@ -974,7 +984,7 @@ def self.query(query, options = {}) filter << { range: { "landing_page.redirectCount": { "gte": options[:link_check_redirect_count_gte] } } } if options[:link_check_redirect_count_gte].present? filter << { terms: { aasm_state: options[:state].to_s.split(",") } } if options[:state].present? filter << { range: { registered: { gte: "#{options[:registered].split(',').min}||/y", lte: "#{options[:registered].split(',').max}||/y", format: "yyyy" } } } if options[:registered].present? - filter << { term: { consortium_id: options[:consortium_id] } } if options[:consortium_id].present? + filter << { term: { "consortium_id": { value: options[:consortium_id], case_insensitive: true } } } if options[:consortium_id].present? # TODO align PID parsing filter << { term: { "client.re3data_id" => doi_from_url(options[:re3data_id]) } } if options[:re3data_id].present? filter << { term: { "client.opendoar_id" => options[:opendoar_id] } } if options[:opendoar_id].present? diff --git a/app/models/doi/graphql_query.rb b/app/models/doi/graphql_query.rb index 9ceed18f7..51f71be2f 100644 --- a/app/models/doi/graphql_query.rb +++ b/app/models/doi/graphql_query.rb @@ -124,8 +124,6 @@ def filters filter << { terms: { doi: options[:ids].map(&:upcase) } } if options[:ids].present? filter << { term: { "types.resourceTypeGeneral": options[:resource_type_id].underscore.camelize } } if options[:resource_type_id].present? filter << { terms: { "types.resourceType": options[:resource_type].split(",") } } if options[:resource_type].present? - filter << { terms: { provider_id: options[:provider_id].split(",") } } if options[:provider_id].present? - filter << { terms: { client_id: options[:client_id].to_s.split(",") } } if options[:client_id].present? filter << { terms: { agency: options[:agency].split(",").map(&:downcase) } } if options[:agency].present? filter << { terms: { prefix: options[:prefix].to_s.split(",") } } if options[:prefix].present? filter << { terms: { language: options[:language].to_s.split(",").map(&:downcase) } } if options[:language].present? @@ -168,7 +166,7 @@ def filters filter << { range: { "landing_page.redirectCount": { "gte": options[:link_check_redirect_count_gte] } } } if options[:link_check_redirect_count_gte].present? filter << { terms: { aasm_state: options[:state].to_s.split(",") } } if options[:state].present? filter << { range: { registered: { gte: "#{options[:registered].split(',').min}||/y", lte: "#{options[:registered].split(',').max}||/y", format: "yyyy" } } } if options[:registered].present? - filter << { term: { consortium_id: options[:consortium_id] } } if options[:consortium_id].present? + filter << { term: { consortium_id: { value: options[:consortium_id], case_insensitive: true } } } if options[:consortium_id].present? # TODO align PID parsing filter << { term: { "client.re3data_id" => doi_from_url(options[:re3data_id]) } } if options[:re3data_id].present? filter << { term: { "client.opendoar_id" => options[:opendoar_id] } } if options[:opendoar_id].present? @@ -183,6 +181,18 @@ def get_should_clause options = @options should_query = [] minimum_should_match = 0 + if options[:provider_id].present? + options[:provider_id].split(",").each { |id| + should_query << { term: { "provider_id": { value: id, case_insensitive: true } } } + } + minimum_should_match = 1 + end + if options[:client_id].present? + options[:client_id].split(",").each { |id| + should_query << { term: { "client_id": { value: id, case_insensitive: true } } } + } + minimum_should_match = 1 + end # match either one of has_affiliation, has_organization, has_funder or has_member if options[:has_organization].present? should_query << { term: { "creators.nameIdentifiers.nameIdentifierScheme" => "ROR" } }