Skip to content

Commit

Permalink
+ Rewrote file backend to use the memory backend with the weights index
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Nov 28, 2012
1 parent ed3c930 commit a5015c2
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions server/lib/picky.rb
Expand Up @@ -25,6 +25,7 @@ class << self
require 'active_support/multibyte'
require 'multi_json'
require 'rack_fast_escape' if defined? Rack
require 'fileutils'

# Check if platform specific modifiers need to be installed.
#
Expand Down
8 changes: 5 additions & 3 deletions server/lib/picky/backends/backend.rb
Expand Up @@ -9,6 +9,8 @@ class Backend
# This is the default behaviour and should be overridden
# for different backends.
#
# TODO Push down.
#

# Returns an object that on #initial, #load returns
# an object that responds to:
Expand All @@ -21,9 +23,9 @@ def create_inverted bundle
# an object that responds to:
# [:token] # => 1.23 (a weight)
#
def create_weights bundle
json bundle.index_path(:weights)
end
# def create_weights bundle
# json bundle.index_path(:weights)
# end
# # Returns an object that on #initial, #load returns
# # an object that responds to:
# # [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
Expand Down
9 changes: 5 additions & 4 deletions server/lib/picky/backends/file.rb
Expand Up @@ -9,10 +9,11 @@ module Backends
# ...[1,2,3,21,7,4,13,15]...
#
class File < Backend

# Returns an object that on #initial, #load returns an object that responds to:
# [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
#

def create_weights bundle
Memory::JSON.new bundle.index_path(:weights)
end

def create_similarity bundle
json bundle.index_path(:similarity)
end
Expand Down
2 changes: 1 addition & 1 deletion server/lib/picky/backends/file/basic.rb
Expand Up @@ -27,7 +27,7 @@ def initialize cache_path, options = {}
# This is the mapping file with the in-memory hash for the
# file position/offset mappings.
#
@mapping_file = Memory::JSON.new "#{cache_path}.file_mapping.#{extension}"
@mapping_file = Memory::JSON.new "#{cache_path}.file_mapping"

@empty = options[:empty]
@initial = options[:initial]
Expand Down
2 changes: 1 addition & 1 deletion server/lib/picky/backends/file/json.rb
Expand Up @@ -65,7 +65,7 @@ def load
def dump hash
offset = 0
mapping = {}

create_directory cache_path
::File.open(cache_path, 'w:utf-8') do |out_file|
hash.each do |(key, object)|
Expand Down
8 changes: 4 additions & 4 deletions server/lib/picky/backends/memory.rb
Expand Up @@ -4,10 +4,10 @@ module Backends

class Memory < Backend

# Returns an object that on #initial, #load returns
# an object that responds to:
# [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
#
def create_weights bundle
JSON.new bundle.index_path(:weights)
end

def create_similarity bundle
Marshal.new bundle.index_path(:similarity)
end
Expand Down
2 changes: 1 addition & 1 deletion server/lib/picky/backends/redis.rb
Expand Up @@ -14,7 +14,7 @@ def initialize options = {}
check_hiredis_gem
check_redis_gem

@client = options[:client] || ::Redis.new(:db => (options[:db] || 15))
@client = options[:client] || ::Redis.new(:db => (options[:db] || 15))
@realtime = options[:realtime]
end
def maybe_load_hiredis
Expand Down

0 comments on commit a5015c2

Please sign in to comment.