Skip to content

Commit

Permalink
Merge 05adbb3 into bd5191a
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinreiss committed Mar 25, 2015
2 parents bd5191a + 05adbb3 commit 33ae4d1
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 2 deletions.
44 changes: 42 additions & 2 deletions app/service_adaptors/sfx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@
# in response. For TITLE-LEVEL (rather than article-level) requests,
# the roll-up algorithm is sensitive to COVERAGES, and will only suppress
# targets that have coverages included in remaining non-suppressed targets.
# related_title_label: The label prefixed in front of the message denoting a full
# related title.
# preferred_targets: ARRAY of STRINGS containing SFX target names in the form of
# "HIGHWIRE_PRESS_JOURNALS". Any target names listed here will be floated to
# the top of the full-text results list. Multiple matching targets will be displayed
# in alpha order. This fires AFTER 'roll_up_prefixes'
# sunk_targets: ARRAY of STRINGS containing SFX target names in the form of
# "HIGHWIRE_PRESS_JOURNALS". Any target names listed here will be floated to
# the bottom of the full-text results list. Multiple matching targets will be displayed
# in alpha order. This fires AFTER 'roll_up_prefixes'
#
class Sfx < Service
require 'uri'
require 'htmlentities'
Expand Down Expand Up @@ -232,6 +243,7 @@ def parse_response(resolver_response, request)

# For each target delivered by SFX
sfx_obj.search("./ctx_obj_targets/target").each_with_index do|target, target_index|

response_data = {}

# First check @extra_targets_of_interest
Expand Down Expand Up @@ -378,6 +390,8 @@ def parse_response(resolver_response, request)

if response_queue["fulltext"].present?
response_queue["fulltext"] = roll_up_responses(response_queue["fulltext"], :coverage_sensitive => request.title_level_citation? )
response_queue["fulltext"] = sort_preferred_responses(response_queue["fulltext"])
response_queue["fulltext"] = sort_sunk_responses(response_queue["fulltext"])
end

# Now that they've been post-processed, actually commit them.
Expand Down Expand Up @@ -517,6 +531,33 @@ def roll_up_responses(list, options = {})
return list
end

def sort_preferred_responses(list)

preferred_targets = @preferred_targets
return list unless preferred_targets.present?

other_targets = list.reject {|a| preferred_targets.include?(a[:sfx_target_name])}
avail_preferred_targets = list.select {|a| preferred_targets.include?(a[:sfx_target_name])}
avail_preferred_targets = avail_preferred_targets.sort do |item1, item2|
preferred_targets.index(item1[:sfx_target_name]) <=> preferred_targets.index(item2[:sfx_target_name])
end

return avail_preferred_targets + other_targets
end

def sort_sunk_responses(list)

sunk_targets = @sunk_targets
return list unless sunk_targets.present?

better_targets = list.reject {|a| sunk_targets.include?(a[:sfx_target_name])}
available_sunk_targets = list.select {|a| sunk_targets.include?(a[:sfx_target_name])}
available_sunk_targets = available_sunk_targets.sort do |item1, item2|
sunk_targets.index(item1[:sfx_target_name]) <=> sunk_targets.index(item2[:sfx_target_name])
end

return better_targets + available_sunk_targets
end

def sfx_click_passthrough
# From config, or default to false.
Expand Down Expand Up @@ -726,5 +767,4 @@ def sfx_relationship_display(sfx_code)
return display
end

end

end
122 changes: 122 additions & 0 deletions test/unit/sfx/sfx_target_precedence_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
require 'test_helper'
###
### Tests adding the followig config values to the SFX service adaptor
###
### @preferred_targets - float specific targets to the top of full-text options
### @sunk_targets - sink specified targets to the bottom of full-text options

class SfxTargetPrecedenceTest < ActiveSupport::TestCase

def test_preferred_target_appears_first
sfx = Sfx.new({'priority' => 1,
'base_url' => "http://example.org",
'preferred_targets' => ['HIGHWIRE_PRESS_JOURNALS']
})
new_list = sfx.sort_preferred_responses(@@svc_list_example)
assert_not_same @@svc_list_example, new_list

assert_equal new_list.first[:sfx_target_name], 'HIGHWIRE_PRESS_JOURNALS'
end

def test_sunk_target_appears_last
sfx = Sfx.new({'priority' => 1,
'base_url' => "http://example.org",
'sunk_targets' => ['JSTOR_EARLY_JOURNAL_CONTENT_FREE']
})

new_list = sfx.sort_sunk_responses(@@svc_list_example)
assert_not_same @@svc_list_example, new_list
assert_equal new_list.last[:sfx_target_name], 'JSTOR_EARLY_JOURNAL_CONTENT_FREE'
end

def test_preferred_targets_appear_in_order
sfx = Sfx.new({'priority' => 1,
'base_url' => "http://example.org",
'preferred_targets' => ['PROQUEST_CENTRAL_NEW_PLATFORM', 'HIGHWIRE_PRESS_JOURNALS']
})
new_list = sfx.sort_preferred_responses(@@svc_list_example)
assert_not_same @@svc_list_example, new_list
first_target = new_list[0]
second_target = new_list[1]
assert_equal first_target[:sfx_target_name], 'PROQUEST_CENTRAL_NEW_PLATFORM'
assert_equal second_target[:sfx_target_name], 'HIGHWIRE_PRESS_JOURNALS'
end

def test_sunk_targets_appear_in_order
sfx = Sfx.new({'priority' => 1,
'base_url' => "http://example.org",
'sunk_targets' => ['GALEGROUP_GREENR', 'EBSCOHOST_MAS_ULTRA_SCHOOL_EDITION']
})
new_list = sfx.sort_sunk_responses(@@svc_list_example)
assert_not_same @@svc_list_example, new_list
first_target = new_list[-2]
second_target = new_list.last
assert_equal first_target[:sfx_target_name], 'GALEGROUP_GREENR'
assert_equal second_target[:sfx_target_name], 'EBSCOHOST_MAS_ULTRA_SCHOOL_EDITION'
end

@@svc_list_example = [

{ :display_text => "JSTOR Early Journal Content",
:sfx_target_name => "JSTOR_EARLY_JOURNAL_CONTENT_FREE",
:coverage_begin_date => Date.new(1880,1,1),
:coverage_end_date => Date.new(1922,12,31)
},
{ :display_text => "JSTOR_LIFE_SCIENCES_COLLECTION",
:sfx_target_name => "JSTOR_LIFE_SCIENCES_COLLECTION",
:coverage_begin_date => Date.new(1880,1,1),
:coverage_end_date => Date.new(2007,12,31)
},
{ :display_text => "EBSCOHOST_ACADEMIC_SEARCH_COMPLETE",
:sfx_target_name => "EBSCOHOST_ACADEMIC_SEARCH_COMPLETE",
:coverage_begin_date => Date.new(1997,1,1),
:coverage_end_date => Date.new(2010,12,31)
},
{ :display_text => "EBSCOHOST_HEALTH_SOURCE_NURSING_ACADEMIC",
:sfx_target_name => "EBSCOHOST_HEALTH_SOURCE_NURSING_ACADEMIC",
:coverage_begin_date => Date.new(1997,1,1),
:coverage_end_date => Date.new(2004,12,31)
},
{ :display_text => "EBSCOHOST_MAS_ULTRA_SCHOOL_EDITION",
:sfx_target_name => "EBSCOHOST_MAS_ULTRA_SCHOOL_EDITION",
:coverage_begin_date => Date.new(1997,1,1),
:coverage_end_date => Date.new(2006,12,31)
},
{ :display_text => "EBSCOHOST_MASTERFILE_PREMIER",
:sfx_target_name => "EBSCOHOST_MASTERFILE_PREMIER",
:coverage_begin_date => Date.new(1997,1,1),
:coverage_end_date => Date.new(2004,12,31)
},
{ :display_text => "HIGHWIRE_PRESS_JOURNALS",
:sfx_target_name => "HIGHWIRE_PRESS_JOURNALS",
:coverage_begin_date => Date.new(1997,1,1),
:coverage_end_date => Date.new(2006,12,31)
},
{ :display_text => "PROQUEST_CENTRAL_NEW_PLATFORM",
:sfx_target_name => "PROQUEST_CENTRAL_NEW_PLATFORM",
:coverage_begin_date => Date.new(1988,1,1),
:coverage_end_date => Date.new(2005,12,31)
},
{ :display_text => "PROQUEST_ENGINEERING_JOURNALS_NEW_PLATFORM",
:sfx_target_name => "PROQUEST_ENGINEERING_JOURNALS_NEW_PLATFORM",
:coverage_begin_date => Date.new(1980,1,1),
:coverage_end_date => Date.new(2000,12,31)
},
{ :display_text => "PROQUEST_MEDLINE_WITH_FULLTEXT",
:sfx_target_name => "PROQUEST_MEDLINE_WITH_FULLTEXT",
:coverage_begin_date => Date.new(1988,1,1),
:coverage_end_date => Date.new(2005,12,31)
},
{ :display_text => "GALEGROUP_GREENR",
:sfx_target_name => "GALEGROUP_GREENR",
:coverage_begin_date => Date.new(1983,1,1),
:coverage_end_date => Date.new(2005,12,31)
},
{ :display_text => "GALEGROUP_BIOGRAPHY_IN_CONTEXT",
:sfx_target_name => "GALEGROUP_GREENR",
:coverage_begin_date => Date.new(1983,1,1),
:coverage_end_date => Date.new(2005,12,31)
}
]

end

0 comments on commit 33ae4d1

Please sign in to comment.