class PMS::TokenProxy

Attributes

results_with_positions[R]
token[R]

Public Class Methods

new(pms, token) click to toggle source
Calls superclass method PMS::Proxy.new
# File lib/pms/proxy.rb, line 101
def initialize(pms, token)
  super(pms)

  @results_with_positions = index.results_with_positions(token)
  @token, @results = token, @results_with_positions.keys
end

Public Instance Methods

%(token, distance = 1, order = false)
Alias for: near
^(token, distance = 1)
Alias for: adjacent
adj(token, distance = 1)
Alias for: adjacent
adjacent(token, distance = 1) click to toggle source
# File lib/pms/proxy.rb, line 131
def adjacent(token, distance = 1)
  near(token, distance, true)
end
Also aliased as: adj, ^
near(token, distance = 1, order = false) click to toggle source
# File lib/pms/proxy.rb, line 108
def near(token, distance = 1, order = false)
  results1 = results_with_positions
  results2 = index.results_with_positions(token)

  doc_nums = results1.keys & results2.keys

  # TODO: i'm sure this can be simplified...
  doc_nums.delete_if { |doc_num|
    positions = results2[doc_num]

    !results1[doc_num].any? { |pos1|
      positions.find { |pos2|
        diff = pos2 - pos1
        order && diff < 0 ? break : diff.abs <= distance
      }
    }
  }

  apply_operator(:and, doc_nums)
end
Also aliased as: %

Private Instance Methods

clone_with_results(results) click to toggle source
Calls superclass method PMS::Proxy#clone_with_results
# File lib/pms/proxy.rb, line 140
def clone_with_results(results)
  super.tap { |clone| clone.instance_variable_set(:@results_with_positions,
    @results_with_positions.dup.delete_if { |k, _| !results.include?(k) }) }
end