class Seasy::InMemoryStorage

a store got search queries as keys and an array of target-weight tuples as values

Public Class Methods

new() click to toggle source
# File lib/seasy/index.rb, line 75
def initialize
  @store = {}
  @sources = {}
end

Public Instance Methods

add(weight, key, target) click to toggle source
# File lib/seasy/index.rb, line 93
def add weight, key, target
  if @store[key].nil?
    @store[key] = {target => weight}
  elsif @store[key][target].nil?
    @store[key][target] = weight
  else
    @store[key][target] += weight
  end
end
clear() click to toggle source
# File lib/seasy/index.rb, line 108
def clear
  @store = {}
  @sources = {}
end
remove(source) click to toggle source
# File lib/seasy/index.rb, line 113
def remove source
  targets = @sources[source]
  @store.delete_if {|key,value| !value[targets.first].nil?}
end
save(target, weights, options = {}) click to toggle source

target is a simple value - we care not what weights are all fragments (indices) and their weight eg. { “aba” => 1, “ab” => 1, “ba” => 1, “b” => 1, “a” => 2 } for the string “aba”

# File lib/seasy/index.rb, line 83
def save target, weights, options = {}
  raise ":source need to be set" if options[:source].nil?
  source = options[:source]
  @sources[source] ||= []
  @sources[source] << target
  weights.keys.each do |key|
    add weights[key], key, target
  end
end