class XapianFu::ResultSet

A XapianFu::ResultSet holds the XapianDoc objects returned from a search. It acts just like an array but is decorated with useful attributes.

Attributes

corrected_query[R]

If any spelling corrections were detected, the full collected query is provided by :corrected_query, otherwise this is empty.

current_page[R]
facets[R]
mset[R]

The Xapian match set for this search

per_page[R]
total_pages[R]

The total number of pages of results available for this search

Public Class Methods

new(options = { }) click to toggle source

nodoc

   # File lib/xapian_fu/result_set.rb
18 def initialize(options = { })
19   @mset = options[:mset]
20   @current_page = options[:current_page]
21   @per_page = options[:per_page]
22   @corrected_query = options[:corrected_query]
23   @facets = {}
24   @db = options[:xapian_db]
25 
26   options[:spies].each do |name, spy|
27     @facets[name] = spy.values.map do |value|
28       term = value.term.force_encoding(Encoding::UTF_8)
29 
30       [@db.unserialize_value(name, term), value.termfreq]
31     end
32   end if options[:spies]
33 
34   doc_options = {:xapian_db => options[:xapian_db] }
35   concat mset.matches.collect { |m| XapianDoc.new(m, doc_options) }
36 end

Public Instance Methods

next_page() click to toggle source

The next page number, or nil if there are no more more pages available

   # File lib/xapian_fu/result_set.rb
55 def next_page
56   p = current_page + 1
57   p > total_pages ? nil : p
58 end
offset() click to toggle source

The offset within the total results of the first result in this page

   # File lib/xapian_fu/result_set.rb
61 def offset
62   (current_page - 1) * per_page
63 end
previous_page() click to toggle source

The previous page number, or nil if there are no previous pages available

   # File lib/xapian_fu/result_set.rb
49 def previous_page
50   p = current_page - 1
51   p == 0 ? nil : p
52 end
total_entries() click to toggle source

The estimated total number of matches this search could return

   # File lib/xapian_fu/result_set.rb
39 def total_entries
40   mset.matches_estimated
41 end