5 attr_accessor :query, :sort_by, :index_start, :index_end, :records
7 #All values of initialize are optional, though you'll want to supply it with a query object if you intend on getting records into your set through a z39.50 search. index_start and index_end will be used for the TUI display.
8 def initialize(query_object=nil, sort_by='title', index_start=0, index_end=5 )
9 @query = query_object #query object
12 @index_start = index_start
13 @index_end = index_end
15 #puts self.index_start
17 #puts self.records.class
21 #Pretty prints the result set object. Nests pretty printed record objects within.
23 full_string = "-------RESULT SET--------------\n" + "Result set has #{self.records.size} records."
24 self.records.each do |record|
25 full_string << record.to_s
27 full_string += "-------RESULT SET--------------\n"
30 # Method to add records only to a result set.
32 self.records << record
35 # appends a result set to another.
36 # Replaces the query and sort_by instance variables with the new ones.
39 #Removes unselected records from the result set. Uses the selected instance variable to check for true or false.
40 def remove_unselected!
41 self.records.each_index do |i|
42 if self.records[i].nil?
44 self.records[i] = nil unless self.records[i].selected
52 #Number of records in the result set
60 selected_records = self.find_all{|record| record.selected unless record == nil}
61 selected_records.length
62 end #returns number of ZCC::Records with @selected set to true
64 alias selected_length selected_size
69 for record in @records
80 self.records = self.records.sort_by{|r| r.marc['245']['a']}
85 self.records = self.records.sort_by{ |r| r.year_260}
88 def sort_by_subfield! sf
90 field, subfield = sf[0,3], sf[3,10]
91 subfield = 'a' if subfield == ''
92 self.records = self.records.sort_by{ |r| r.marc[field][subfield]}
97 self.records = self.records.sort_by{|r| r.marc.leader[18]}
101 def rank_by_relevance!
102 raise NotImplementedError
103 unless self.query.type == 'title'
104 raise "Relevancy ranking only works with titles (and not even them yet)"
106 term = self.query.term
111 self.records.compact!
112 self.records.flatten!
116 end #=> hash{zurl=>[rec, rec],zurl=>[rec, rec]
121 end # Record at that position
124 if self.records.size == 0
126 elsif self.records.size > 0
129 end #returns true if the @ZCCRecords array is empty or only nil values
132 #self.find_all {|record| record.selected}
137 self.records << result_set.records
138 self.query = result_set.query
139 self.sort_by = result_set.sort_by
140 self.records.flatten!
141 #puts self.records.inspect