quick_search-summon_searcher 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +30 -0
  3. data/Rakefile +37 -0
  4. data/app/searchers/quick_search/summon_searcher.rb +215 -0
  5. data/config/initializers/summon_searcher_config.rb +8 -0
  6. data/config/locales/en.yml +11 -0
  7. data/config/routes.rb +2 -0
  8. data/config/summon_config.yml +35 -0
  9. data/lib/quick_search-summon_searcher.rb +5 -0
  10. data/lib/quick_search_summon_searcher/engine.rb +5 -0
  11. data/lib/quick_search_summon_searcher/version.rb +3 -0
  12. data/lib/tasks/quick_search_summon_searcher_tasks.rake +4 -0
  13. data/test/dummy/README.rdoc +28 -0
  14. data/test/dummy/Rakefile +6 -0
  15. data/test/dummy/app/assets/javascripts/application.js +13 -0
  16. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  17. data/test/dummy/app/controllers/application_controller.rb +5 -0
  18. data/test/dummy/app/helpers/application_helper.rb +2 -0
  19. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  20. data/test/dummy/bin/bundle +3 -0
  21. data/test/dummy/bin/rails +4 -0
  22. data/test/dummy/bin/rake +4 -0
  23. data/test/dummy/bin/setup +29 -0
  24. data/test/dummy/config.ru +4 -0
  25. data/test/dummy/config/application.rb +26 -0
  26. data/test/dummy/config/boot.rb +5 -0
  27. data/test/dummy/config/database.yml +25 -0
  28. data/test/dummy/config/environment.rb +5 -0
  29. data/test/dummy/config/environments/development.rb +41 -0
  30. data/test/dummy/config/environments/production.rb +79 -0
  31. data/test/dummy/config/environments/test.rb +42 -0
  32. data/test/dummy/config/initializers/assets.rb +11 -0
  33. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  34. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  35. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  36. data/test/dummy/config/initializers/inflections.rb +16 -0
  37. data/test/dummy/config/initializers/mime_types.rb +4 -0
  38. data/test/dummy/config/initializers/session_store.rb +3 -0
  39. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  40. data/test/dummy/config/locales/en.yml +23 -0
  41. data/test/dummy/config/routes.rb +4 -0
  42. data/test/dummy/config/secrets.yml +22 -0
  43. data/test/dummy/public/404.html +67 -0
  44. data/test/dummy/public/422.html +67 -0
  45. data/test/dummy/public/500.html +66 -0
  46. data/test/dummy/public/favicon.ico +0 -0
  47. data/test/integration/navigation_test.rb +8 -0
  48. data/test/quick_search_summon_searcher_test.rb +7 -0
  49. data/test/test_helper.rb +21 -0
  50. metadata +170 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 849cab8b1ba229f451ea92828c2dea7021637361
4
+ data.tar.gz: d4cdacfdfd9560fc58c66ab3dece06c890d21871
5
+ SHA512:
6
+ metadata.gz: 8d346dfcca4f013605ae8f2cc9ff601fa963941490898c5b258fd8683faf848995b2fabad2ae2f26775ebf9a4a512c38ac407f9f8106150bd7dc8bec6a490094
7
+ data.tar.gz: 8cba9a0dbc28a8294a667e64371e7028294c3ff3b82aae5ea28d773fe71ee1c71a5310c0b379526c85d5e0e33503640e280abb72cd6706c9ab2f9d33ba42b836
@@ -0,0 +1,30 @@
1
+ # QuickSearch Summon Searcher
2
+
3
+ ## Description
4
+
5
+ This is a gem engine implementing a Summon searcher for QuickSearch.
6
+
7
+ In addition to providing Summon results, the searcher can provide:
8
+
9
+ * Spelling Suggestions
10
+ * Related Topics
11
+ * Topic Snippets
12
+
13
+ These services can be enabled / disabled by adding / removing them from the "services" configuration option in summon_config.yml.
14
+
15
+ > Note: This gem was extracted from NCSU Libraries' implementation of QuickSearch, and although some aspects have been made configurable, there may be still be some assumptions baked into the searcher. Issues or pull requests are welcome if you run into this situation.
16
+
17
+
18
+ ## Usage
19
+
20
+ To use, add 'quick_search-summon_searcher' to your QuickSearch Gemfile, add the searcher to quick_search_config.yml, and add a render_module call into the app/views/search/index.html.erb results page.
21
+
22
+ For more general information about setting up searcher plugins in QuickSearch, see https://github.com/NCSU-Libraries/quick_search
23
+
24
+ ## Configuration
25
+
26
+ Configuration for the searcher is found in config/summon_config.yml. To override the default configuration, copy summon_config.yml to your QuickSearch application's config directory: <my_app>/config/searchers/summon_searcher.yml, then modify that version.
27
+
28
+ You need to supply your API keys to summon_config.yml in order to allow the searcher to make requests to the Summon API. Additionally, you'll want to configure the commands and filters that are applied to the API response and link into the Summon search results page respectively. These are also set in summon_config.yml, and map to values for filters in the Summon API URL or search results page URL. You can see examples in the default summon_config.yml: https://www.github.com/ncsu-libraries/quick_search-summon_searcher/blob/master/config/summon_config.yml
29
+
30
+ For more information about commands and filters, look at the Summon API documentation: https://api.summon.serialssolutions.com/help/api/search/commands
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'QuickSearchSummonSearcher'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,215 @@
1
+ module QuickSearch
2
+ class SummonSearcher < QuickSearch::Searcher
3
+
4
+ attr_accessor :spelling_suggestion
5
+
6
+ def search
7
+ url = api_base_url + api_parameters.to_query
8
+ raw_response = @http.get(url, {}, headers)
9
+ @response = JSON.parse(raw_response.body)
10
+ end
11
+
12
+ def results
13
+ if results_list
14
+ results_list
15
+ else
16
+ pages = response['documents']
17
+ @results_list = []
18
+ pages.each do |value|
19
+ result = OpenStruct.new
20
+ result.title = title(value)
21
+ result.link = link(value)
22
+ result.format = format(value)
23
+ result.description = description(value)
24
+ result.citation = true
25
+ result.author = author(value)
26
+ result.date = date(value)
27
+ result.publisher = publisher(value)
28
+ result.volume = volume(value)
29
+ result.issue = issue(value)
30
+ result.pages = pages(value)
31
+ result.fulltext = fulltext(value)
32
+ result.thumbnail = thumbnail(value)
33
+ @results_list << result
34
+ end
35
+ @results_list
36
+ end
37
+ end
38
+
39
+ def loaded_link
40
+ loaded_link_base_url + loaded_link_parameters.to_query
41
+ end
42
+
43
+ def total
44
+ response['recordCount']
45
+ end
46
+
47
+ # This returns the spelling suggestion for the whole app!
48
+ def spelling_suggestion
49
+ unless response['didYouMeanSuggestions'].blank?
50
+ response['didYouMeanSuggestions'][0]['suggestedQuery']
51
+ else
52
+ ""
53
+ end
54
+ end
55
+
56
+ def related_topics
57
+ related_topics = []
58
+ unless response['topicRecommendations'].blank?
59
+ response['topicRecommendations'][0]['relatedTopics'].each do |topic|
60
+ related_topics << topic['title']
61
+ end
62
+ end
63
+ related_topics
64
+ end
65
+
66
+ def topic_snippet
67
+ topic_snippet = {}
68
+ unless response['topicRecommendations'].blank?
69
+ topic_snippet['title'] = response['topicRecommendations'][0]['title']
70
+ topic_snippet['snippet'] = response['topicRecommendations'][0]['snippet']
71
+ topic_snippet['source_name'] = response['topicRecommendations'][0]['sourceName']
72
+ topic_snippet['source_link'] = response['topicRecommendations'][0]['sourceLink']
73
+ end
74
+ topic_snippet
75
+ end
76
+
77
+ private
78
+
79
+ def api_base_url
80
+ QuickSearch::Engine::SUMMON_CONFIG['api_base']
81
+ end
82
+
83
+ def loaded_link_base_url
84
+ QuickSearch::Engine::SUMMON_CONFIG['loaded_link_base']
85
+ end
86
+
87
+ def commands
88
+ QuickSearch::Engine::SUMMON_CONFIG['commands']
89
+ end
90
+
91
+ def filters
92
+ QuickSearch::Engine::SUMMON_CONFIG['filters']
93
+ end
94
+
95
+ def api_parameters
96
+ api_parameters = {
97
+ 's.cmd' => commands.join(' '),
98
+ 's.light' => 'true',
99
+ 's.pn' => '1',
100
+ 's.ps' => @per_page,
101
+ 's.q' => http_request_queries['not_escaped'],
102
+ 's.rec.topic.max' => '1'
103
+ }
104
+
105
+ if @on_campus
106
+ api_parameters['s.role'] = 'authenticated'
107
+ end
108
+
109
+ api_parameters
110
+ end
111
+
112
+ def loaded_link_parameters
113
+ {
114
+ 'fvf' => filters.join('|'),
115
+ 'q' => http_request_queries['not_escaped'],
116
+ 'l' => 'en',
117
+ 'keep_r' => 'true'
118
+ }
119
+ end
120
+
121
+ def headers
122
+ Summon::Transport::Headers.new(
123
+ :url => api_base_url,
124
+ :access_id => QuickSearch::Engine::SUMMON_CONFIG['access_id'],
125
+ :client_key => QuickSearch::Engine::SUMMON_CONFIG['client_key'],
126
+ :secret_key => QuickSearch::Engine::SUMMON_CONFIG['secret_key'],
127
+ :accept => "json",
128
+ :params => api_parameters
129
+ )
130
+ end
131
+
132
+ def format(value)
133
+ value['ContentType'][0] if value['ContentType']
134
+ end
135
+
136
+ def title(value)
137
+ value['Title'][0] if value['Title']
138
+ end
139
+
140
+ def link(value)
141
+ value['link'] if value['link']
142
+ end
143
+
144
+ def description(value)
145
+ value['Abstract'][0] if value['Abstract']
146
+ end
147
+
148
+ def author(value)
149
+ authors = ''
150
+ if value['Author']
151
+ value['Author'].each do |author|
152
+ authors << author if value['Author']
153
+ authors << '; '
154
+ end
155
+ end
156
+ authors.chomp('; ')
157
+ end
158
+
159
+ def date(value)
160
+ value['PublicationDate_xml'][0]['year'] if value['PublicationDate_xml']
161
+ end
162
+
163
+ def publisher(value)
164
+ value['PublicationTitle'][0].titleize if value['PublicationTitle']
165
+ end
166
+
167
+ def volume(value)
168
+ value['Volume'][0] if value['Volume']
169
+ end
170
+
171
+ def issue(value)
172
+ value['Issue'][0] if value['Issue']
173
+ end
174
+
175
+ def fulltext(value)
176
+ value['hasFullText'] ? true : false
177
+ end
178
+
179
+ def page_start(value)
180
+ if value['StartPage']
181
+ Integer(value['StartPage'][0]) rescue nil
182
+ end
183
+ end
184
+
185
+ def page_end(value)
186
+ if value['EndPage']
187
+ Integer(value['EndPage'][0]) rescue nil
188
+ end
189
+ end
190
+
191
+ def pages(value)
192
+ page_start = page_start(value)
193
+ page_end = page_end(value)
194
+ if page_end && page_start && page_end > page_start
195
+ formatted_page = "#{page_start}&nbsp;-&nbsp;#{page_end}"
196
+ elsif page_start
197
+ formatted_page = "#{page_start}"
198
+ end
199
+ end
200
+
201
+ def thumbnail(value)
202
+ if value['thumbnail_s']
203
+ image_size = FastImage.size(value['thumbnail_s'][0], :timeout => 0.1)
204
+ unless image_size.nil?
205
+ if image_size.first > 1
206
+ thumbnail = value['thumbnail_s'][0].sub! "http://www.", "//"
207
+ end
208
+ end
209
+ end
210
+
211
+ thumbnail
212
+ end
213
+
214
+ end
215
+ end
@@ -0,0 +1,8 @@
1
+ # Try to load a local version of the config file if it exists - expected to be in quick_search_root/config/searchers/summon_config.yml
2
+ if File.exists?(File.join(Rails.root, "/config/searchers/summon_config.yml"))
3
+ config_file = File.join Rails.root, "/config/searchers/summon_config.yml"
4
+ else
5
+ # otherwise load the default config file
6
+ config_file = File.expand_path("../../summon_config.yml", __FILE__)
7
+ end
8
+ QuickSearch::Engine::SUMMON_CONFIG = YAML.load_file(config_file)[Rails.env]
@@ -0,0 +1,11 @@
1
+ en:
2
+ summon_search:
3
+ display_name: "Articles"
4
+ short_display_name: "article"
5
+ search_form_placeholder: "Search for articles and book chapters"
6
+ module_callout: "Search Summon for articles and book chapters."
7
+ error_service_message: "searching Summon"
8
+ no_results_service_message: "a different search for articles"
9
+ loaded_link: "https://<institution>.summon.serialssolutions.com/#!/search?fvf=ContentType,Journal%20Article,f%7CContentType,Magazine%20Article,f%7CContentType,Book%20Chapter,f%7CContentType,Trade%20Publication%20Article,f%7CContentType,Journal%20%2F%20eJournal,f%7CLanguage,English,f&l=en&q="
10
+ no_results_link: "http://<institution>.summon.serialssolutions.com/"
11
+
@@ -0,0 +1,2 @@
1
+ QuickSearchSummonSearcher::Engine.routes.draw do
2
+ end
@@ -0,0 +1,35 @@
1
+ defaults: &defaults
2
+ access_id: "summon"
3
+ secret_key: "your secret key here"
4
+ client_key: "your client key here"
5
+ api_base: "http://api.summon.serialssolutions.com/2.0.0/search?"
6
+ loaded_link_base: "http://<your_institution_here>.summon.serialssolutions.com/search?"
7
+ services: [spelling_suggestion, related_topics, topic_snippet]
8
+
9
+ filters:
10
+ - 'ContentType,Journal Article,f'
11
+ - 'ContentType,Magazine Article,f'
12
+ - 'ContentType,Book Chapter,f'
13
+ - 'ContentType,Trade Publication Article,f'
14
+ - 'ContentType,Journal / eJournal,f'
15
+ - 'Language,English,f'
16
+ - 'IsFullText,true,f'
17
+
18
+ commands:
19
+ - 'addFacetValueFilters(ContentType,Journal Article,Journal / eJournal,Book Chapter,Magazine Article,Trade Publication Article)'
20
+ - 'addFacetValueFilters(Language,English)'
21
+ - 'addFacetValueFilters(IsFullText,true)'
22
+ - 'setHoldingsOnly(true)'
23
+
24
+ development:
25
+ <<: *defaults
26
+
27
+ test:
28
+ <<: *defaults
29
+
30
+ staging:
31
+ <<: *defaults
32
+
33
+ production:
34
+ <<: *defaults
35
+
@@ -0,0 +1,5 @@
1
+ require "summon"
2
+ require "quick_search_summon_searcher/engine"
3
+
4
+ module QuickSearchSummonSearcher
5
+ end
@@ -0,0 +1,5 @@
1
+ module QuickSearchSummonSearcher
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace QuickSearchSummonSearcher
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module QuickSearchSummonSearcher
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :quick_search_summon_searcher do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */