Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/models/search_eds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class SearchEds
EDS_URL = ENV['EDS_URL'].freeze
EDS_NO_ALEPH_PROFILE = ENV['EDS_NO_ALEPH_PROFILE'].freeze
EDS_ALEPH_PROFILE = ENV['EDS_ALEPH_PROFILE'].freeze
RESULTS_PER_BOX = ENV['RESULTS_PER_BOX'] || 3

def initialize
@auth_token = uid_auth
Expand Down Expand Up @@ -75,9 +76,9 @@ def relationships(record)

def search_url(term)
[EDS_URL, '/edsapi/rest/Search?query=', URI.escape(term).to_s,
'&searchmode=all', '&resultsperpage=3', '&pagenumber=1', '&sort=relevance',
'&highlight=n', '&includefacets=n', '&view=brief',
'&autosuggest=n'].join('')
'&searchmode=all', "&resultsperpage=#{RESULTS_PER_BOX}",
'&pagenumber=1', '&sort=relevance', '&highlight=n', '&includefacets=n',
'&view=brief', '&autosuggest=n'].join('')
end

def search_filtered(term)
Expand Down
6 changes: 5 additions & 1 deletion app/models/search_google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# - GOOGLE_API_KEY
# - GOOGLE_CUSTOM_SEARCH_ID
#
# == Optional Environment Variables:
# - RESULTS_PER_BOX
#
# == See Also
# - https://developers.google.com/custom-search/json-api/v1/overview
# - https://github.com/google/google-api-ruby-client
Expand All @@ -25,7 +28,8 @@ def initialize
def search(term)
@results['raw_google'] = @service.list_cses(
term,
cx: ENV['GOOGLE_CUSTOM_SEARCH_ID']
cx: ENV['GOOGLE_CUSTOM_SEARCH_ID'],
num: ENV['RESULTS_PER_BOX'] || 3
)
to_result(@results['raw_google'])
end
Expand Down
4 changes: 2 additions & 2 deletions test/models/search_google_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class SearchGoogleTest < ActiveSupport::TestCase
test 'valid google search with valid credentials returns results' do
VCR.use_cassette('valid google search and credentials') do
query = SearchGoogle.new.search('endnote')
assert_equal(1640, query['total'])
assert_equal(1610, query['total'])
end
end

Expand Down Expand Up @@ -69,7 +69,7 @@ class SearchGoogleTest < ActiveSupport::TestCase
test 'handles pages with no metadata' do
VCR.use_cassette('google no metadata') do
query = SearchGoogle.new.search('weather patterns')
assert_equal(87, query['total'])
assert_equal(88, query['total'])
end
end
end
184 changes: 15 additions & 169 deletions test/vcr_cassettes/google_no_metadata.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 10 additions & 12 deletions test/vcr_cassettes/google_no_results.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/vcr_cassettes/invalid_google_credentials.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading