From e26a5740519b8eac7ccd8ce04b58e624b93e9e2e Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Thu, 3 Jan 2019 08:37:34 +0100 Subject: [PATCH] use query string queries. #175 --- app/controllers/clients_controller.rb | 2 +- app/controllers/dois_controller.rb | 1 - app/controllers/providers_controller.rb | 2 +- app/models/client.rb | 6 +++--- app/models/concerns/indexable.rb | 5 +++-- app/models/doi.rb | 6 +++--- app/models/provider.rb | 6 +++--- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index 3fccb4bb3..d8a02e92b 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -31,7 +31,7 @@ def index elsif params[:ids].present? response = Client.find_by_ids(params[:ids], page: page, sort: sort) else - response = Client.query(params[:query], year: params[:year], provider_id: params[:provider_id], software: params[:software], query_fields: params[:query_fields], page: page, sort: sort) + response = Client.query(params[:query], year: params[:year], provider_id: params[:provider_id], software: params[:software], page: page, sort: sort) end total = response.results.total diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index 386f222cf..99e947750 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -120,7 +120,6 @@ def index prefix: params[:prefix], person_id: params[:person_id], resource_type_id: params[:resource_type_id], - query_fields: params[:query_fields], schema_version: params[:schema_version], link_check_status: params[:link_check_status], link_check_has_schema_org: params[:link_check_has_schema_org], diff --git a/app/controllers/providers_controller.rb b/app/controllers/providers_controller.rb index 6d5cc1eeb..8d77966c5 100644 --- a/app/controllers/providers_controller.rb +++ b/app/controllers/providers_controller.rb @@ -30,7 +30,7 @@ def index elsif params[:ids].present? response = Provider.find_by_ids(params[:ids], page: page, sort: sort) else - response = Provider.query(params[:query], year: params[:year], region: params[:region], organization_type: params[:organization_type], focus_area: params[:focus_area], query_fields: params[:query_fields], page: page, sort: sort) + response = Provider.query(params[:query], year: params[:year], region: params[:region], organization_type: params[:organization_type], focus_area: params[:focus_area], page: page, sort: sort) end total = response.results.total diff --git a/app/models/client.rb b/app/models/client.rb index 5f16f2118..7a3380efe 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -127,9 +127,9 @@ def as_indexed_json(options={}) } end - def self.query_fields - ['symbol^10', 'name^10', 'description^10', 'contact_name^10', 'contact_email^10', 'domains', 'url', 'software^3', 'repository.subjects.text^3', 'repository.certificates.text^3', '_all'] - end + # def self.query_fields + # ['symbol^10', 'name^10', 'description^10', 'contact_name^10', 'contact_email^10', 'domains', 'url', 'software^3', 'repository.subjects.text^3', 'repository.certificates.text^3', '_all'] + # end def self.query_aggregations { diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index 3dc06de11..7f282cc4b 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -111,10 +111,11 @@ def query(query, options={}) sort = options[:sort] end - fields = options[:query_fields].presence || query_fields + # currently not used + # fields = options[:query_fields].presence || query_fields must = [] - must << { multi_match: { query: query, fields: fields, type: "phrase_prefix", slop: 3, max_expansions: 10 }} if query.present? + must << { query_string: { query: query }} if query.present? must << { term: { aasm_state: options[:state] }} if options[:state].present? must << { term: { "types.resourceTypeGeneral": options[:resource_type_id].underscore.camelize }} if options[:resource_type_id].present? must << { terms: { provider_id: options[:provider_id].split(",") }} if options[:provider_id].present? diff --git a/app/models/doi.rb b/app/models/doi.rb index 9230b74c6..9e45a6202 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -319,9 +319,9 @@ def self.query_aggregations } end - def self.query_fields - ['doi^10', 'titles.title^10', 'creator_names^10', 'creators.name^10', 'creators.id^10', 'publisher^10', 'descriptions.description^10', 'types.resourceTypeGeneral^10', 'subjects.subject^10', 'identifiers.identifier^10', 'related_identifiers.relatedIdentifier^10', '_all'] - end + # def self.query_fields + # ['doi^10', 'titles.title^10', 'creator_names^10', 'creators.name^10', 'creators.id^10', 'publisher^10', 'descriptions.description^10', 'types.resourceTypeGeneral^10', 'subjects.subject^10', 'identifiers.identifier^10', 'related_identifiers.relatedIdentifier^10', '_all'] + # end def self.find_by_id(id, options={}) return nil unless id.present? diff --git a/app/models/provider.rb b/app/models/provider.rb index 259c85606..bcdee6860 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -134,9 +134,9 @@ def as_indexed_json(options={}) } end - def self.query_fields - ['symbol^10', 'name^10', 'contact_name^10', 'contact_email^10', '_all'] - end + # def self.query_fields + # ['symbol^10', 'name^10', 'contact_name^10', 'contact_email^10', '_all'] + # end def self.query_aggregations {