class Qwik::DBIndexer
Public Class Methods
new(path)
click to toggle source
# File vendor/qwik/lib/qwik/db-indexer.rb, line 18 def initialize(path) @path = path @index = nil return if ! $have_senna_so @cache_path = @path+'.cache' @index_path = @cache_path+'index' check_directory @index = Senna::Index.new((@cache_path+'index').to_s) end
Public Instance Methods
check(k, v)
click to toggle source
# File vendor/qwik/lib/qwik/db-indexer.rb, line 31 def check(k, v) return update(k, v) end
put(k, v, time=nil)
click to toggle source
# File vendor/qwik/lib/qwik/db-indexer.rb, line 35 def put(k, v, time=nil) return update(k, v) end
search(key)
click to toggle source
# File vendor/qwik/lib/qwik/db-indexer.rb, line 61 def search(key) return nil if @index.nil? records = @index.sel(key) return [] if records.nil? || records.nhits == 0 ar = [] while res = records.next ar << res end return ar end
update(k, v)
click to toggle source
# File vendor/qwik/lib/qwik/db-indexer.rb, line 39 def update(k, v) return if @index.nil? # Try to read old content. pa = path(k) old = nil old = pa.get if pa.exist? # Avoid \0 from its contents. v = v.gsub("\0", '')if v.include?("\0") # FIXME: Too ad hoc. return false if v == old # Not necessary to update. result = @index.upd(k, old, v) # FIXME: Take care of result? # Store new value to cached content. check_directory pa.open('wb') {|f| f.print(v) } return result end
Private Instance Methods
check_directory()
click to toggle source
# File vendor/qwik/lib/qwik/db-indexer.rb, line 76 def check_directory @cache_path.check_directory @index_path.check_directory end
path(k)
click to toggle source
# File vendor/qwik/lib/qwik/db-indexer.rb, line 81 def path(k) return @index_path+(k+'.txt') end