Skip to content

Commit

Permalink
SFX, change preferred_targets config to
Browse files Browse the repository at this point in the history
  • Loading branch information
jrochkind committed Mar 25, 2015
1 parent d5edbb4 commit bddb787
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions app/service_adaptors/sfx.rb
Expand Up @@ -42,9 +42,9 @@
# 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.
# preferred_targets: ARRAY of STRINGS containing SFX target names in the form of
# boosted_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. You can end your preferred target
# the top of the full-text results list. You can end your boosted target
# in a "*" to wildcard: "EBSCOHOST_*". 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
Expand Down Expand Up @@ -390,7 +390,7 @@ 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_boosted_responses(response_queue["fulltext"])
response_queue["fulltext"] = sort_sunk_responses(response_queue["fulltext"])
end

Expand Down Expand Up @@ -531,13 +531,13 @@ def roll_up_responses(list, options = {})
return list
end

def sort_preferred_responses(list)
return list unless @preferred_targets.present?
def sort_boosted_responses(list)
return list unless @boosted_targets.present?

preferred = []
other_targets = list

@preferred_targets.each do |spec|
@boosted_targets.each do |spec|
(picked, other_targets) = other_targets.partition do |a|
if spec.end_with?("*")
a[:sfx_target_name].start_with? spec[0..-2]
Expand Down
20 changes: 10 additions & 10 deletions test/unit/sfx/sfx_target_precedence_test.rb
Expand Up @@ -2,29 +2,29 @@
###
### Tests adding the followig config values to the SFX service adaptor
###
### @preferred_targets - float specific targets to the top of full-text options
### @boosted_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
def test_boosted_target_appears_first
sfx = Sfx.new({'priority' => 1,
'base_url' => "http://example.org",
'preferred_targets' => ['HIGHWIRE_PRESS_JOURNALS']
'boosted_targets' => ['HIGHWIRE_PRESS_JOURNALS']
})
new_list = sfx.sort_preferred_responses(@@svc_list_example)
new_list = sfx.sort_boosted_responses(@@svc_list_example)
assert_not_same @@svc_list_example, new_list
assert_equal @@svc_list_example.length, new_list.length

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

def test_preferred_wildcard
def test_boosted_wildcard
sfx = Sfx.new({'priority' => 1,
'base_url' => "http://example.org",
'preferred_targets' => ['GALEGROUP_*']
'boosted_targets' => ['GALEGROUP_*']
})
new_list = sfx.sort_preferred_responses(@@svc_list_example)
new_list = sfx.sort_boosted_responses(@@svc_list_example)
assert_not_same @@svc_list_example, new_list

assert_equal new_list.first[:sfx_target_name], 'GALEGROUP_GREENR'
Expand Down Expand Up @@ -57,12 +57,12 @@ def test_sunk_wildcard
assert_equal new_list.last[:sfx_target_name], 'PROQUEST_MEDLINE_WITH_FULLTEXT'
end

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

0 comments on commit bddb787

Please sign in to comment.