Skip to content

Commit

Permalink
support find_by_id for researchers
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jul 22, 2019
1 parent 18bd618 commit ccc329e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/models/researcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ def self.query_fields
['uid^10', 'name^5', 'given_names^5', 'family_name^5', '_all']
end

# return results for one or more ids
def self.find_by_id(ids, options={})
ids = ids.split(",") if ids.is_a?(String)

options[:page] ||= {}
options[:page][:number] ||= 1
options[:page][:size] ||= 1000
options[:sort] ||= { created_at: { order: "asc" }}

__elasticsearch__.search({
from: (options.dig(:page, :number) - 1) * options.dig(:page, :size),
size: options.dig(:page, :size),
sort: [options[:sort]],
query: {
terms: {
uid: ids.map(&:upcase)
}
},
aggregations: query_aggregations
})
end

def self.query_aggregations
{}
end
Expand Down

0 comments on commit ccc329e

Please sign in to comment.