Skip to content

Commit

Permalink
use query string queries. #175
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 3, 2019
1 parent 6c7de1b commit e26a574
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/models/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
5 changes: 3 additions & 2 deletions app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
6 changes: 3 additions & 3 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
6 changes: 3 additions & 3 deletions app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit e26a574

Please sign in to comment.