Sha256: 83f821e4a46470c88e3eec58fac2fa54aa2be8d70ab54bd657a7ae0b3b0373d3

Contents?: true

Size: 611 Bytes

Versions: 7

Compression:

Stored size: 611 Bytes

Contents

module Lunar
  # @private Used internally by Lunar::search to get all the range matches
  # given `nest`, `att` and it's `val`.
  class RangeMatches
    MAX_RESULTS = 10_000

    attr :nest
    attr :att
    attr :range

    def initialize(nest, att, range)
      @nest, @att, @range = nest, att.to_sym, range
    end


    def distkey
      nest[{ att => range }.hash].tap do |dk|
        res = zset.zrangebyscore(range.first, range.last, :limit => [0, MAX_RESULTS])
        res.each { |val| dk.zadd(1, val) }
      end
    end

  private
    def zset
      @sortedset ||= nest[:Numbers][att]
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lunar-0.6.0 lib/lunar/range_matches.rb
lunar-0.5.5 lib/lunar/range_matches.rb
lunar-0.5.4 lib/lunar/range_matches.rb
lunar-0.5.3 lib/lunar/range_matches.rb
lunar-0.5.2 lib/lunar/range_matches.rb
lunar-0.5.1 lib/lunar/range_matches.rb
lunar-0.5.0 lib/lunar/range_matches.rb