Skip to content

Exports and the get by unique_id feature

Jonathan Rochkind edited this page May 9, 2013 · 11 revisions

Bento_search includes an RISCreator class that can be used to serialize any individual BentoSearch::ResultItem to the RIS format, which can then be imported into EndNote, used for RefWorks export, etc.

    results  = some_engine.search("something")
    item     = results.first
    ris_data = RISCreator.new( item ).export 

Other export format translations may be provided later, as needed.

However, using this to actually implement export in a web app can be tricky, because of how a user's transactional flow works in a web app. You'll usually first fetch results and display them to users, and perhaps display them along with an 'export' link. When the user clicks the export link, and issues a new request to your app -- at that point the app has to figure out what record they were interested in and get an object representing it, so it can be translated to (eg) RIS.

Bento_search provides a feature where each record can be given an engine-specific unique_id, which can then be used to fetch a record by unique_id. This feature can come in handy for providing exports. You can set up an action in your app that takes a unique id, and create a url routing to it using an individual records unique_id, which might look something like:

 bento_record_path( bento_item.unique_id )

Then in that hypothetical bento_record action, you can take the unique id and fetch the single record from the remote service:

 def get
   bento_item = BentoSearch.get_engine("my_engine").get(params[:id])
   respond_to do |format|
      #....
      format.ris {   RISCreator.new( bento_item ).export  }
   end
 end

You might want to register the RIS mime type with your app for this to work smoothly, eg in your ./config/initializers/mime_types.rb, Mime::Type.register "application/x-research-info-systems", :ris

Not every engine supports #unique_id or the #get(unique_id) function -- look in engine source code, or check some_engine.respond_to?(:get). If an engine supports #get, it ought to support #unique_id too, but some engines may support #unique_id without #get.

Refworks Export

Refworks accepts imports (to Refworks) in multiple formats, including the RIS Format, which is quite well supported. So you can use the export to RIS feature to transfer to refworks. See Refworks own documentation at http://www.refworks.com/DirectExport.htm

Use &filter=RIS%20Format and &encoding=65001 (UTF8, BentoSearch RIS exports should be UTF8).

You supply a callback URL to Refworks, a URL where Refworks can connect back to your app and get one or more records in RIS format. A convenient way to construct your app is such that the callback url has one oe more record unique_ids embedded in it, possibly along with the registered engine id -- so the app can refetch the record and serialize it out as RIS.

An added challenge with Refworks exports, however, is around authentication. If you are using bento_search with an engine whose results can only be shown to authenticated users, then normally you protect actions revealing these results, requiring authentication. But the callback URL can't require authentication, or Refworks couldn't get to it. But if you do not require any authentication here, than if a third party knew of the refworks callback URL, they could use it to download metadata that they ought not to have access to.

There are a variety of possible solutions here. One creative one I am currently using is to encrypt the unique_id in the refworks callback URL, using the Rails ActiveSupport::MessageEncryptor functionalty. This approach is demo'd in the sample_megasearch demo app, for instance implemented in this commit.

See also more info in my blog post