Sha256: a10d4eb3e318c90c277f6f19ab44fe29c77e762531c8eab53551013a97d18149

Contents?: true

Size: 793 Bytes

Versions: 5

Compression:

Stored size: 793 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 ||= @results.map { |doc| Spontaneous::Content.first(:id => doc.id) }
    end
  end # Results
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spontaneous-0.2.0.alpha7 lib/spontaneous/search/results.rb
spontaneous-0.2.0.alpha6 lib/spontaneous/search/results.rb
spontaneous-0.2.0.alpha5 lib/spontaneous/search/results.rb
spontaneous-0.2.0.alpha4 lib/spontaneous/search/results.rb
spontaneous-0.2.0.alpha3 lib/spontaneous/search/results.rb