class Indexer101::Index
Attributes
h[R]
index[RW]
uri_index[RW]
Public Class Methods
new()
click to toggle source
# File lib/indexer101.rb, line 20 def initialize() @uri_index = {} # contains each URI long with the title @index = {} # contains eack keyword @h = {} # nested keywords constructed from shared string keys end
Public Instance Methods
build(a)
click to toggle source
# File lib/indexer101.rb, line 28 def build(a) threads = [] if @index.empty? then threads << Thread.new do @index = Hash[a.map(&:to_sym).zip([''] * a.length)] end end threads << Thread.new { @h = group a } ThreadsWait.all_waits(*threads) end
inspect()
click to toggle source
# File lib/indexer101.rb, line 43 def inspect() h = @h ? @h.inspect[0..30] + "..." : nil "#<Indexer101::Index @h=#{h.inspect}>" end
Private Instance Methods
group(a, length=0)
click to toggle source
# File lib/indexer101.rb, line 50 def group(a, length=0) h = a.group_by {|x| x[0..length]} h.each do |key, value| if length+1 < value.max.length - 1 then h2 = group value, length + 1 h[key] = h2 unless h2.length < 2 and value.length < 2 end end h3 = h.inject({}) do |r,x| r.merge(x[0].to_sym => x[-1]) end end