Class: XapianFu::ResultSet
Overview
A XapianFu::ResultSet holds the XapianDoc objects returned from a search. It acts just like an array but is decorated with useful attributes.
Instance Attribute Summary collapse
-
#corrected_query ⇒ Object
readonly
If any spelling corrections were detected, the full collected query is provided by :corrected_query, otherwise this is empty.
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#facets ⇒ Object
readonly
Returns the value of attribute facets.
-
#mset ⇒ Object
readonly
The Xapian match set for this search.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#total_pages ⇒ Object
readonly
The estimated total number of pages of results this search could return.
Instance Method Summary collapse
-
#initialize(options = { }) ⇒ ResultSet
constructor
nodoc.
-
#next_page ⇒ Object
The next page number, or nil if there are no more more pages available.
-
#offset ⇒ Object
The offset within the total results of the first result in this page.
-
#previous_page ⇒ Object
The previous page number, or nil if there are no previous pages available.
-
#total_entries ⇒ Object
The estimated total number of matches this search could return.
Methods inherited from Array
Constructor Details
#initialize(options = { }) ⇒ ResultSet
nodoc
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/xapian_fu/result_set.rb', line 18 def initialize( = { }) @mset = [:mset] @current_page = [:current_page] @per_page = [:per_page] @corrected_query = [:corrected_query] @facets = {} @db = [:xapian_db] [:spies].each do |name, spy| @facets[name] = spy.values.map do |value| term = value.term.force_encoding(Encoding::UTF_8) [@db.unserialize_value(name, term), value.termfreq] end end if [:spies] = {:xapian_db => [:xapian_db] } concat mset.matches.collect { |m| XapianDoc.new(m, ) } end |
Instance Attribute Details
#corrected_query ⇒ Object (readonly)
If any spelling corrections were detected, the full collected query is provided by :corrected_query, otherwise this is empty.
13 14 15 |
# File 'lib/xapian_fu/result_set.rb', line 13 def corrected_query @corrected_query end |
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
8 9 10 |
# File 'lib/xapian_fu/result_set.rb', line 8 def current_page @current_page end |
#facets ⇒ Object (readonly)
Returns the value of attribute facets.
15 16 17 |
# File 'lib/xapian_fu/result_set.rb', line 15 def facets @facets end |
#mset ⇒ Object (readonly)
The Xapian match set for this search
7 8 9 |
# File 'lib/xapian_fu/result_set.rb', line 7 def mset @mset end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
8 9 10 |
# File 'lib/xapian_fu/result_set.rb', line 8 def per_page @per_page end |
#total_pages ⇒ Object (readonly)
The estimated total number of pages of results this search could return
10 11 12 |
# File 'lib/xapian_fu/result_set.rb', line 10 def total_pages @total_pages end |
Instance Method Details
#next_page ⇒ Object
The next page number, or nil if there are no more more pages available
55 56 57 58 |
# File 'lib/xapian_fu/result_set.rb', line 55 def next_page p = current_page + 1 p > total_pages ? nil : p end |
#offset ⇒ Object
The offset within the total results of the first result in this page
61 62 63 |
# File 'lib/xapian_fu/result_set.rb', line 61 def offset (current_page - 1) * per_page end |
#previous_page ⇒ Object
The previous page number, or nil if there are no previous pages available
49 50 51 52 |
# File 'lib/xapian_fu/result_set.rb', line 49 def previous_page p = current_page - 1 p == 0 ? nil : p end |
#total_entries ⇒ Object
The estimated total number of matches this search could return
39 40 41 |
# File 'lib/xapian_fu/result_set.rb', line 39 def total_entries mset.matches_estimated end |