ebsco-eds 0.0.4.pre → 0.0.5.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81a61b693843d786e5274cf56b1799c439f07586
4
- data.tar.gz: cd7e51b21d87a8d7dac6c1dd1d306d81b5105316
3
+ metadata.gz: 43e9ebad04e9e0aaa2b87f2e25d10e1cfad40934
4
+ data.tar.gz: 94e000ec7b6f2ccac3514dfa6fce6c567df90d76
5
5
  SHA512:
6
- metadata.gz: 0078e01f8ca86d2d84f8720a4f70ff983e4c02f8e929f29f76b8214e7bb08d3d4feb13a557ef32bb864b621e19212a0e00bddb1f754f839ddb737bb220dcf289
7
- data.tar.gz: 3ecbc29fd10cf728fcad1ea885b65fef5cd14d4003b0f8797d76e00b76944e91a153e3d34df4d8dcf7b0929f54487fb3e85da859d8c8f7e535665da56c640ed8
6
+ metadata.gz: debbac1ad692666481d61fafe2c67fb667bd44f6c3f6de810720f96caea1da7569632193e20760a7abb151a9eb63baf2de7fe3ed168ffdf64816eea6c3fc7496
7
+ data.tar.gz: 8c30c14fee4443d7403985ccb9fa58c7e5c21c49666813c0836378439eeebb91ce4f655a028b8764f1a31a8230cab485cb1987f758a2d42d16d685af32503f5b
data/.env.test CHANGED
@@ -1,6 +1,6 @@
1
- EDS_PROFILE=eds-api
2
- EDS_USER=billmckinn
3
- EDS_PASS=4n~r1me86y
1
+ EDS_PROFILE=edsapi
2
+ EDS_USER=user
3
+ EDS_PASS=secret
4
4
  EDS_AUTH=user
5
5
  EDS_GUEST=n
6
6
  EDS_ORG=none
@@ -1,6 +1,7 @@
1
1
  require 'yaml'
2
2
  require 'json'
3
3
  require 'bibtex'
4
+ require 'cgi'
4
5
 
5
6
  module EBSCO
6
7
 
@@ -35,9 +36,9 @@ module EBSCO
35
36
  .fetch('BibRelationships', {})
36
37
 
37
38
  @bib_part = @record.fetch('RecordInfo', {})
38
- .fetch('BibRecord', {})
39
- .fetch('BibRelationships', {})
40
- .fetch('IsPartOfRelationships', {})[0]
39
+ .fetch('BibRecord', {})
40
+ .fetch('BibRelationships', {})
41
+ .fetch('IsPartOfRelationships', {})[0]
41
42
 
42
43
  @bibtex = BibTeX::Entry.new
43
44
  end
@@ -77,31 +78,35 @@ module EBSCO
77
78
 
78
79
  # The title.
79
80
  def title
80
- _title = get_item_data_by_name('Title') || bib_title
81
- if _title.nil?
82
- _title = 'This title is unavailable for guests, please login to see more information.'
81
+ _retval = get_item_data_by_name('Title') || bib_title
82
+ # todo: make this configurable
83
+ if _retval.nil?
84
+ _retval = 'This title is unavailable for guests, please login to see more information.'
83
85
  end
84
- _title
86
+ CGI.unescapeHTML(_retval)
85
87
  end
86
88
 
87
89
  # The source title (e.g., Journal)
88
90
  def source_title
89
- bib_source_title || get_item_data_by_name('TitleSource')
91
+ _retval = bib_source_title || get_item_data_by_name('TitleSource')
92
+ _retval.nil?? nil : CGI.unescapeHTML(_retval)
90
93
  end
91
94
 
92
95
  # Other alternative titles.
93
96
  def other_titles
94
- get_item_data_by_name('TitleAlt')
97
+ _retval = get_item_data_by_name('TitleAlt')
98
+ _retval.nil?? nil : CGI.unescapeHTML(_retval)
95
99
  end
96
100
 
97
101
  # The abstract
98
102
  def abstract
99
- get_item_data_by_name('Abstract')
103
+ _retval = get_item_data_by_name('Abstract')
104
+ _retval.nil?? nil : CGI.unescapeHTML(_retval)
100
105
  end
101
106
 
102
107
  # The list of authors
103
108
  def authors
104
- bib_authors || get_item_data_by_name('Author')
109
+ bib_authors || get_item_data_by_name('Author')
105
110
  end
106
111
 
107
112
  # The author affiliations
@@ -131,7 +136,8 @@ module EBSCO
131
136
 
132
137
  # Notes
133
138
  def notes
134
- get_item_data_by_name('Note')
139
+ _retval = get_item_data_by_name('Note')
140
+ _retval.nil?? nil : CGI.unescapeHTML(_retval)
135
141
  end
136
142
 
137
143
  # Languages
@@ -241,12 +247,20 @@ module EBSCO
241
247
 
242
248
  # Cover image - thumbnail size link
243
249
  def cover_thumb_url
244
- images('thumb').first[:src]
250
+ if images('thumb').any?
251
+ images('thumb').first[:src]
252
+ else
253
+ nil
254
+ end
245
255
  end
246
256
 
247
257
  # Cover image - medium size link
248
258
  def cover_medium_url
249
- images('medium').first[:src]
259
+ if images('medium').any?
260
+ images('medium').first[:src]
261
+ else
262
+ nil
263
+ end
250
264
  end
251
265
 
252
266
  # Word count for fulltext.
@@ -417,7 +431,7 @@ module EBSCO
417
431
 
418
432
  links
419
433
  end
420
-
434
+
421
435
  #:nodoc: all
422
436
  # No need to document methods below
423
437
 
@@ -768,7 +782,7 @@ module EBSCO
768
782
  hash['id'] = database_id + '__' + safe_an
769
783
  end
770
784
  if !title.nil?
771
- hash['title_display'] = title.gsub('<highlight>', '').gsub('</highlight>', '')
785
+ hash['title_display'] = title.gsub('<highlight>', '').gsub('</highlight>', '')
772
786
  end
773
787
  if publication_year
774
788
  hash['pub_date'] = publication_year
@@ -792,6 +806,12 @@ module EBSCO
792
806
  if abstract
793
807
  hash['abstract'] = abstract
794
808
  end
809
+ if cover_thumb_url
810
+ hash['cover_thumb_url'] = cover_thumb_url
811
+ end
812
+ if cover_medium_url
813
+ hash['cover_medium_url'] = cover_medium_url
814
+ end
795
815
  hash
796
816
  end
797
817
 
@@ -800,7 +820,7 @@ module EBSCO
800
820
  {
801
821
  'responseHeader' => {
802
822
  'status' => 0
803
- },
823
+ },
804
824
  'response' => {
805
825
  'numFound' => 1,
806
826
  'start' => 0,
@@ -11,26 +11,28 @@ module EBSCO
11
11
  # Raw results as Hash
12
12
  attr_reader :results
13
13
  # Array of EBSCO::EDS::Record results
14
- attr_reader :records
14
+ attr_accessor :records
15
15
  # Array of EBSCO::EDS::Record Research Starters
16
16
  attr_reader :research_starters
17
17
  # Array of EBSCO::EDS::Record Exact Publication Matches
18
18
  attr_reader :publication_match
19
19
 
20
+ attr_accessor :stat_total_hits
21
+
20
22
  # Lookup table of databases that have their labels suppressed in the response.
21
23
  DBS = YAML::load_file(File.join(__dir__, 'settings.yml'))['databases']
22
24
 
23
25
  # Creates search results from the \EDS API search response. It includes information about the results and a list
24
26
  # of Record items.
25
27
  def initialize(search_results, additional_limiters = {}, raw_options = {})
26
-
28
+
27
29
  @results = search_results
28
30
  @limiters = additional_limiters
29
31
  @raw_options = raw_options
30
32
 
31
33
  # convert all results to a list of records
32
34
  @records = []
33
- if stat_total_hits > 0
35
+ if @results['SearchResult']['Data']['Records']
34
36
  @results['SearchResult']['Data']['Records'].each { |record|
35
37
 
36
38
  @records.push(EBSCO::EDS::Record.new(record))
@@ -48,7 +50,7 @@ module EBSCO
48
50
 
49
51
  }
50
52
  end
51
-
53
+
52
54
  # create a special list of research starter records
53
55
  @research_starters = []
54
56
  _related_records = @results.fetch('SearchResult',{}).fetch('RelatedContent',{}).fetch('RelatedRecords',{})
@@ -64,7 +66,7 @@ module EBSCO
64
66
  end
65
67
  end
66
68
  end
67
-
69
+
68
70
  # create a special list of exact match publications
69
71
  @publication_match = []
70
72
  _related_publications = @results.fetch('SearchResult',{}).fetch('RelatedContent',{}).fetch('RelatedPublications',{})
@@ -80,7 +82,7 @@ module EBSCO
80
82
  end
81
83
  end
82
84
  end
83
-
85
+
84
86
  end
85
87
 
86
88
  # returns solr search response format
@@ -90,55 +92,69 @@ module EBSCO
90
92
  hl_hash = {}
91
93
  solr_docs = []
92
94
 
93
- if stat_total_hits > 0
95
+ if @records.any?
94
96
  @records.each { |record|
95
97
 
96
98
  # todo: add solr hl.tag.pre and hl.tag.post to retrieval criteria
97
- if retrieval_criteria.fetch('Highlight',{}) == 'y'
98
- hl_title = record.title.gsub('&lt;highlight&gt;', '<em>').gsub('&lt;/highlight&gt;', '</em>')
99
+ if retrieval_criteria && retrieval_criteria.fetch('Highlight',{}) == 'y'
100
+ hl_title = record.title.gsub('<highlight>', '<em>').gsub('</highlight>', '</em>')
99
101
  hl_hash.update({ record.database_id + '__' + record.accession_number => { 'title_display' => [hl_title]} })
100
102
  #hl_hash.merge title_hl
101
103
  end
102
-
103
104
  solr_docs.push(record.to_hash)
104
105
  }
105
106
  end
106
107
 
108
+ status = 0
109
+ wt = 'ruby'
110
+ qtime = stat_total_time
111
+ qterms = search_terms.join(' ')
112
+ rows = results_per_page
113
+ num_found = stat_total_hits.to_i
114
+ search_limiters = solr_search_limiters
115
+ format = solr_facets('SourceType')
116
+ language_facet = solr_facets('Language')
117
+ subject_topic_facet = solr_facets('SubjectEDS')
118
+ publisher_facet = solr_facets('Publisher')
119
+ journal_facet = solr_facets('Journal')
120
+ geographic_facet = solr_facets('SubjectGeographic')
121
+ category_facet = solr_facets('Category')
122
+ content_provider_facet = solr_facets('ContentProvider')
123
+ library_location_facet = solr_facets('LocationLibrary')
124
+ facet = true
125
+
107
126
  # solr response
108
127
  {
109
128
  'responseHeader' => {
110
- 'status' => 0,
111
- 'QTime' => stat_total_time,
112
- 'params' => {
113
- 'q' => search_terms.join(' '),
114
- 'wt' => 'ruby',
115
- 'start' => solr_start,
116
- 'rows' => results_per_page,
117
- 'facet' => true,
118
- 'f.subject_topic_facet.facet.limit' => 21,
119
- 'f.language_facet.facet.limit' => 11,
120
-
121
- }
129
+ 'status' => status,
130
+ 'QTime' => qtime,
131
+ 'params' => {
132
+ 'q' => qterms,
133
+ 'wt' => wt,
134
+ 'start' => solr_start,
135
+ 'rows' => rows,
136
+ 'facet' => facet
137
+ }
122
138
  },
123
139
  'response' => {
124
- 'numFound' => stat_total_hits.to_i,
125
- 'start' => solr_start,
126
- 'docs' => solr_docs
140
+ 'numFound' => num_found,
141
+ 'start' => solr_start,
142
+ 'docs' => solr_docs
127
143
  },
128
144
  'highlighting' => hl_hash,
129
145
  'facet_counts' =>
130
146
  {
131
147
  'facet_fields' => {
132
- 'search_limiters' => solr_search_limiters,
133
- 'format' => solr_facets('SourceType'),
134
- 'language_facet' => solr_facets('Language'),
135
- 'subject_topic_facet' => solr_facets('SubjectEDS'),
136
- 'publisher_facet' => solr_facets('Publisher'),
137
- 'journal_facet' => solr_facets('Journal'),
138
- 'geographic_facet' => solr_facets('SubjectGeographic'),
139
- 'category_facet' => solr_facets('Category'),
140
- 'content_provider_facet' => solr_facets('ContentProvider'),
141
- 'library_location_facet' => solr_facets('LocationLibrary')
148
+ 'search_limiters' => search_limiters,
149
+ 'format' => format,
150
+ 'language_facet' => language_facet,
151
+ 'subject_topic_facet' => subject_topic_facet,
152
+ 'publisher_facet' => publisher_facet,
153
+ 'journal_facet' => journal_facet,
154
+ 'geographic_facet' => geographic_facet,
155
+ 'category_facet' => category_facet,
156
+ 'content_provider_facet' => content_provider_facet,
157
+ 'library_location_facet' => library_location_facet
142
158
  }
143
159
  }
144
160
  }
@@ -149,17 +165,19 @@ module EBSCO
149
165
  def solr_search_limiters
150
166
  search_limiters = []
151
167
  if stat_total_hits.to_i > 0
152
- _ft_limiter = @limiters.find{|item| item['Id'] == 'FT'}
153
- if _ft_limiter['DefaultOn'] == 'y'
154
- search_limiters.push('Full Text').push('')
155
- end
156
- _rv_limiter = @limiters.find{|item| item['Id'] == 'RV'}
157
- if _rv_limiter['DefaultOn'] == 'y'
158
- search_limiters.push('Peer Reviewed').push('')
159
- end
160
- _ft1_limiter = @limiters.find{|item| item['Id'] == 'FT1'}
161
- if _ft1_limiter['DefaultOn'] == 'y'
162
- search_limiters.push('Available in Library Collection').push('')
168
+ if @limiters.any?
169
+ _ft_limiter = @limiters.find{|item| item['Id'] == 'FT'}
170
+ if _ft_limiter['DefaultOn'] == 'y'
171
+ search_limiters.push('Full Text').push('')
172
+ end
173
+ _rv_limiter = @limiters.find{|item| item['Id'] == 'RV'}
174
+ if _rv_limiter['DefaultOn'] == 'y'
175
+ search_limiters.push('Peer Reviewed').push('')
176
+ end
177
+ _ft1_limiter = @limiters.find{|item| item['Id'] == 'FT1'}
178
+ if _ft1_limiter['DefaultOn'] == 'y'
179
+ search_limiters.push('Available in Library Collection').push('')
180
+ end
163
181
  end
164
182
  end
165
183
  search_limiters
@@ -209,7 +227,7 @@ module EBSCO
209
227
  def retrieval_criteria
210
228
  @results['SearchRequest']['RetrievalCriteria']
211
229
  end
212
-
230
+
213
231
  # Queries used to produce the results. Returns an array of query hashes.
214
232
  # ==== Example
215
233
  # [{"BooleanOperator"=>"AND", "Term"=>"volcano"}]
@@ -412,7 +430,7 @@ module EBSCO
412
430
  end
413
431
  terms
414
432
  end
415
-
433
+
416
434
  end
417
435
 
418
436
  end
@@ -213,6 +213,22 @@ module EBSCO
213
213
  EBSCO::EDS::Record.new(retrieve_response)
214
214
  end
215
215
 
216
+ def solr_retrieve_list(list: [], highlight: nil, ebook: 'ebook-pdf')
217
+ records = []
218
+ if list.any?
219
+ list.each { |id|
220
+ dbid = id.split('__').first
221
+ accession = id.split('__').last
222
+ accession.gsub!(/_/, '.')
223
+ records.push retrieve(dbid: dbid, an: accession, highlight: highlight, ebook: ebook)
224
+ }
225
+ end
226
+ r = empty_results(records.length)
227
+ results = EBSCO::EDS::Results.new(r)
228
+ results.records = records
229
+ results.to_solr
230
+ end
231
+
216
232
  # :category: Search & Retrieve Methods
217
233
  # Invalidates the session token. End Session should be called when you know a user has logged out.
218
234
  def end
@@ -648,7 +664,7 @@ module EBSCO
648
664
  end
649
665
 
650
666
  # used to reliably create empty results when there are no search terms provided
651
- def empty_results
667
+ def empty_results(hits = 0)
652
668
  {
653
669
  'SearchRequest'=>
654
670
  {
@@ -675,8 +691,8 @@ module EBSCO
675
691
  {
676
692
  'Statistics'=>
677
693
  {
678
- 'TotalHits'=>0,
679
- 'TotalSearchTime'=>62,
694
+ 'TotalHits'=>hits,
695
+ 'TotalSearchTime'=>0,
680
696
  'Databases'=>[]
681
697
  },
682
698
  'Data'=> {'RecordFormat'=>'EP Display'},
@@ -1,5 +1,5 @@
1
1
  module EBSCO
2
2
  module EDS
3
- VERSION = '0.0.4.pre'
3
+ VERSION = '0.0.5.pre'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ebsco-eds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.pre
4
+ version: 0.0.5.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bill McKinney
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-03-24 00:00:00.000000000 Z
12
+ date: 2017-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday