Sha256: 3dbd6e78c7560bbfc3d8f9ad2791e129875df55c0f832580acf9557e7fd30c07

Contents?: true

Size: 784 Bytes

Versions: 4

Compression:

Stored size: 784 Bytes

Contents

# encoding: UTF-8

require 'forwardable'

module Spontaneous::Search
  # Wraps XapianFu::ResultSet to provide a list of pages rather than a list of
  # XapianDocs
  class Results
    extend  Forwardable
    include Enumerable

    def_delegators :@results, :current_page, :per_page, :total_pages, :next_page, :offset, :previous_page, :total_entries

    def initialize(result_set, corrected_query = nil)
      @results, @corrected_query = result_set, corrected_query
    end

    def corrected_query
      @corrected_query || @results.corrected_query
    end

    def each
      pages.each { |page| yield(page) }
    end

    def length
      pages.length
    end

    def pages
      @page_list ||= Spontaneous::Content.get(@results.map { |doc| doc.id })
    end
  end # Results
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta4 lib/spontaneous/search/results.rb
spontaneous-0.2.0.beta3 lib/spontaneous/search/results.rb
spontaneous-0.2.0.beta2 lib/spontaneous/search/results.rb
spontaneous-0.2.0.beta1 lib/spontaneous/search/results.rb