class EBSCO::EDS::Session
Sessions are used to query and retrieve information from the EDS
API.
Constants
- Actions
- Comment
- FacetFilters
Attributes
The session configuration.
Contains search Info
available in the session profile. Includes the sort options, search fields, limiters and expanders available to the profile.
Public Class Methods
Creates a new session.
This can be done in one of two ways:
1. Environment variables¶ ↑
-
EDS_AUTH
- authentication method: 'ip' or 'user' -
EDS_PROFILE
- profile ID for theEDS
API -
EDS_USER
- user id attached to the profile -
EDS_PASS
- user password -
EDS_GUEST
- allow guest access: 'y' or 'n' -
EDS_ORG
- name of your institution or company
Example¶ ↑
Once you have environment variables set, simply create a session like this:
session = EBSCO::EDS::Session.new
2. Options¶ ↑
-
:auth
-
:profile
-
:user
-
:pass
-
:guest
-
:org
Example¶ ↑
session = EBSCO::EDS::Session.new { :auth => 'user', :profile => 'edsapi', :user => 'joe' :pass => 'secret', :guest => false, :org => 'Acme University' }
# File lib/ebsco/eds/session.rb, line 68 def initialize(options = {}) @session_token = '' @citation_token = '' @auth_token = '' @config = {} @guest = true @api_hosts_list = '' @api_host_index = 0 eds_config = EBSCO::EDS::Configuration.new if options[:config] @config = eds_config.configure_with(options[:config]) # return default if there is some problem with the yaml file (bad syntax, not found, etc.) @config = eds_config.configure if @config.nil? else @config = eds_config.configure(options) end # these properties aren't in the config if options.has_key? :user @user = options[:user] elsif ENV.has_key? 'EDS_USER' @user = ENV['EDS_USER'] end if options.has_key? :pass @pass = options[:pass] elsif ENV.has_key? 'EDS_PASS' @pass = ENV['EDS_PASS'] end if options.has_key? :profile @profile = options[:profile] elsif ENV.has_key? 'EDS_PROFILE' @profile = ENV['EDS_PROFILE'] end raise EBSCO::EDS::InvalidParameter, 'Session must specify a valid api profile.' if blank?(@profile) # these config options can be overridden by environment vars @auth_type = (ENV.has_key? 'EDS_AUTH') ? ENV['EDS_AUTH'] : @config[:auth] @org = (ENV.has_key? 'EDS_ORG') ? ENV['EDS_ORG'] : @config[:org] @cache_dir = (ENV.has_key? 'EDS_CACHE_DIR') ? ENV['EDS_CACHE_DIR'] : @config[:eds_cache_dir] @auth_expire = (ENV.has_key? 'EDS_AUTH_CACHE_EXPIRES_IN') ? ENV['EDS_AUTH_CACHE_EXPIRES_IN'] : @config[:auth_cache_expires_in] @info_expire = (ENV.has_key? 'EDS_INFO_CACHE_EXPIRES_IN') ? ENV['EDS_INFO_CACHE_EXPIRES_IN'] : @config[:info_cache_expires_in] @retrieve_expire = (ENV.has_key? 'EDS_RETRIEVE_CACHE_EXPIRES_IN') ? ENV['EDS_RETRIEVE_CACHE_EXPIRES_IN'] : @config[:retrieve_cache_expires_in] @search_expire = (ENV.has_key? 'EDS_SEARCH_CACHE_EXPIRES_IN') ? ENV['EDS_SEARCH_CACHE_EXPIRES_IN'] : @config[:search_cache_expires_in] @export_format_expire = (ENV.has_key? 'EDS_EXPORT_FORMAT_CACHE_EXPIRES_IN') ? ENV['EDS_EXPORT_FORMAT_CACHE_EXPIRES_IN'] : @config[:export_format_cache_expires_in] @citation_styles_expire = (ENV.has_key? 'EDS_CITATION_STYLES_CACHE_EXPIRES_IN') ? ENV['EDS_CITATION_STYLES_CACHE_EXPIRES_IN'] : @config[:citation_styles_cache_expires_in] @log_level = (ENV.has_key? 'EDS_LOG_LEVEL') ? ENV['EDS_LOG_LEVEL'] : @config[:log_level] (ENV.has_key? 'EDS_GUEST') ? if %w(n N no No false False).include?(ENV['EDS_GUEST']) @guest = false else @guest = true end : @guest = @config[:guest] (ENV.has_key? 'EDS_USE_CACHE') ? if %w(n N no No false False).include?(ENV['EDS_USE_CACHE']) @use_cache = false else @use_cache = true end : @use_cache = @config[:use_cache] (ENV.has_key? 'EDS_DEBUG') ? if %w(y Y yes Yes true True).include?(ENV['EDS_DEBUG']) @debug = true else @debug = false end : @debug = @config[:debug] (ENV.has_key? 'EDS_HOSTS') ? @api_hosts_list = ENV['EDS_HOSTS'].split(',') : @api_hosts_list = @config[:api_hosts_list] (ENV.has_key? 'EDS_RECOVER_FROM_BAD_SOURCE_TYPE') ? if %w(y Y yes Yes true True).include?(ENV['EDS_RECOVER_FROM_BAD_SOURCE_TYPE']) @recover_130 = true else @recover_130 = false end : @recover_130 = @config[:recover_from_bad_source_type] # use cache for auth token, info, search and retrieve calls? if @use_cache cache_dir = File.join(@cache_dir, 'faraday_eds_cache') @cache_store = ActiveSupport::Cache::FileStore.new cache_dir end @max_retries = @config[:max_attempts] if options.has_key? :auth_token @auth_token = options[:auth_token] else @auth_token = create_auth_token end if options.key? :session_token @session_token = options[:session_token] else @session_token = create_session_token end if options.key? :citation_token @citation_token = options[:citation_token] else @citation_token = create_citation_token end @info = EBSCO::EDS::Info.new(do_request(:get, path: @config[:info_url]), @config) @current_page = 0 @search_options = nil if @debug if options.key? :caller puts '*** CREATE SESSION CALLER: ' + options[:caller].inspect puts '*** CALLER OPTIONS: ' + options.inspect end puts '*** AUTH TOKEN: ' + @auth_token.inspect puts '*** SESSION TOKEN: ' + @session_token.inspect puts '*** CITATION TOKEN: ' + @citation_token.inspect end end
Public Instance Methods
fetch the citation from the citation rest endpoint
# File lib/ebsco/eds/session.rb, line 341 def get_citation_exports(dbid:, an:, format: 'all') begin # only available as non-guest otherwise 148 error citation_exports_params = "?an=#{an}&dbid=#{dbid}&format=#{format}" citation_exports_response = do_request(:get, path: @config[:citation_exports_url] + citation_exports_params) EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: citation_exports_response, eds_config: @config) rescue EBSCO::EDS::NotFound => e custom_error_message = JSON.parse e.message.gsub('=>', ':') # ErrorNumber 132 - Record not found if custom_error_message['ErrorNumber'] == '132' record_not_found = {"Format"=>format, "Label"=>"", "Data"=>"", "Error"=>"Record not found"} EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: record_not_found, eds_config: @config) end rescue EBSCO::EDS::BadRequest => e custom_error_message = JSON.parse e.message.gsub('=>', ':') # ErrorNumber 112 - Invalid Argument Value if custom_error_message['ErrorNumber'] == '112' unknown_export_format = {"Format"=>format, "Label"=>"", "Data"=>"", "Error"=>"Invalid citation export format"} EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: unknown_export_format, eds_config: @config) else unknown_error = {"Format"=>format, "Label"=>"", "Data"=>"", "Error"=>custom_error_message['ErrorDescription']} EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: unknown_error, eds_config: @config) end end end
get citation exports for a list of result ids
# File lib/ebsco/eds/session.rb, line 401 def get_citation_exports_list(id_list: [], format: 'all') citations = [] if id_list.any? id_list.each { |id| dbid = id.split('__',2).first accession = id.split('__',2).last citations.push get_citation_exports(dbid: dbid, an: accession, format: format) } end citations end
fetch the citation from the citation rest endpoint
# File lib/ebsco/eds/session.rb, line 368 def get_citation_styles(dbid:, an:, format: 'all') begin citation_styles_params = "?an=#{an}&dbid=#{dbid}&styles=#{format}" citation_styles_response = do_request(:get, path: @config[:citation_styles_url] + citation_styles_params) EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: citation_styles_response, eds_config: @config) rescue EBSCO::EDS::NotFound => e custom_error_message = JSON.parse e.message.gsub('=>', ':') # ErrorNumber 132 - Record not found if custom_error_message['ErrorNumber'] == '132' record_not_found = {"Format"=>format, "Label"=>"", "Data"=>"", "Error"=>"Record not found"} EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: record_not_found, eds_config: @config) end rescue EBSCO::EDS::BadRequest => e custom_error_message = JSON.parse e.message.gsub('=>', ':') unknown_error = {"Id"=>format, "Label"=>"", "Data"=>"", "Error"=>custom_error_message['ErrorDescription']} EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: unknown_error, eds_config: @config) end end
get citation styles for a list of result ids
# File lib/ebsco/eds/session.rb, line 388 def get_citation_styles_list(id_list: [], format: 'all') citations = [] if id_list.any? id_list.each { |id| dbid = id.split('__',2).first accession = id.split('__',2).last citations.push get_citation_styles(dbid: dbid, an: accession, format: format) } end citations end
# File lib/ebsco/eds/session.rb, line 481 def solr_retrieve_list(list: [], highlight: nil) records = [] if list.any? list.each.with_index(1) { |id, index| dbid = id.split('__',2).first accession = id.split('__',2).last begin current_rec = retrieve(dbid: dbid, an: accession, highlight: highlight, ebook: @config[:ebook_preferred_format]) current_rec.eds_result_id = index records.push current_rec rescue EBSCO::EDS::BadRequest, EBSCO::EDS::NotFound => e puts "Request for #{id} in #{self.class.name}#solr_retrieve_list failed with #{e}" if @debug end } end r = empty_results(records.length) results = EBSCO::EDS::Results.new(r, @config) results.records = records results.to_solr end
Create a result set with just the record before and after the current detailed record
# File lib/ebsco/eds/session.rb, line 414 def solr_retrieve_previous_next(options = {}) rid = options['previous-next-index'] # set defaults if missing if options['page'].nil? options['page'] = '1' end if options['per_page'].nil? options['per_page'] = '20' end rpp = options['per_page'].to_i # determine result page and update options goto_page = rid / rpp if (rid % rpp) > 0 goto_page += 1 end options['page'] = goto_page.to_s pnum = options['page'].to_i max = rpp * pnum min = max - rpp + 1 result_index = rid - min cached_results = search(options, false, false) cached_results_found = cached_results.stat_total_hits # last result in set, get next result if rid == max options_next = options options_next['page'] = cached_results.page_number+1 next_result_set = search(options_next, false, false) result_next = next_result_set.records.first else unless rid == cached_results_found result_next = cached_results.records[result_index+1] end end if result_index == 0 # first result in set that's not the very first result, get previous result if rid != 1 options_previous = options options_previous['page'] = cached_results.page_number-1 previous_result_set = search(options_previous, false, false) result_prev = previous_result_set.records.last end else result_prev = cached_results.records[result_index-1] end # return json result set with just the previous and next records in it r = empty_results(cached_results.stat_total_hits) results = EBSCO::EDS::Results.new(r, @config) next_previous_records = [] unless result_prev.nil? next_previous_records << result_prev end unless result_next.nil? next_previous_records << result_next end results.records = next_previous_records results.to_solr end
Private Instance Methods
helper methods
# File lib/ebsco/eds/session.rb, line 1199 def blank?(var) var.nil? || var.respond_to?(:length) && var.empty? end
# File lib/ebsco/eds/session.rb, line 1141 def citation_connection logger = Logger.new(@config[:log]) logger.level = Logger.const_get(@log_level) Faraday.new(url: 'https://' + @api_hosts_list[@api_host_index]) do |conn| conn.headers['Content-Type'] = 'application/json;charset=UTF-8' conn.headers['Accept'] = 'application/json' conn.headers['x-sessionToken'] = @citation_token ? @citation_token : '' conn.headers['x-authenticationToken'] = @auth_token ? @auth_token : '' conn.headers['User-Agent'] = @config[:user_agent] conn.request :url_encoded conn.use :eds_caching_middleware, store: @cache_store, auth_expire: @auth_expire, info_expire: @info_expire, search_expire: @search_expire, retrieve_expire: @retrieve_expire, export_format_expire: @export_format_expire, citation_styles_expire: @citation_styles_expire, logger: @debug ? logger : nil if @use_cache conn.use :eds_exception_middleware conn.response :json, content_type: /\bjson$/ conn.response :detailed_logger, logger if @debug conn.options[:open_timeout] = @config[:open_timeout] conn.options[:timeout] = @config[:timeout] conn.adapter :net_http_persistent end end
# File lib/ebsco/eds/session.rb, line 1093 def connection logger = Logger.new(@config[:log]) logger.level = Logger.const_get(@log_level) Faraday.new(url: 'https://' + @api_hosts_list[@api_host_index]) do |conn| conn.headers['Content-Type'] = 'application/json;charset=UTF-8' conn.headers['Accept'] = 'application/json' conn.headers['x-sessionToken'] = @session_token ? @session_token : '' conn.headers['x-authenticationToken'] = @auth_token ? @auth_token : '' conn.headers['User-Agent'] = @config[:user_agent] conn.request :url_encoded conn.use :eds_caching_middleware, store: @cache_store, auth_expire: @auth_expire, info_expire: @info_expire, search_expire: @search_expire, retrieve_expire: @retrieve_expire, export_format_expire: @export_format_expire, citation_styles_expire: @citation_styles_expire, logger: @debug ? logger : nil if @use_cache conn.use :eds_exception_middleware conn.response :json, content_type: /\bjson$/ conn.response :detailed_logger, logger if @debug conn.options[:open_timeout] = @config[:open_timeout] conn.options[:timeout] = @config[:timeout] conn.adapter :net_http_persistent end end
# File lib/ebsco/eds/session.rb, line 1169 def create_auth_token if blank?(@auth_token) # ip auth if (blank?(@user) && blank?(@pass)) || @auth_type.casecmp('ip').zero? resp = do_request(:post, path: @config[:ip_auth_url]) # user auth else resp = do_request(:post, path: @config[:uid_auth_url], payload: { UserId: @user, Password: @pass, InterfaceId: @config[:interface_id] }) end end @auth_token = resp['AuthToken'] @auth_token end
# File lib/ebsco/eds/session.rb, line 1192 def create_citation_token resp = do_request(:get, path: @config[:create_session_url] + '?profile=' + @profile + '&guest=n&displaydatabasename=y') @citation_token = resp['SessionToken'] end
# File lib/ebsco/eds/session.rb, line 1184 def create_session_token guest_string = @guest ? 'y' : 'n' resp = do_request(:get, path: @config[:create_session_url] + '?profile=' + @profile + '&guest=' + guest_string + '&displaydatabasename=y') @session_token = resp['SessionToken'] end
# File lib/ebsco/eds/session.rb, line 1252 def eds_sanitize(str) pattern = /([)(:,])/ str = str.gsub(pattern){ |match| '\\' + match } str end
used to reliably create empty results when there are no search terms provided
# File lib/ebsco/eds/session.rb, line 1204 def empty_results(hits = 0) { 'SearchRequest'=> { 'SearchCriteria'=> { 'Queries'=>nil, 'SearchMode'=>'', 'IncludeFacets'=>'y', 'Sort'=>'relevance', 'AutoSuggest'=>'n', 'AutoCorrect'=>'n' }, 'RetrievalCriteria'=> { 'View'=>'brief', 'ResultsPerPage'=>20, 'Highlight'=>'y', 'IncludeImageQuickView'=>'n' }, 'SearchCriteriaWithActions'=> { 'QueriesWithAction'=>nil } }, 'SearchResult'=> { 'Statistics'=> { 'TotalHits'=>hits, 'TotalSearchTime'=>0, 'Databases'=>[] }, 'Data'=> {'RecordFormat'=>'EP Display'}, 'AvailableCriteria'=>{'DateRange'=>{'MinDate'=>'0001-01', 'MaxDate'=>'0001-01'}} } } end
generate a cache id for search and retrieve post requests, using a hash of the payload + guest mode
# File lib/ebsco/eds/session.rb, line 1244 def get_cache_id(path, payload) if path == '/edsapi/rest/Search' or path == '/edsapi/rest/Retrieve' '?cache_id=' + Digest::MD5.hexdigest(payload + @guest.to_s) else '' end end
# File lib/ebsco/eds/session.rb, line 1258 def get_jump_pages(search_options) dest_page = search_options.RetrievalCriteria.PageNumber.to_i jump_incr = 250/search_options.RetrievalCriteria.ResultsPerPage.to_i attempts = dest_page/jump_incr jump_pages = [] (1..attempts).to_a.each do |n| jump_pages.push(jump_incr*n) end puts 'JUMP PAGES: ' + jump_pages.inspect if @debug jump_pages end
same as above but no caching
# File lib/ebsco/eds/session.rb, line 1122 def jump_connection logger = Logger.new(@config[:log]) logger.level = Logger.const_get(@log_level) Faraday.new(url: 'https://' + @api_hosts_list[@api_host_index]) do |conn| conn.headers['Content-Type'] = 'application/json;charset=UTF-8' conn.headers['Accept'] = 'application/json' conn.headers['x-sessionToken'] = @session_token ? @session_token : '' conn.headers['x-authenticationToken'] = @auth_token ? @auth_token : '' conn.headers['User-Agent'] = @config[:user_agent] conn.request :url_encoded conn.use :eds_exception_middleware conn.response :json, content_type: /\bjson$/ conn.response :detailed_logger, logger if @debug conn.options[:open_timeout] = @config[:open_timeout] conn.options[:timeout] = @config[:timeout] conn.adapter :net_http_persistent end end
Expander Methods
↑ topPublic Instance Methods
Removes all specified expanders and sets the page number back to 1. Returns search Results
.
# File lib/ebsco/eds/session.rb, line 760 def clear_expanders add_actions 'ClearExpanders()' end
Facet Methods
↑ topPublic Instance Methods
Adds a facet filter to the search request. Sets the page number back to 1. Returns search Results
.
Examples¶ ↑
results = session.add_facet('Publisher', 'wiley-blackwell') results = session.add_facet('SubjectEDS', 'water quality')
# File lib/ebsco/eds/session.rb, line 688 def add_facet(facet_id, facet_val) facet_val = eds_sanitize(facet_val) add_actions "AddFacetFilter(#{facet_id}:#{facet_val})" end
Removes all specified facet filters. Sets the page number back to 1. Returns search Results
.
# File lib/ebsco/eds/session.rb, line 677 def clear_facets add_actions 'ClearFacetFilters()' end
Removes a specific facet filter value from a group. Sets the page number back to 1. Returns search Results
.
Examples¶ ↑
results = session.remove_facet_value(2, 'DE', 'Psychology')
# File lib/ebsco/eds/session.rb, line 707 def remove_facet_value(group_id, facet_id, facet_val) add_actions "RemoveFacetFilterValue(#{group_id},#{facet_id}:#{facet_val})" end
Limiter Methods
↑ topPublic Instance Methods
Clears all currently specified limiters and sets the page number back to 1. Returns search Results
.
# File lib/ebsco/eds/session.rb, line 720 def clear_limiters add_actions 'ClearLimiters()' end
Pagination Methods
↑ topPublic Instance Methods
Get a specified page of results Returns search Results
.
# File lib/ebsco/eds/session.rb, line 649 def get_page(page = 1) add_actions "GoToPage(#{page})" end
Increments the current results page number by the value specified. If the current page was 5 and the specified value was 2, the page number would be set to 7. Returns search Results
.
# File lib/ebsco/eds/session.rb, line 657 def move_page(num) add_actions "MovePage(#{num})" end
Get the next page of results. Returns search Results
.
# File lib/ebsco/eds/session.rb, line 634 def next_page page = @current_page + 1 get_page(page) end
Get the previous page of results. Returns search Results
.
# File lib/ebsco/eds/session.rb, line 642 def prev_page get_page([1, @current_page - 1].sort.last) end
Get the first page of results. Returns search Results
.
# File lib/ebsco/eds/session.rb, line 664 def reset_page add_actions 'ResetPaging()' end
Profile Settings Methods
↑ topPublic Instance Methods
Determine if a database ID is available in the profile. Returns Boolean.
# File lib/ebsco/eds/session.rb, line 1073 def dbid_in_profile(dbid) get_available_database_ids.include? dbid end
Get a list of all available database IDs. Returns Array of IDs.
# File lib/ebsco/eds/session.rb, line 1066 def get_available_database_ids get_available_databases.map{|item| item[:id]} end
Determine if publication matching is available in the profile. Returns Boolean.
# File lib/ebsco/eds/session.rb, line 1080 def publication_match_in_profile @info.available_related_content_types.include? 'emp' end
Determine if research starters are available in the profile. Returns Boolean.
# File lib/ebsco/eds/session.rb, line 1087 def research_starters_match_in_profile @info.available_related_content_types.include? 'rs' end
Publication Methods
↑ topPublic Instance Methods
Removes all publications from the search. Sets the page number back to 1. Returns search Results
.
# File lib/ebsco/eds/session.rb, line 807 def remove_all_publications add_actions 'RemovePublication()' end
Removes a publication from the search. Sets the page number back to 1. Returns search Results
.
# File lib/ebsco/eds/session.rb, line 800 def remove_publication(pub_id) add_actions "RemovePublication(#{pub_id})" end
Search & Retrieve Methods
↑ topPublic Instance Methods
Add a query to the search request. When a query is added, it will be assigned an ordinal, which will be exposed in the search response message. It also removes any specified facet filters and sets the page number to 1. Returns search Results
.
Examples¶ ↑
results = session.add_query('AND,California')
# File lib/ebsco/eds/session.rb, line 531 def add_query(query) add_actions "AddQuery(#{query})" end
Clears all queries and facet filters, and set the page number back to 1; limiters and expanders are not modified. Returns search Results
.
# File lib/ebsco/eds/session.rb, line 521 def clear_queries add_actions 'ClearQueries()' end
Clear all specified query expressions, facet filters, limiters and expanders, and set the page number back to 1. Returns search Results
.
# File lib/ebsco/eds/session.rb, line 514 def clear_search add_actions 'ClearSearch()' end
Invalidates the session token. End Session
should be called when you know a user has logged out.
# File lib/ebsco/eds/session.rb, line 504 def end # todo: catch when there is no valid session? do_request(:post, path: @config[:end_session_url], payload: {:SessionToken => @session_token}) connection.headers['x-sessionToken'] = '' @session_token = '' end
Removes query from the currently specified search. It also removes any specified facet filters and sets the page number to 1. Returns search Results
.
Examples¶ ↑
results = session.remove_query(1)
# File lib/ebsco/eds/session.rb, line 541 def remove_query(query_id) add_actions "removequery(#{query_id})" end
Returns a Record
based a particular result based on a database ID and accession number.
Attributes¶ ↑
-
:dbid
- The database ID (required). -
:an
- The accession number (required). -
highlight
- Comma separated list of terms to highlight in the data records (optional). -
ebook
- Preferred format to return ebook content in. Either ebook-pdf (default) or ebook-pdf.
Examples¶ ↑
record = session.retrieve({dbid: 'asn', an: '108974507'})
# File lib/ebsco/eds/session.rb, line 325 def retrieve(dbid:, an:, highlight: nil, ebook: 'ebook-pdf') payload = { DbId: dbid, An: an, HighlightTerms: highlight, EbookPreferredFormat: ebook } retrieve_response = do_request(:post, path: @config[:retrieve_url], payload: payload) record = EBSCO::EDS::Record.new(retrieve_response, @config) record_citation_exports = get_citation_exports({dbid: dbid, an: an, format: @config[:citation_exports_formats]}) unless record_citation_exports.nil? record.set_citation_exports(record_citation_exports) end record_citation_styles = get_citation_styles({dbid: dbid, an: an, format: @config[:citation_styles_formats]}) unless record_citation_styles.nil? record.set_citation_styles(record_citation_styles) end record end
Performs a search.
Returns search Results
.
Options¶ ↑
-
:query
- Required. The search terms. Format: {booleanOperator},{fieldCode}:{term}. Example: SU:Hiking -
:mode
- Search mode to be used. Either: all (default), any, bool, smart -
:results_per_page
- The number of records retrieved with the search results (between 1-100, default is 20). -
:page
- Starting page number for the result set returned from a search (if results per page = 10, and page number = 3 , this implies: I am expecting 10 records starting at page 3). -
:sort
- The sort order for the search results. Either: relevance (default), oldest, newest -
:highlight
- Specifies whether or not the search term is highlighted using <highlight /> tags. Either true or false. -
:include_facets
- Specifies whether or not the search term is highlighted using <highlight /> tags. Either true (default) or false. -
:facet_filters
- Facets to apply to the search. Facets are used to refine previous search results. Format: {filterID},{facetID}:{value}[,{facetID}:{value}]* Example: 1,SubjectEDS:food,SubjectEDS:fiction -
:view
- Specifies the amount of data to return with the response. Either 'title': title only; 'brief' (default): Title + Source, Subjects; 'detailed': Brief + full abstract -
:actions
-Actions
to take on the existing query specification. Example: addfacetfilter(SubjectGeographic:massachusetts) -
:limiters
- Criteria to limit the search results by. Example: LA99:English,French,German -
:expanders
- Expanders that can be applied to the search. Either: thesaurus, fulltext, relatedsubjects -
:publication_id
- Publication to search within. -
:related_content
- Comma separated list of related content types to return with the search results. Either 'rs' (Research Starters) or 'emp' (Exact Publication Match) -
:auto_suggest
- Specifies whether or not to return search suggestions along with the search results. Either true or false (default).
Examples¶ ↑
results = session.search({query: 'abraham lincoln', results_per_page: 5, related_content: ['rs','emp']}) results = session.search({query: 'volcano', results_per_page: 1, publication_id: 'eric', include_facets: false})
# File lib/ebsco/eds/session.rb, line 224 def search(options = {}, add_actions = false, increment_page = true) # use existing/updated SearchOptions if options.empty? if @search_options.nil? @search_results = EBSCO::EDS::Results.new(empty_results,@config) else _response = do_request(:post, path: '/edsapi/rest/Search', payload: @search_options) @search_results = EBSCO::EDS::Results.new(_response, @config, @info.available_limiters, options) if increment_page @current_page = @search_results.page_number end @search_results end else # Only perform a search when there are query terms since certain EDS profiles will throw errors when # given empty queries if (options.keys & %w[query q]).any? || options.has_key?(:query) # create/recreate the search options if nil or not passing actions if @search_options.nil? || !add_actions @search_options = EBSCO::EDS::Options.new(options, @info) end _response = do_request(:post, path: '/edsapi/rest/Search', payload: @search_options) @search_results = EBSCO::EDS::Results.new(_response, @config, @info.available_limiters, options) if @search_results.stat_total_hits.to_i == 0 && @config[:smarttext_failover] == true @search_options.add_actions('SetSearchMode(smart)', @info) _response = do_request(:post, path: '/edsapi/rest/Search', payload: @search_options) @search_results = EBSCO::EDS::Results.new(_response, @config, @info.available_limiters, options, true) end # create temp format facet results if needed if options['f'] if options['f'].key?('eds_publication_type_facet') format_options = options.dup format_options['f'] = options['f'].except('eds_publication_type_facet') format_search_options = EBSCO::EDS::Options.new(format_options, @info) format_search_options.Comment = 'temp source type facets' _format_response = do_request(:post, path: '/edsapi/rest/Search', payload: format_search_options) @search_results.temp_format_facet_results = EBSCO::EDS::Results.new(_format_response, @config, @info.available_limiters, format_options) end end # create temp content provider facet results if needed if options['f'] if options['f'].key?('eds_content_provider_facet') content_options = options.dup content_options['f'] = options['f'].except('eds_content_provider_facet') content_search_options = EBSCO::EDS::Options.new(content_options, @info) content_search_options.Comment = 'temp content provider facet' _content_response = do_request(:post, path: '/edsapi/rest/Search', payload: content_search_options) @search_results.temp_content_provider_facet_results = EBSCO::EDS::Results.new(_content_response, @config, @info.available_limiters, content_options) end end if increment_page @current_page = @search_results.page_number end @search_results else @search_results = EBSCO::EDS::Results.new(empty_results, @config) end end end
Setter Methods
↑ topPublic Instance Methods
Sets the sort for the search. The available sorts for the specified databases can be obtained from the session’s info attribute. Sets the page number back to 1. Returns search Results
.
Examples¶ ↑
results = session.set_sort('newest')
# File lib/ebsco/eds/session.rb, line 561 def set_sort(val) add_actions "SetSort(#{val})" end