Class: XapianFu::ResultSet

Inherits:
Array show all
Defined in:
lib/xapian_fu/result_set.rb

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

Instance Method Summary collapse

Methods inherited from Array

#to_xapian_fu_string

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(options = { })
  @mset = options[:mset]
  @current_page = options[:current_page]
  @per_page = options[:per_page]
  @corrected_query = options[:corrected_query]
  @facets = {}
  @db = options[:xapian_db]

  options[: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 options[:spies]

  doc_options = {:xapian_db => options[:xapian_db] }
  concat mset.matches.collect { |m| XapianDoc.new(m, doc_options) }
end

Instance Attribute Details

#corrected_queryObject (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_pageObject (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

#facetsObject (readonly)

Returns the value of attribute facets



15
16
17
# File 'lib/xapian_fu/result_set.rb', line 15

def facets
  @facets
end

#msetObject (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_pageObject (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_pagesObject (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_pageObject

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

#offsetObject

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_pageObject

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_entriesObject

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