@@ -32,73 +32,81 @@ class Results
3232 def initialize ( search_results , eds_config = { } , additional_limiters = { } , options = { } )
3333
3434 @results = search_results
35- @limiters = additional_limiters
36- @raw_options = options
37-
38- # titleize facets?
39- ( ENV . has_key? 'EDS_TITLEIZE_FACETS' ) ?
40- if %w( y Y yes Yes true True ) . include? ( ENV [ 'EDS_TITLEIZE_FACETS' ] )
41- @titleize_facets_on = true
42- else
43- @titleize_facets_on = false
44- end :
45- @titleize_facets_on = eds_config [ :titleize_facets ]
46-
47- # convert all results to a list of records
48- @records = [ ]
49- if @results [ 'SearchResult' ] [ 'Data' ] [ 'Records' ]
50- @results [ 'SearchResult' ] [ 'Data' ] [ 'Records' ] . each { |record |
51-
52- @records . push ( EBSCO ::EDS ::Record . new ( record , eds_config ) )
53-
54- # # records hidden in guest mode
55- # if record['Header']['AccessLevel']
56- # if record['Header']['AccessLevel'].to_i > 1
57- # @records.push(EBSCO::EDS::Record.new(record))
58- # else
59- # @records.push(EBSCO::EDS::Record.new(record))
60- # end
61- # else
62- # @records.push(EBSCO::EDS::Record.new(record))
63- # end
6435
65- }
66- end
36+ if @results . is_a? ( Hash )
37+
38+ @limiters = additional_limiters
39+ @raw_options = options
40+
41+ # titleize facets?
42+ ( ENV . has_key? 'EDS_TITLEIZE_FACETS' ) ?
43+ if %w( y Y yes Yes true True ) . include? ( ENV [ 'EDS_TITLEIZE_FACETS' ] )
44+ @titleize_facets_on = true
45+ else
46+ @titleize_facets_on = false
47+ end :
48+ @titleize_facets_on = eds_config [ :titleize_facets ]
49+
50+ # convert all results to a list of records
51+ @records = [ ]
52+ if @results [ 'SearchResult' ] [ 'Data' ] [ 'Records' ]
53+ @results [ 'SearchResult' ] [ 'Data' ] [ 'Records' ] . each { |record |
54+
55+ @records . push ( EBSCO ::EDS ::Record . new ( record , eds_config ) )
56+
57+ # # records hidden in guest mode
58+ # if record['Header']['AccessLevel']
59+ # if record['Header']['AccessLevel'].to_i > 1
60+ # @records.push(EBSCO::EDS::Record.new(record))
61+ # else
62+ # @records.push(EBSCO::EDS::Record.new(record))
63+ # end
64+ # else
65+ # @records.push(EBSCO::EDS::Record.new(record))
66+ # end
67+
68+ }
69+ end
6770
68- # create a special list of research starter records
69- @research_starters = [ ]
70- _related_records = @results . fetch ( 'SearchResult' , { } ) . fetch ( 'RelatedContent' , { } ) . fetch ( 'RelatedRecords' , { } )
71- if _related_records . count > 0
72- _related_records . each do |related_item |
73- if related_item [ 'Type' ] == 'rs'
74- rs_entries = related_item . fetch ( 'Records' , { } )
75- if rs_entries . count > 0
76- rs_entries . each do |rs_record |
77- @research_starters . push ( EBSCO ::EDS ::Record . new ( rs_record , eds_config ) )
71+ # create a special list of research starter records
72+ @research_starters = [ ]
73+ _related_records = @results . fetch ( 'SearchResult' , { } ) . fetch ( 'RelatedContent' , { } ) . fetch ( 'RelatedRecords' , { } )
74+ if _related_records . count > 0
75+ _related_records . each do |related_item |
76+ if related_item [ 'Type' ] == 'rs'
77+ rs_entries = related_item . fetch ( 'Records' , { } )
78+ if rs_entries . count > 0
79+ rs_entries . each do |rs_record |
80+ @research_starters . push ( EBSCO ::EDS ::Record . new ( rs_record , eds_config ) )
81+ end
7882 end
7983 end
8084 end
8185 end
82- end
8386
84- # create a special list of exact match publications
85- @publication_match = [ ]
86- _related_publications = @results . fetch ( 'SearchResult' , { } ) . fetch ( 'RelatedContent' , { } ) . fetch ( 'RelatedPublications' , { } )
87- if _related_publications . count > 0
88- _related_publications . each do |related_item |
89- if related_item [ 'Type' ] == 'emp'
90- _publication_matches = related_item . fetch ( 'PublicationRecords' , { } )
91- if _publication_matches . count > 0
92- _publication_matches . each do |publication_record |
93- @publication_match . push ( EBSCO ::EDS ::Record . new ( publication_record , eds_config ) )
87+ # create a special list of exact match publications
88+ @publication_match = [ ]
89+ _related_publications = @results . fetch ( 'SearchResult' , { } ) . fetch ( 'RelatedContent' , { } ) . fetch ( 'RelatedPublications' , { } )
90+ if _related_publications . count > 0
91+ _related_publications . each do |related_item |
92+ if related_item [ 'Type' ] == 'emp'
93+ _publication_matches = related_item . fetch ( 'PublicationRecords' , { } )
94+ if _publication_matches . count > 0
95+ _publication_matches . each do |publication_record |
96+ @publication_match . push ( EBSCO ::EDS ::Record . new ( publication_record , eds_config ) )
97+ end
9498 end
9599 end
96100 end
97101 end
98- end
99102
100- # titleize facets
101- @titleize_facets = %w[ Language Journal SubjectEDS SubjectGeographic Publisher ]
103+ # titleize facets
104+ @titleize_facets = %w[ Language Journal SubjectEDS SubjectGeographic Publisher ]
105+
106+ else
107+ # response isn't a hash (eg, html error page)
108+ raise EBSCO ::EDS ::ApiError , 'EBSCO API error: Query failed.'
109+ end
102110
103111 end
104112
0 commit comments