Skip to content

Commit

Permalink
Merge pull request #1003 from datacite/case-issue
Browse files Browse the repository at this point in the history
Implement case-insensitive searches for certain API requests
  • Loading branch information
svogt0511 authored Sep 6, 2023
2 parents 9cd0212 + 3f3b9ac commit e541500
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 31 deletions.
57 changes: 35 additions & 22 deletions app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(",") } }
Expand Down Expand Up @@ -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 <<
Expand All @@ -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 <<
Expand Down Expand Up @@ -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(",") } }
Expand All @@ -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(",") } }
Expand All @@ -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] } }
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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

Expand Down
22 changes: 16 additions & 6 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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?
Expand Down
16 changes: 13 additions & 3 deletions app/models/doi/graphql_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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?
Expand All @@ -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" } }
Expand Down

0 comments on commit e541500

Please sign in to comment.