Class: BentoSearch::ScopusEngine
- Inherits:
-
Object
- Object
- BentoSearch::ScopusEngine
- Extended by:
- HTTPClientPatch::IncludeClient
- Includes:
- SearchEngine
- Defined in:
- app/search_engines/bento_search/scopus_engine.rb
Overview
Supports fielded searching, sorting, pagination.
Required configuration:
-
api_key
Defaults to ‘relevance’ sort, rather than scopus’s default of date desc.
Uses the Scopus SciVerse REST API. You need to be a Scopus customer to access. api.elsevier.com www.developers.elsevier.com/action/devprojects
ToS: www.developers.elsevier.com/devcms/content-policies “Federated Search” use case. Also: www.developers.elsevier.com/cms/apiserviceagreement
Note that ToS applying to you probably means you must restrict access to search functionality to authenticated affiliated users only.
Register for an API key at “Register New Site” at developers.elsevier.com/action/devnewsite You will then need to get server IP addresses registered with Scopus too, apparently by emailing directly to dave.santucci at elsevier dot com.
Scopus API Docs:
-
www.developers.elsevier.com/devcms/content-api-search-request
-
www.developers.elsevier.com/devcms/content/search-fields-overview
Some more docs on response elements and query elements:
Other API’s in the suite not being used by this code at present:
-
www.developers.elsevier.com/devcms/content-api-retrieval-request
-
www.developers.elsevier.com/devcms/content-api-metadata-request
Support: [email protected]
TODO: Mention to Scopus: Only one author? Paging of 50 gets an error, but docs say I should be able to request 200. q
Scopus response does not seem to include language of hit, even though api allows you to restrict by language. ask scopus if we’re missing something?
Constant Summary
Constants included from SearchEngine
BentoSearch::SearchEngine::DefaultPerPage
Class Method Summary collapse
Instance Method Summary collapse
-
#escape_query(query) ⇒ Object
The escaping rules are not entirely clear for the API.
-
#max_per_page ⇒ Object
Max per-page is 200, as per www.developers.elsevier.com/devcms/content-apis, bottom of page.
- #search_field_definitions ⇒ Object
- #search_implementation(args) ⇒ Object
- #sort_definitions ⇒ Object
Methods included from HTTPClientPatch::IncludeClient
Methods included from SearchEngine
#fill_in_search_metadata_for, #initialize, #normalized_search_arguments, #public_settable_search_args, #search
Methods included from BentoSearch::SearchEngine::Capabilities
#search_keys, #semantic_search_keys, #semantic_search_map, #sort_keys
Class Method Details
.default_configuration ⇒ Object
179 180 181 182 183 184 |
# File 'app/search_engines/bento_search/scopus_engine.rb', line 179 def self.default_configuration { :base_url => "http://api.elsevier.com/", :cluster => "SCOPUS" } end |
.required_configuration ⇒ Object
175 176 177 |
# File 'app/search_engines/bento_search/scopus_engine.rb', line 175 def self.required_configuration ["api_key"] end |
Instance Method Details
#escape_query(query) ⇒ Object
The escaping rules are not entirely clear for the API. We know colons and parens are special chars. It’s unclear how or if we can escape them, we’ll just remove them.
166 167 168 169 170 171 172 |
# File 'app/search_engines/bento_search/scopus_engine.rb', line 166 def escape_query(query) # backslash escape doesn't seem to work #query.gsub(/([\\\(\)\:])/) do |match| # "\\#{$1}" #end query.gsub(/([\\\(\)\:])/, ' ') end |
#max_per_page ⇒ Object
Max per-page is 200, as per www.developers.elsevier.com/devcms/content-apis, bottom of page.
187 188 189 |
# File 'app/search_engines/bento_search/scopus_engine.rb', line 187 def max_per_page 200 end |
#search_field_definitions ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 |
# File 'app/search_engines/bento_search/scopus_engine.rb', line 191 def search_field_definitions { nil => {:semantic => :general}, "AUTH" => {:semantic => :author}, "TITLE" => {:semantic => :title}, # controlled and author-assigned keywords "KEY" => {:semantic => :subject}, "ISBN" => {:semantic => :isbn}, "ISSN" => {:semantic => :issn}, } end |
#search_implementation(args) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/search_engines/bento_search/scopus_engine.rb', line 53 def search_implementation(args) results = Results.new xml, response, exception = nil, nil, nil url = scopus_url(args) begin response = http_client.get( url , nil, # HTTP headers. {"X-ELS-APIKey" => configuration.api_key, "X-ELS-ResourceVersion" => "XOCS", "Accept" => "application/atom+xml"} ) xml = Nokogiri::XML(response.body) rescue TimeoutError, HTTPClient::ConfigurationError, HTTPClient::BadResponseError, Nokogiri::SyntaxError => e exception = e end # handle errors if (response.nil? || xml.nil? || exception || (! HTTP::Status.successful? response.status) || xml.at_xpath("service-error") ) # UGH. Scopus reports 0 hits as an error, not entirely distinguishable # from an actual error. Oh well, we have to go with it. if ( (response.status == 400) && xml && (error_xml = xml.at_xpath("./service-error/status")) && (node_text(error_xml.at_xpath("./statusCode")) == "INVALID_INPUT") && (node_text(error_xml.at_xpath("./statusText")).starts_with? "Result set was empty") ) # PROBABLY 0 hit count, although could be something else I'm afraid. results.total_items = 0 return results else # real error results.error ||= {} results.error[:exception] = e results.error[:status] = response.status if response # keep from storing the entire possibly huge response as error # but sometimes it's an error message. results.error[:error_info] = xml.at_xpath("service_error") if xml return results end end results.total_items = (node_text xml.at_xpath("//opensearch:totalResults", xml_ns)).to_i xml.xpath("//atom:entry", xml_ns).each do | entry | results << (item = ResultItem.new) if scopus_link = entry.at_xpath("atom:link[@ref='scopus']", xml_ns) item.link = scopus_link["href"] end item.unique_id = node_text entry.at_xpath("dc:identifier", xml_ns) item.title = node_text entry.at_xpath("dc:title", xml_ns) item.journal_title = node_text entry.at_xpath("prism:publicationName", xml_ns) item.issn = node_text entry.at_xpath("prism:issn", xml_ns) item.volume = node_text entry.at_xpath("prism:volume", xml_ns) item.issue = node_text entry.at_xpath("prism:issueIdentifier", xml_ns) item.doi = node_text entry.at_xpath("prism:doi", xml_ns) # pages might be in startingPage/endingPage OR in pageRange if (start = entry.at_xpath("prism:startingPage", xml_ns)) item.start_page = start.text.to_i if ( epage = entry.at_xpath("prism:endingPage", xml_ns)) item.end_page = epage.text.to_i end elsif (range = entry.at_xpath("prism:pageRange", xml_ns)) (spage, epage) = *range.text().split("-") item.start_page = spage item.end_page = epage end # get the year out of the date if date = entry.at_xpath("prism:coverDate", xml_ns) date.text =~ /^(\d\d\d\d)/ item.year = $1.to_i if $1 end # Authors might be in atom:authors seperated by |, or just # a single one in dc:creator if ( = entry.at_xpath("atom:authors", xml_ns)) .text.split("|").each do || item. << Author.new(:display => .strip) end elsif ( = entry.at_xpath("dc:creator", xml_ns)) item. << Author.new(:display => .text.strip) end # Format we're still trying to figure out how Scopus API # delivers it. Here is at at least one way. if (doctype = entry.at_xpath("atom:subtype", xml_ns)) item.format = doctype_to_format(doctype.text) item.format_str = doctype_to_string(doctype.text) end end return results end |
#sort_definitions ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'app/search_engines/bento_search/scopus_engine.rb', line 203 def sort_definitions # scopus &sort= values, not yet URI-escaped, later code will do that. # # 'refeid' key is currently undocumented on Scopus site, but # was given to me in email by scopus. { "title_asc" => {:implementation => "+itemtitle"}, "date_desc" => {:implementation => "-datesort,+auth"}, "relevance" => {:implementation => "refeid" }, "author_asc" => {:implementation => "+auth"}, "num_cite_desc" => {:implementation => "-numcitedby"} } end |