bento_search 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.md +299 -0
- data/Rakefile +40 -0
- data/app/assets/images/bento_search/large_loader.gif +0 -0
- data/app/assets/javascripts/bento_search.js +3 -0
- data/app/assets/javascripts/bento_search/ajax_load.js +22 -0
- data/app/assets/stylesheets/bento_search/bento.css +4 -0
- data/app/controllers/bento_search/bento_search_controller.rb +7 -0
- data/app/controllers/bento_search/search_controller.rb +72 -0
- data/app/helpers/bento_search_helper.rb +138 -0
- data/app/item_decorators/bento_search/only_premade_openurl.rb +16 -0
- data/app/item_decorators/bento_search/openurl_add_other_link.rb +35 -0
- data/app/item_decorators/bento_search/openurl_main_link.rb +30 -0
- data/app/models/bento_search/author.rb +25 -0
- data/app/models/bento_search/link.rb +30 -0
- data/app/models/bento_search/multi_searcher.rb +109 -0
- data/app/models/bento_search/openurl_creator.rb +128 -0
- data/app/models/bento_search/registrar.rb +70 -0
- data/app/models/bento_search/result_item.rb +203 -0
- data/app/models/bento_search/results.rb +54 -0
- data/app/models/bento_search/results/pagination.rb +67 -0
- data/app/models/bento_search/search_engine.rb +219 -0
- data/app/models/bento_search/search_engine/capabilities.rb +65 -0
- data/app/search_engines/bento_search/#Untitled-1# +11 -0
- data/app/search_engines/bento_search/ebsco_host_engine.rb +356 -0
- data/app/search_engines/bento_search/eds_engine.rb +557 -0
- data/app/search_engines/bento_search/google_books_engine.rb +184 -0
- data/app/search_engines/bento_search/primo_engine.rb +231 -0
- data/app/search_engines/bento_search/scopus_engine.rb +295 -0
- data/app/search_engines/bento_search/summon_engine.rb +398 -0
- data/app/search_engines/bento_search/xerxes_engine.rb +168 -0
- data/app/views/bento_search/_link.html.erb +4 -0
- data/app/views/bento_search/_search_error.html.erb +22 -0
- data/app/views/bento_search/_std_item.html.erb +39 -0
- data/app/views/bento_search/search/search.html.erb +1 -0
- data/config/locales/en.yml +25 -0
- data/lib/bento_search.rb +29 -0
- data/lib/bento_search/engine.rb +5 -0
- data/lib/bento_search/routes.rb +45 -0
- data/lib/bento_search/version.rb +3 -0
- data/lib/generators/bento_search/pull_ebsco_dbs_generator.rb +24 -0
- data/lib/generators/bento_search/templates/ebsco_global_var.erb +6 -0
- data/lib/http_client_patch/include_client.rb +86 -0
- data/lib/tasks/bento_search_tasks.rake +4 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +56 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +6 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +3100 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/functional/bento_search/search_controller_test.rb +81 -0
- data/test/helper/bento_search_helper_test.rb +125 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/support/mock_engine.rb +23 -0
- data/test/support/test_with_cassette.rb +38 -0
- data/test/test_helper.rb +52 -0
- data/test/unit/#vcr_test.rb# +68 -0
- data/test/unit/ebsco_host_engine_test.rb +134 -0
- data/test/unit/eds_engine_test.rb +105 -0
- data/test/unit/google_books_engine_test.rb +93 -0
- data/test/unit/item_decorators_test.rb +66 -0
- data/test/unit/multi_searcher_test.rb +49 -0
- data/test/unit/openurl_creator_test.rb +111 -0
- data/test/unit/pagination_test.rb +59 -0
- data/test/unit/primo_engine_test.rb +37 -0
- data/test/unit/register_engine_test.rb +50 -0
- data/test/unit/result_item_display_test.rb +39 -0
- data/test/unit/result_item_test.rb +36 -0
- data/test/unit/scopus_engine_test.rb +130 -0
- data/test/unit/search_engine_base_test.rb +178 -0
- data/test/unit/search_engine_test.rb +95 -0
- data/test/unit/summon_engine_test.rb +161 -0
- data/test/unit/xerxes_engine_test.rb +70 -0
- data/test/vcr_cassettes/ebscohost/error_bad_db.yml +45 -0
- data/test/vcr_cassettes/ebscohost/error_bad_password.yml +45 -0
- data/test/vcr_cassettes/ebscohost/get_info.yml +3626 -0
- data/test/vcr_cassettes/ebscohost/live_search.yml +45 -0
- data/test/vcr_cassettes/ebscohost/live_search_smoke_test.yml +1311 -0
- data/test/vcr_cassettes/eds/basic_search_smoke_test.yml +1811 -0
- data/test/vcr_cassettes/eds/get_auth_token.yml +75 -0
- data/test/vcr_cassettes/eds/get_auth_token_failure.yml +39 -0
- data/test/vcr_cassettes/eds/get_with_auth.yml +243 -0
- data/test/vcr_cassettes/eds/get_with_auth_recovers_from_bad_auth.yml +368 -0
- data/test/vcr_cassettes/gbs/error_condition.yml +40 -0
- data/test/vcr_cassettes/gbs/pagination.yml +702 -0
- data/test/vcr_cassettes/gbs/search.yml +340 -0
- data/test/vcr_cassettes/primo/search_smoke_test.yml +1112 -0
- data/test/vcr_cassettes/scopus/bad_api_key_should_return_error_response.yml +60 -0
- data/test/vcr_cassettes/scopus/escaped_chars.yml +187 -0
- data/test/vcr_cassettes/scopus/fielded_search.yml +176 -0
- data/test/vcr_cassettes/scopus/simple_search.yml +227 -0
- data/test/vcr_cassettes/scopus/zero_results_search.yml +67 -0
- data/test/vcr_cassettes/summon/bad_auth.yml +54 -0
- data/test/vcr_cassettes/summon/proper_tags_for_snippets.yml +216 -0
- data/test/vcr_cassettes/summon/search.yml +242 -0
- data/test/vcr_cassettes/xerxes/live_search.yml +2580 -0
- data/test/view/std_item_test.rb +98 -0
- metadata +421 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ParseSearchArgumentsTest < ActiveSupport::TestCase
|
|
4
|
+
class Dummy
|
|
5
|
+
include BentoSearch::SearchEngine
|
|
6
|
+
|
|
7
|
+
def search_implementation(args)
|
|
8
|
+
# no-op for now
|
|
9
|
+
BentoSearch::Results.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_parse(*args)
|
|
13
|
+
# original method is protected, this is a lame way
|
|
14
|
+
# to expose it.
|
|
15
|
+
parse_search_arguments(*args)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def max_per_page
|
|
19
|
+
40
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def search_field_definitions
|
|
23
|
+
{
|
|
24
|
+
"my_title" => {:semantic => :title},
|
|
25
|
+
"my_author" => {:semantic => :author},
|
|
26
|
+
"my_other" => nil
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_single_arg
|
|
34
|
+
d = Dummy.new
|
|
35
|
+
|
|
36
|
+
args = d.test_parse("query")
|
|
37
|
+
|
|
38
|
+
assert_equal( {:query => "query", :per_page => BentoSearch::SearchEngine::DefaultPerPage }, args )
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_two_arg
|
|
42
|
+
d = Dummy.new
|
|
43
|
+
|
|
44
|
+
args = d.test_parse("query", :arg => "1")
|
|
45
|
+
|
|
46
|
+
assert_equal( {:query => "query", :arg => "1", :per_page => BentoSearch::SearchEngine::DefaultPerPage }, args )
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_convert_page_to_start
|
|
52
|
+
d = Dummy.new
|
|
53
|
+
|
|
54
|
+
args = d.test_parse(:query => "query", :page => 1, :per_page => 20)
|
|
55
|
+
|
|
56
|
+
assert_equal 0, args[:start]
|
|
57
|
+
assert_equal 1, args[:page]
|
|
58
|
+
assert_equal 20, args[:per_page]
|
|
59
|
+
|
|
60
|
+
args = d.test_parse(:query => "query", :page => 3, :per_page => 20)
|
|
61
|
+
|
|
62
|
+
assert_equal 40, args[:start]
|
|
63
|
+
assert_equal 3, args[:page]
|
|
64
|
+
assert_equal 20, args[:per_page]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_convert_start_to_page
|
|
68
|
+
d = Dummy.new
|
|
69
|
+
|
|
70
|
+
# rounds down to get closest 'page' if need be.
|
|
71
|
+
args = d.test_parse(:query => "query", :start => '19', :per_page => '20')
|
|
72
|
+
|
|
73
|
+
assert_equal 19, args[:start]
|
|
74
|
+
assert_equal 1, args[:page]
|
|
75
|
+
|
|
76
|
+
args = d.test_parse(:query => "query", :start => '20', :per_page => '20')
|
|
77
|
+
assert_equal 2, args[:page]
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_pagination_to_integer
|
|
82
|
+
d = Dummy.new
|
|
83
|
+
|
|
84
|
+
args = d.test_parse(:query => "query", :page => "1", :per_page => "20")
|
|
85
|
+
assert_equal 0, args[:start]
|
|
86
|
+
assert_equal 1, args[:page]
|
|
87
|
+
assert_equal 20, args[:per_page]
|
|
88
|
+
|
|
89
|
+
args = d.test_parse(:query => "query", :start => "20", :per_page => "20")
|
|
90
|
+
assert_equal 20, args[:start]
|
|
91
|
+
assert_equal 20, args[:per_page]
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def test_ignore_blank_pagination_args
|
|
96
|
+
d = Dummy.new
|
|
97
|
+
|
|
98
|
+
args = d.test_parse(:query => "query", :page => "", :per_page => "", :start => "")
|
|
99
|
+
|
|
100
|
+
assert ! (args.has_key? :page)
|
|
101
|
+
assert ! (args.has_key? :start)
|
|
102
|
+
assert (args.has_key? :per_page) # default per page always provided
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_enforce_max_per_page
|
|
106
|
+
d = Dummy.new
|
|
107
|
+
|
|
108
|
+
assert_raise(ArgumentError) { d.test_parse(:query => "query", :per_page => 1000) }
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def test_search_field_keys
|
|
112
|
+
assert_equal ["my_title", "my_author", "my_other"], Dummy.new.search_keys
|
|
113
|
+
assert_equal ["title", "author"], Dummy.new.semantic_search_keys
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def test_semantic_search_map
|
|
117
|
+
assert_equal( {"title" => "my_title", "author" => "my_author"},
|
|
118
|
+
Dummy.new.semantic_search_map)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def test_translate_search_field_semantics
|
|
122
|
+
d = Dummy.new
|
|
123
|
+
|
|
124
|
+
args = d.test_parse(:query => "query", :semantic_search_field => :title)
|
|
125
|
+
|
|
126
|
+
assert ! (args.has_key? :semantic_search_field), "translates semantic_search_field to search_field"
|
|
127
|
+
assert_equal "my_title", args[:search_field]
|
|
128
|
+
|
|
129
|
+
assert_raise(ArgumentError, "Raises for undefined semantic_search_field") do
|
|
130
|
+
d.test_parse(:query => "query", :semantic_search_field => :subject)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def test_semantic_blank_ignored
|
|
135
|
+
d = Dummy.new
|
|
136
|
+
|
|
137
|
+
args1 = d.test_parse(:query => "query", :semantic_search_field => nil)
|
|
138
|
+
args2 = d.test_parse(:query => "query", :semantic_search_field => nil)
|
|
139
|
+
|
|
140
|
+
assert_nil args1[:search_field]
|
|
141
|
+
assert_nil args2[:search_field]
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def test_semantic_string_or_symbol
|
|
145
|
+
d = Dummy.new
|
|
146
|
+
|
|
147
|
+
args1 = d.test_parse(:query => "query", :semantic_search_field => :title)
|
|
148
|
+
args2 = d.test_parse(:query => "query", :semantic_search_field => "title")
|
|
149
|
+
|
|
150
|
+
assert_equal args1, args2
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def test_converts_sort_to_string
|
|
154
|
+
d = Dummy.new
|
|
155
|
+
|
|
156
|
+
args = d.test_parse(:query => "query", :sort => :title_asc)
|
|
157
|
+
|
|
158
|
+
assert_equal "title_asc", args[:sort]
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def test_sets_timing
|
|
162
|
+
d = Dummy.new
|
|
163
|
+
results = d.search("foo")
|
|
164
|
+
|
|
165
|
+
assert_not_nil results.timing
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def test_passes_arbitrary_keys
|
|
169
|
+
d = Dummy.new
|
|
170
|
+
args = d.test_parse(:query => "foo", :custom_auth => true)
|
|
171
|
+
|
|
172
|
+
assert_present args[:custom_auth]
|
|
173
|
+
assert_equal true, args[:custom_auth]
|
|
174
|
+
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
end
|
|
178
|
+
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SearchEngineTest < ActiveSupport::TestCase
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
@dummy_class = Class.new do
|
|
9
|
+
include BentoSearch::SearchEngine
|
|
10
|
+
|
|
11
|
+
def self.required_configuration
|
|
12
|
+
["required.key"]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def search_implementation(arguments)
|
|
16
|
+
#no-op for now
|
|
17
|
+
BentoSearch::Results.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
test "takes configuration" do
|
|
25
|
+
conf = Confstruct::Configuration.new( :foo => "foo", :bar => "bar", :required => {:key => "required key"} )
|
|
26
|
+
engine = @dummy_class.new(conf)
|
|
27
|
+
|
|
28
|
+
assert_not_nil engine.configuration
|
|
29
|
+
assert_equal engine.configuration.foo, "foo"
|
|
30
|
+
assert_equal engine.configuration.bar, "bar"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
test "required configuration keys" do
|
|
34
|
+
conf = Confstruct::Configuration.new( :foo => "foo", :bar => "bar" )
|
|
35
|
+
assert_raise ArgumentError do
|
|
36
|
+
@dummy_class.new(conf)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
test "merges default configuration" do
|
|
41
|
+
@dummy_class = Class.new do
|
|
42
|
+
include BentoSearch::SearchEngine
|
|
43
|
+
def self.default_configuration
|
|
44
|
+
{ :one => "default",
|
|
45
|
+
:two => "default",
|
|
46
|
+
:array => [:a, :b, :c],
|
|
47
|
+
:nested => {:one => "default", :two => "default"}
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
engine = @dummy_class.new( :two => "new", :array => ["one", "two"], :nested => {:two => "new"}, :required => {:key => "required key"} )
|
|
53
|
+
|
|
54
|
+
assert_kind_of Confstruct::Configuration, engine.configuration
|
|
55
|
+
assert_equal "default" , engine.configuration.one
|
|
56
|
+
assert_equal "new" , engine.configuration.two
|
|
57
|
+
assert_equal "default" , engine.configuration.nested.one
|
|
58
|
+
assert_equal "new" , engine.configuration.nested.two
|
|
59
|
+
assert_equal ["one", "two"] , engine.configuration.array
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
test "no default configuration" do
|
|
63
|
+
@dummy_class = Class.new do
|
|
64
|
+
include BentoSearch::SearchEngine
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
engine = @dummy_class.new( :one => "one" )
|
|
68
|
+
|
|
69
|
+
assert_kind_of Confstruct::Configuration, engine.configuration
|
|
70
|
+
assert_equal "one", engine.configuration.one
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
test "sets metadata on results" do
|
|
74
|
+
engine = MockEngine.new(:id => "foo")
|
|
75
|
+
|
|
76
|
+
results = engine.search(:query => "cancer", :per_page => 20)
|
|
77
|
+
|
|
78
|
+
assert_present results.search_args
|
|
79
|
+
assert_equal "foo", results.engine_id
|
|
80
|
+
|
|
81
|
+
pagination = results.pagination
|
|
82
|
+
assert_present pagination
|
|
83
|
+
|
|
84
|
+
assert_equal 20, pagination.per_page
|
|
85
|
+
assert_equal 1, pagination.current_page
|
|
86
|
+
assert_equal 1, pagination.start_record
|
|
87
|
+
assert_equal 20, pagination.end_record
|
|
88
|
+
assert pagination.first_page?
|
|
89
|
+
|
|
90
|
+
assert_present pagination.total_pages
|
|
91
|
+
assert_present pagination.count_records
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
end
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
require 'cgi'
|
|
4
|
+
require 'uri'
|
|
5
|
+
|
|
6
|
+
#
|
|
7
|
+
# To run queries live (without recorded VCR), you must have ENV variables
|
|
8
|
+
# set: SUMMON_ACCESS_ID and SUMMON_SECRET_KEY
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SummonEngineTest < ActiveSupport::TestCase
|
|
12
|
+
extend TestWithCassette
|
|
13
|
+
|
|
14
|
+
@@access_id = (ENV['SUMMON_ACCESS_ID'] || "DUMMY_ACCESS_ID")
|
|
15
|
+
@@secret_key = (ENV['SUMMON_SECRET_KEY'] || "DUMMY_SECRET_KEY")
|
|
16
|
+
|
|
17
|
+
VCR.configure do |c|
|
|
18
|
+
c.filter_sensitive_data("DUMMY_ACCESS_ID", :summon) { @@access_id }
|
|
19
|
+
c.filter_sensitive_data("DUMMY_SECRET_KEY", :summon) { @@secret_key }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def setup
|
|
23
|
+
@engine = BentoSearch::SummonEngine.new('access_id' => @@access_id,
|
|
24
|
+
'secret_key' => @@secret_key)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_request_construction
|
|
28
|
+
uri, headers = @engine.construct_request(:query => "elephant's")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
assert_present headers
|
|
32
|
+
assert_present headers["Content-Type"]
|
|
33
|
+
assert_present headers["Accept"]
|
|
34
|
+
assert_present headers["x-summon-date"]
|
|
35
|
+
assert_present headers["Authorization"]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
assert_present uri
|
|
39
|
+
query_params = CGI.parse( URI.parse(uri).query )
|
|
40
|
+
assert_present query_params["s.q"]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_summon_escape
|
|
44
|
+
uri, headers = @engine.construct_request(:query=> "Foo: A) \\Bar \"a phrase\"")
|
|
45
|
+
|
|
46
|
+
query_params = CGI.parse( URI.parse(uri).query )
|
|
47
|
+
|
|
48
|
+
assert_present (query = query_params["s.q"].first)
|
|
49
|
+
|
|
50
|
+
# double backslashes are escaping for ruby string literal,
|
|
51
|
+
# it's actually only a single backslash in output.
|
|
52
|
+
assert_equal "Foo\\: A\\) \\\\Bar \"a phrase\"", query
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_sort_construction
|
|
56
|
+
uri, headers = @engine.construct_request(:query => "elephants", :sort => "date_desc")
|
|
57
|
+
|
|
58
|
+
query_params = CGI.parse( URI.parse(uri).query )
|
|
59
|
+
|
|
60
|
+
assert_present (sort = query_params["s.sort"].first )
|
|
61
|
+
|
|
62
|
+
assert_equal("PublicationDate:desc", sort)
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_fielded_search_construction
|
|
67
|
+
uri, headers = @engine.construct_request(:query => "eleph)ants", :search_field => "SomeField")
|
|
68
|
+
|
|
69
|
+
query_params = CGI.parse( URI.parse(uri).query )
|
|
70
|
+
|
|
71
|
+
assert_equal "SomeField:(eleph\\\)ants)", query_params["s.q"].first
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_pagination_construction
|
|
75
|
+
uri, headers = @engine.construct_request(:query => "elephants_per_page", :per_page => 20, :page => 2)
|
|
76
|
+
|
|
77
|
+
query_params = CGI.parse( URI.parse(uri).query )
|
|
78
|
+
|
|
79
|
+
assert_equal "20", query_params["s.ps"].first
|
|
80
|
+
assert_equal "2", query_params["s.pn"].first
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_authenticated_user_construction
|
|
84
|
+
uri, headers = @engine.construct_request(:query => "elephants", :auth => true)
|
|
85
|
+
|
|
86
|
+
query_params = CGI.parse( URI.parse(uri).query )
|
|
87
|
+
|
|
88
|
+
assert_present query_params['s.role']
|
|
89
|
+
assert_equal "authenticated", query_params['s.role'].first
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def test_construct_fixed_param_config
|
|
93
|
+
engine = BentoSearch::SummonEngine.new('access_id' => @@access_id,
|
|
94
|
+
'secret_key' => @@secret_key,
|
|
95
|
+
'fixed_params' => {
|
|
96
|
+
"s.fvf" => ["ContentType,Newspaper Article,true", "ContentType,Book,true"],
|
|
97
|
+
"s.role" => "authenticated"
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
uri, headers = engine.construct_request(:query => "elephants")
|
|
101
|
+
|
|
102
|
+
query_params = CGI.parse( URI.parse(uri).query )
|
|
103
|
+
|
|
104
|
+
assert_include query_params["s.fvf"], "ContentType,Newspaper Article,true"
|
|
105
|
+
assert_include query_params["s.fvf"], "ContentType,Book,true"
|
|
106
|
+
assert_include query_params["s.role"], "authenticated"
|
|
107
|
+
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_construct_no_highlighting
|
|
111
|
+
engine = BentoSearch::SummonEngine.new('access_id' => @@access_id,
|
|
112
|
+
'secret_key' => @@secret_key,
|
|
113
|
+
'highlighting' => false)
|
|
114
|
+
|
|
115
|
+
uri, headers = engine.construct_request(:query => "elephants")
|
|
116
|
+
|
|
117
|
+
query_params = CGI.parse( URI.parse(uri).query )
|
|
118
|
+
|
|
119
|
+
assert_include query_params['s.hl'], "false"
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
test_with_cassette("bad auth", :summon) do
|
|
123
|
+
engine = BentoSearch::SummonEngine.new('access_id' => "bad_access_id", :secret_key => 'bad_secret_key')
|
|
124
|
+
|
|
125
|
+
results = engine.search("elephants")
|
|
126
|
+
|
|
127
|
+
assert results.failed?, "should return #failed?"
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
test_with_cassette("search", :summon) do
|
|
132
|
+
results = @engine.search("elephants")
|
|
133
|
+
|
|
134
|
+
assert ! results.failed?
|
|
135
|
+
|
|
136
|
+
assert_present results
|
|
137
|
+
|
|
138
|
+
assert_present results.total_items
|
|
139
|
+
assert_not_equal 0, results.total_items
|
|
140
|
+
|
|
141
|
+
first = results.first
|
|
142
|
+
|
|
143
|
+
assert_present first.title
|
|
144
|
+
assert_present first.format_str
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
test_with_cassette("proper tags for snippets", :summon) do
|
|
148
|
+
results = @engine.search("cancer")
|
|
149
|
+
|
|
150
|
+
first = results.first
|
|
151
|
+
|
|
152
|
+
assert_include first.title, '<b class="bento_search_highlight">'
|
|
153
|
+
|
|
154
|
+
assert first.title.html_safe?, "title is HTML safe"
|
|
155
|
+
|
|
156
|
+
assert_present first.custom_data['raw_title']
|
|
157
|
+
assert_not_include first.custom_data['raw_title'], '<b class="bento_search_highlight">'
|
|
158
|
+
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
require 'cgi'
|
|
4
|
+
require 'uri'
|
|
5
|
+
|
|
6
|
+
# If you need to re-record cassette, you need to REMOVE
|
|
7
|
+
# the :refresh_wait => 0 below, along with
|
|
8
|
+
# the :record => once in the use_cassette
|
|
9
|
+
class XerxesEngineTest < ActiveSupport::TestCase
|
|
10
|
+
extend TestWithCassette
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
conf = Confstruct::Configuration.new( :base_url => "http://jhsearch.library.jhu.edu/",
|
|
14
|
+
:databases => ["JHU04066","JHU06614"] ,
|
|
15
|
+
# when we have a VCR recorded, we don't need to wait
|
|
16
|
+
# if re-recording, change this key to nil.
|
|
17
|
+
:refresh_wait => 0
|
|
18
|
+
)
|
|
19
|
+
@engine = BentoSearch::XerxesEngine.new( conf )
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_construct_xerxes_url
|
|
24
|
+
url = @engine.send(:xerxes_search_url, {:query => "skin disease"})
|
|
25
|
+
|
|
26
|
+
uri = nil
|
|
27
|
+
assert_nothing_raised { uri = URI.parse(url) }
|
|
28
|
+
|
|
29
|
+
assert uri.to_s.start_with?(@engine.configuration.base_url), "starts with base_url"
|
|
30
|
+
|
|
31
|
+
query_hash = CGI.parse( uri.query )
|
|
32
|
+
|
|
33
|
+
assert_equal ["metasearch"], query_hash["base"]
|
|
34
|
+
assert_equal ["search"], query_hash["action"]
|
|
35
|
+
#assert_equal [@engine.configuration.xerxes_context], query_hash["context"]
|
|
36
|
+
assert_equal ["WRD"], query_hash["field"]
|
|
37
|
+
assert_equal ["skin disease"],query_hash["query"]
|
|
38
|
+
|
|
39
|
+
@engine.configuration.databases.each do |db|
|
|
40
|
+
assert query_hash["database"].include?( db )
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
test_with_cassette("live search", :xerxes, :record => :none) do
|
|
45
|
+
results = @engine.search("skin disease")
|
|
46
|
+
|
|
47
|
+
assert results.length > 0, "returns results"
|
|
48
|
+
|
|
49
|
+
record = results.first
|
|
50
|
+
|
|
51
|
+
assert_present record.title
|
|
52
|
+
assert_present record.format
|
|
53
|
+
assert_present record.link
|
|
54
|
+
assert_present record.volume
|
|
55
|
+
assert_present record.issue
|
|
56
|
+
assert_present record.start_page
|
|
57
|
+
assert_present record.end_page
|
|
58
|
+
assert_present record.abstract
|
|
59
|
+
assert_present record.openurl_kev_co
|
|
60
|
+
assert_present record.journal_title
|
|
61
|
+
assert_present record.issn
|
|
62
|
+
|
|
63
|
+
assert_operator record.authors.length, :>, 0
|
|
64
|
+
|
|
65
|
+
assert_present record.authors.first.first
|
|
66
|
+
assert_present record.authors.first.last
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|