From b591eddbf31aed5f86764adfb7165b0a433e2f11 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Fri, 26 Jul 2019 14:44:10 +0200 Subject: [PATCH] fix consortium_lead_id. datacite/bracco#210 --- app/models/concerns/indexable.rb | 2 +- app/models/provider.rb | 4 ++-- spec/requests/providers_spec.rb | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index abf95e4ec..e77cc3e63 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -167,7 +167,7 @@ def query(query, options={}) if self.name == "Provider" must << { range: { created: { gte: "#{options[:year].split(",").min}||/y", lte: "#{options[:year].split(",").max}||/y", format: "yyyy" }}} if options[:year].present? must << { term: { region: options[:region].upcase }} if options[:region].present? - must << { term: { consortium_lead_id: options[:consortium_lead_id].upcase }} if options[:consortium_lead_id].present? + must << { term: { "consortium_lead_id.raw" => options[:consortium_lead_id] }} if options[:consortium_lead_id].present? must << { term: { member_type: options[:member_type] }} if options[:member_type].present? must << { term: { organization_type: options[:organization_type] }} if options[:organization_type].present? must << { term: { focus_area: options[:focus_area] }} if options[:focus_area].present? diff --git a/app/models/provider.rb b/app/models/provider.rb index 3e77dfea3..937b65755 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -106,7 +106,7 @@ class Provider < ActiveRecord::Base indexes :focus_area, type: :keyword indexes :organization_type, type: :keyword indexes :member_type, type: :keyword - indexes :consortium_lead_id, type: :keyword + indexes :consortium_lead_id, type: :text, fields: { keyword: { type: "keyword" }, raw: { type: "text", "analyzer": "string_lowercase", "fielddata": true }} indexes :consortium_organization_ids, type: :keyword indexes :country_code, type: :keyword indexes :role_name, type: :keyword @@ -297,7 +297,7 @@ def uid end def consortium_organization_ids - consortium_organizations.pluck(:symbol) if consortium_organizations.present? + consortium_organizations.pluck(:symbol).map(&:downcase) if consortium_organizations.present? end def cache_key diff --git a/spec/requests/providers_spec.rb b/spec/requests/providers_spec.rb index 91cb8fa8f..64f37158e 100644 --- a/spec/requests/providers_spec.rb +++ b/spec/requests/providers_spec.rb @@ -195,7 +195,7 @@ expect(json.dig('data', 'relationships', 'consortiumLead', 'data', 'id')).to eq(consortium_lead.symbol.downcase) sleep 1 - + get "/providers/#{consortium_lead.symbol.downcase}?include=consortium-organizations", nil, headers expect(last_response.status).to eq(200) @@ -204,15 +204,15 @@ expect(json.dig('included', 0, 'attributes', 'memberType')).to eq("consortium_organization") expect(json.dig('included', 0, 'relationships', 'consortiumLead', 'data', 'id')).to eq(consortium_lead.symbol) - get "/providers?consortium-lead-id=#{consortium_lead.symbol.downcase}", nil, headers + # get "/providers?consortium-lead-id=#{consortium_lead.symbol.downcase}", nil, headers - expect(last_response.status).to eq(200) - puts last_response.body + # expect(last_response.status).to eq(200) + # puts last_response.body - get "/providers/#{consortium_lead.symbol.downcase}/organizations", nil, headers + # get "/providers/#{consortium_lead.symbol.downcase}/organizations", nil, headers - expect(last_response.status).to eq(200) - puts last_response.body + # expect(last_response.status).to eq(200) + # puts last_response.body end end