Skip to content

Commit

Permalink
support query by repository_id for clients. #292
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jun 16, 2019
1 parent 604a3c9 commit 5d767de
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 161 deletions.
8 changes: 7 additions & 1 deletion app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ def index
elsif params[:ids].present?
response = Client.find_by_id(params[:ids], page: page, sort: sort)
else
response = Client.query(params[:query], year: params[:year], provider_id: params[:provider_id], software: params[:software], page: page, sort: sort)
response = Client.query(params[:query],
year: params[:year],
provider_id: params[:provider_id],
repository_id: params[:repository_id],
software: params[:software],
page: page,
sort: sort)
end

begin
Expand Down
1 change: 0 additions & 1 deletion app/models/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class Client < ActiveRecord::Base
indexes :description, type: :text
indexes :contact_name, type: :text
indexes :contact_email, type: :text, fields: { keyword: { type: "keyword" }}
indexes :re3data, type: :keyword
indexes :version, type: :integer
indexes :is_active, type: :keyword
indexes :domains, type: :text
Expand Down
3 changes: 2 additions & 1 deletion app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,13 @@ def query(query, options={})
elsif self.name == "Client"
must << { range: { created: { gte: "#{options[:year].split(",").min}||/y", lte: "#{options[:year].split(",").max}||/y", format: "yyyy" }}} if options[:year].present?
must << { terms: { "software.raw" => options[:software].split(",") }} if options[:software].present?
must << { term: { repository_id: options[:repository_id].gsub("/", '\/') }} if options[:repository_id].present?
must_not << { exists: { field: "deleted_at" }} unless options[:include_deleted]
must_not << { terms: { provider_id: ["crossref"] }} if options[:exclude_registration_agencies]
elsif self.name == "Doi"
must << { terms: { aasm_state: options[:state].to_s.split(",") }} if options[:state].present?
must << { range: { registered: { gte: "#{options[:registered].split(",").min}||/y", lte: "#{options[:registered].split(",").max}||/y", format: "yyyy" }}} if options[:registered].present?
must << { term: { "client.repository_id": options[:repository_id].upcase }} if options[:repository_id].present?
must << { term: { "client.repository_id" => options[:repository_id].upcase.gsub("/", '\/') }} if options[:repository_id].present?
must_not << { terms: { provider_id: ["crossref"] }} if options[:exclude_registration_agencies]
elsif self.name == "Event"
must << { term: { subj_id: options[:subj_id] }} if options[:subj_id].present?
Expand Down
351 changes: 193 additions & 158 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,165 +99,200 @@ class Doi < ActiveRecord::Base
# use different index for testing
index_name Rails.env.test? ? "dois-test" : "dois"

mapping dynamic: 'false' do
indexes :id, type: :keyword
indexes :uid, type: :keyword
indexes :doi, type: :keyword
indexes :identifier, type: :keyword
indexes :url, type: :text, fields: { keyword: { type: "keyword" }}
indexes :creators, type: :object, properties: {
nameType: { type: :keyword },
nameIdentifiers: { type: :object, properties: {
nameIdentifier: { type: :keyword },
nameIdentifierScheme: { type: :keyword },
schemeUri: { type: :keyword }
}},
name: { type: :text },
givenName: { type: :text },
familyName: { type: :text },
affiliation: { type: :text }
}
indexes :contributors, type: :object, properties: {
nameType: { type: :keyword },
nameIdentifiers: { type: :object, properties: {
nameIdentifier: { type: :keyword },
nameIdentifierScheme: { type: :keyword },
schemeUri: { type: :keyword }
}},
name: { type: :text },
givenName: { type: :text },
familyName: { type: :text },
affiliation: { type: :text },
contributorType: { type: :keyword }
}
indexes :creator_names, type: :text
indexes :titles, type: :object, properties: {
title: { type: :text, fields: { keyword: { type: "keyword" }}},
titleType: { type: :keyword },
lang: { type: :keyword }
}
indexes :descriptions, type: :object, properties: {
description: { type: :text },
descriptionType: { type: :keyword },
lang: { type: :keyword }
}
indexes :publisher, type: :text, fields: { keyword: { type: "keyword" }}
indexes :publication_year, type: :date, format: "yyyy", ignore_malformed: true
indexes :client_id, type: :keyword
indexes :provider_id, type: :keyword
indexes :resource_type_id, type: :keyword
indexes :media_ids, type: :keyword
indexes :media, type: :object, properties: {
type: { type: :keyword },
id: { type: :keyword },
uid: { type: :keyword },
url: { type: :text },
media_type: { type: :keyword },
version: { type: :keyword },
created: { type: :date, ignore_malformed: true },
updated: { type: :date, ignore_malformed: true }
}
indexes :identifiers, type: :object, properties: {
identifierType: { type: :keyword },
identifier: { type: :keyword }
}
indexes :related_identifiers, type: :object, properties: {
relatedIdentifierType: { type: :keyword },
relatedIdentifier: { type: :keyword },
relationType: { type: :keyword },
relatedMetadataScheme: { type: :keyword },
schemeUri: { type: :keyword },
schemeType: { type: :keyword },
resourceTypeGeneral: { type: :keyword }
}
indexes :types, type: :object, properties: {
resourceTypeGeneral: { type: :keyword },
resourceType: { type: :keyword },
schemaOrg: { type: :keyword },
bibtex: { type: :keyword },
citeproc: { type: :keyword },
ris: { type: :keyword }
}
indexes :funding_references, type: :object, properties: {
funderName: { type: :keyword },
funderIdentifier: { type: :keyword },
funderIdentifierType: { type: :keyword },
awardNumber: { type: :keyword },
awardUri: { type: :keyword },
awardTitle: { type: :keyword }
}
indexes :dates, type: :object, properties: {
date: { type: :date, format: "date_optional_time", ignore_malformed: true, fields: { raw: { type: :text }} },
dateType: { type: :keyword }
}
indexes :geo_locations, type: :object, properties: {
geoLocationPoint: { type: :object },
geoLocationBox: { type: :object },
geoLocationPlace: { type: :keyword }
}
indexes :rights_list, type: :object, properties: {
rights: { type: :keyword },
rightsUri: { type: :keyword },
lang: { type: :keyword }
}
indexes :subjects, type: :object, properties: {
subject: { type: :keyword },
subjectScheme: { type: :keyword },
schemeUri: { type: :keyword },
valueUri: { type: :keyword },
lang: { type: :keyword }
}
indexes :container, type: :object, properties: {
type: { type: :keyword },
identifier: { type: :keyword },
identifierType: { type: :keyword },
title: { type: :keyword },
volume: { type: :keyword },
issue: { type: :keyword },
firstPage: { type: :keyword },
lastPage: { type: :keyword }
}

indexes :xml, type: :text, index: "false"
indexes :content_url, type: :keyword
indexes :version_info, type: :keyword
indexes :formats, type: :keyword
indexes :sizes, type: :keyword
indexes :language, type: :keyword
indexes :is_active, type: :keyword
indexes :aasm_state, type: :keyword
indexes :schema_version, type: :keyword
indexes :metadata_version, type: :keyword
indexes :agency, type: :keyword
indexes :source, type: :keyword
indexes :prefix, type: :keyword
indexes :suffix, type: :keyword
indexes :reason, type: :text
indexes :landing_page, type: :object, properties: {
checked: { type: :date, ignore_malformed: true },
url: { type: :text, fields: { keyword: { type: "keyword" }}},
status: { type: :integer },
contentType: { type: :keyword },
error: { type: :keyword },
redirectCount: { type: :integer },
redirectUrls: { type: :keyword },
downloadLatency: { type: :scaled_float, scaling_factor: 100 },
hasSchemaOrg: { type: :boolean },
schemaOrgId: { type: :keyword },
dcIdentifier: { type: :keyword },
citationDoi: { type: :keyword },
bodyHasPid: { type: :boolean }
settings index: {
analysis: {
analyzer: {
string_lowercase: { tokenizer: 'keyword', filter: %w(lowercase ascii_folding) }
},
normalizer: {
keyword_lowercase: { type: "custom", filter: %w(lowercase) }
},
filter: {
ascii_folding: { type: 'asciifolding', preserve_original: true }
}
}
indexes :cache_key, type: :keyword
indexes :registered, type: :date, ignore_malformed: true
indexes :published, type: :date, ignore_malformed: true
indexes :created, type: :date, ignore_malformed: true
indexes :updated, type: :date, ignore_malformed: true

# include parent objects
indexes :client, type: :object
indexes :provider, type: :object
indexes :resource_type, type: :object
} do
mapping dynamic: 'false' do
indexes :id, type: :keyword
indexes :uid, type: :keyword
indexes :doi, type: :keyword
indexes :identifier, type: :keyword
indexes :url, type: :text, fields: { keyword: { type: "keyword" }}
indexes :creators, type: :object, properties: {
nameType: { type: :keyword },
nameIdentifiers: { type: :object, properties: {
nameIdentifier: { type: :keyword },
nameIdentifierScheme: { type: :keyword },
schemeUri: { type: :keyword }
}},
name: { type: :text },
givenName: { type: :text },
familyName: { type: :text },
affiliation: { type: :text }
}
indexes :contributors, type: :object, properties: {
nameType: { type: :keyword },
nameIdentifiers: { type: :object, properties: {
nameIdentifier: { type: :keyword },
nameIdentifierScheme: { type: :keyword },
schemeUri: { type: :keyword }
}},
name: { type: :text },
givenName: { type: :text },
familyName: { type: :text },
affiliation: { type: :text },
contributorType: { type: :keyword }
}
indexes :creator_names, type: :text
indexes :titles, type: :object, properties: {
title: { type: :text, fields: { keyword: { type: "keyword" }}},
titleType: { type: :keyword },
lang: { type: :keyword }
}
indexes :descriptions, type: :object, properties: {
description: { type: :text },
descriptionType: { type: :keyword },
lang: { type: :keyword }
}
indexes :publisher, type: :text, fields: { keyword: { type: "keyword" }}
indexes :publication_year, type: :date, format: "yyyy", ignore_malformed: true
indexes :client_id, type: :keyword
indexes :provider_id, type: :keyword
indexes :resource_type_id, type: :keyword
indexes :media_ids, type: :keyword
indexes :media, type: :object, properties: {
type: { type: :keyword },
id: { type: :keyword },
uid: { type: :keyword },
url: { type: :text },
media_type: { type: :keyword },
version: { type: :keyword },
created: { type: :date, ignore_malformed: true },
updated: { type: :date, ignore_malformed: true }
}
indexes :identifiers, type: :object, properties: {
identifierType: { type: :keyword },
identifier: { type: :keyword }
}
indexes :related_identifiers, type: :object, properties: {
relatedIdentifierType: { type: :keyword },
relatedIdentifier: { type: :keyword },
relationType: { type: :keyword },
relatedMetadataScheme: { type: :keyword },
schemeUri: { type: :keyword },
schemeType: { type: :keyword },
resourceTypeGeneral: { type: :keyword }
}
indexes :types, type: :object, properties: {
resourceTypeGeneral: { type: :keyword },
resourceType: { type: :keyword },
schemaOrg: { type: :keyword },
bibtex: { type: :keyword },
citeproc: { type: :keyword },
ris: { type: :keyword }
}
indexes :funding_references, type: :object, properties: {
funderName: { type: :keyword },
funderIdentifier: { type: :keyword },
funderIdentifierType: { type: :keyword },
awardNumber: { type: :keyword },
awardUri: { type: :keyword },
awardTitle: { type: :keyword }
}
indexes :dates, type: :object, properties: {
date: { type: :date, format: "date_optional_time", ignore_malformed: true, fields: { raw: { type: :text }} },
dateType: { type: :keyword }
}
indexes :geo_locations, type: :object, properties: {
geoLocationPoint: { type: :object },
geoLocationBox: { type: :object },
geoLocationPlace: { type: :keyword }
}
indexes :rights_list, type: :object, properties: {
rights: { type: :keyword },
rightsUri: { type: :keyword },
lang: { type: :keyword }
}
indexes :subjects, type: :object, properties: {
subject: { type: :keyword },
subjectScheme: { type: :keyword },
schemeUri: { type: :keyword },
valueUri: { type: :keyword },
lang: { type: :keyword }
}
indexes :container, type: :object, properties: {
type: { type: :keyword },
identifier: { type: :keyword },
identifierType: { type: :keyword },
title: { type: :keyword },
volume: { type: :keyword },
issue: { type: :keyword },
firstPage: { type: :keyword },
lastPage: { type: :keyword }
}

indexes :xml, type: :text, index: "false"
indexes :content_url, type: :keyword
indexes :version_info, type: :keyword
indexes :formats, type: :keyword
indexes :sizes, type: :keyword
indexes :language, type: :keyword
indexes :is_active, type: :keyword
indexes :aasm_state, type: :keyword
indexes :schema_version, type: :keyword
indexes :metadata_version, type: :keyword
indexes :agency, type: :keyword
indexes :source, type: :keyword
indexes :prefix, type: :keyword
indexes :suffix, type: :keyword
indexes :reason, type: :text
indexes :landing_page, type: :object, properties: {
checked: { type: :date, ignore_malformed: true },
url: { type: :text, fields: { keyword: { type: "keyword" }}},
status: { type: :integer },
contentType: { type: :keyword },
error: { type: :keyword },
redirectCount: { type: :integer },
redirectUrls: { type: :keyword },
downloadLatency: { type: :scaled_float, scaling_factor: 100 },
hasSchemaOrg: { type: :boolean },
schemaOrgId: { type: :keyword },
dcIdentifier: { type: :keyword },
citationDoi: { type: :keyword },
bodyHasPid: { type: :boolean }
}
indexes :cache_key, type: :keyword
indexes :registered, type: :date, ignore_malformed: true
indexes :published, type: :date, ignore_malformed: true
indexes :created, type: :date, ignore_malformed: true
indexes :updated, type: :date, ignore_malformed: true

# include parent objects
indexes :client, type: :object, properties: {
id: { type: :keyword },
symbol: { type: :keyword },
provider_id: { type: :keyword },
repository_id: { type: :keyword },
prefix_ids: { type: :keyword },
name: { type: :text, fields: { keyword: { type: "keyword" }, raw: { type: "text", analyzer: "string_lowercase", "fielddata": true }} },
description: { type: :text },
contact_name: { type: :text },
contact_email: { type: :text, fields: { keyword: { type: "keyword" }} },
version: { type: :integer },
is_active: { type: :keyword },
domains: { type: :text },
year: { type: :integer },
url: { type: :text, fields: { keyword: { type: "keyword" }} },
software: { type: :text, fields: { keyword: { type: "keyword" }, raw: { type: "text", analyzer: "string_lowercase", "fielddata": true }} },
cache_key: { type: :keyword },
created: { type: :date },
updated: { type: :date },
deleted_at: { type: :date },
cumulative_years: { type: :integer, index: "false" }
}
indexes :provider, type: :object
indexes :resource_type, type: :object
end
end

def as_indexed_json(options={})
Expand Down

0 comments on commit 5d767de

Please sign in to comment.