Permalink
Browse files

+ backend rewrite, towards making it more exchangeable

  • Loading branch information...
1 parent dbe241f commit 536a852100f7a9ec7b16d132b69e5969c617f35b @floere committed Aug 25, 2011
Showing with 458 additions and 905 deletions.
  1. +1 −1 server/lib/picky/{backend → backends}/base.rb
  2. +1 −1 server/lib/picky/{backend → backends}/file/basic.rb
  3. +1 −1 server/lib/picky/{backend → backends}/file/json.rb
  4. +1 −1 server/lib/picky/{backend → backends}/file/marshal.rb
  5. +1 −1 server/lib/picky/{backend → backends}/file/text.rb
  6. +2 −2 server/lib/picky/{backend/files.rb → backends/memory.rb}
  7. +1 −1 server/lib/picky/{backend → backends}/redis.rb
  8. +1 −1 server/lib/picky/{backend → backends}/redis/basic.rb
  9. +1 −1 server/lib/picky/{backend → backends}/redis/float_hash.rb
  10. +1 −1 server/lib/picky/{backend → backends}/redis/list_hash.rb
  11. +1 −1 server/lib/picky/{backend → backends}/redis/string_hash.rb
  12. +9 −3 server/lib/picky/bundle.rb
  13. +5 −5 server/lib/picky/category.rb
  14. +112 −0 server/lib/picky/indexed/bundle.rb
  15. +0 −116 server/lib/picky/indexed/bundle/base.rb
  16. +0 −31 server/lib/picky/indexed/bundle/memory.rb
  17. +0 −29 server/lib/picky/indexed/bundle/redis.rb
  18. +1 −1 server/lib/picky/indexed/wrappers/exact_first.rb
  19. +3 −6 server/lib/picky/indexes/index.rb
  20. +2 −5 server/lib/picky/indexes/memory.rb
  21. +2 −5 server/lib/picky/indexes/redis.rb
  22. +239 −0 server/lib/picky/indexing/bundle.rb
  23. +0 −242 server/lib/picky/indexing/bundle/base.rb
  24. +0 −28 server/lib/picky/indexing/bundle/memory.rb
  25. +0 −28 server/lib/picky/indexing/bundle/redis.rb
  26. +13 −20 server/lib/picky/loader.rb
  27. +2 −2 server/spec/lib/backend/file/basic_spec.rb
  28. +2 −2 server/spec/lib/backend/file/json_spec.rb
  29. +2 −2 server/spec/lib/backend/file/marshal_spec.rb
  30. +1 −1 server/spec/lib/backend/file/text_spec.rb
  31. +5 −3 server/spec/lib/backend/{files_spec.rb → memory_spec.rb}
  32. +2 −2 server/spec/lib/backend/redis/basic_spec.rb
  33. +2 −2 server/spec/lib/backend/redis/float_hash_spec.rb
  34. +2 −2 server/spec/lib/backend/redis/list_hash_spec.rb
  35. +2 −2 server/spec/lib/backend/redis/string_hash_spec.rb
  36. +1 −1 server/spec/lib/backend/redis_spec.rb
  37. +4 −4 server/spec/lib/category_indexed_spec.rb
  38. +0 −17 server/spec/lib/indexed/bundle/redis_spec.rb
  39. +4 −4 server/spec/lib/indexed/{bundle → }/memory_spec.rb
  40. +0 −38 server/spec/lib/indexing/bundle/base_spec.rb
  41. +0 −283 server/spec/lib/indexing/bundle/redis_spec.rb
  42. +2 −2 ...dexing/{bundle/memory_partial_generation_speed_spec.rb → bundle_partial_generation_speed_spec.rb}
  43. +29 −7 server/spec/lib/indexing/{bundle/memory_spec.rb → bundle_spec.rb}
@@ -1,6 +1,6 @@
module Picky
- module Backend
+ module Backends
class Base
@@ -1,6 +1,6 @@
module Picky
- module Backend
+ module Backends
# Handles all aspects of index files, such as dumping/loading.
#
@@ -1,6 +1,6 @@
module Picky
- module Backend
+ module Backends
module File
@@ -1,6 +1,6 @@
module Picky
- module Backend
+ module Backends
module File
@@ -1,6 +1,6 @@
module Picky
- module Backend
+ module Backends
module File
@@ -1,8 +1,8 @@
module Picky
- module Backend
+ module Backends
- class Files < Base
+ class Memory < Base
def initialize bundle
super bundle
@@ -1,6 +1,6 @@
module Picky
- module Backend
+ module Backends
#
#
@@ -1,6 +1,6 @@
module Picky
- module Backend
+ module Backends
class Redis
@@ -1,6 +1,6 @@
module Picky
- module Backend
+ module Backends
class Redis
@@ -1,6 +1,6 @@
module Picky
- module Backend
+ module Backends
class Redis
@@ -1,6 +1,6 @@
module Picky
- module Backend
+ module Backends
class Redis
View
@@ -35,16 +35,22 @@ class Bundle
delegate :[], :[]=, :to => :configuration
delegate :index_directory, :to => :category
- def initialize name, category, similarity_strategy, options = {}
+ def initialize name, category, backend_class, similarity_strategy, options = {}
@name = name
@category = category
- # TODO Still needed?
+ # TODO Refactor further.
+ #
+ @backend = backend_class.new self
+
+ # Default backend values.
+ #
+ # TODO Use a default (memory) backend and load instantly.
#
@inverted = {}
@weights = {}
@similarity = {}
- @configuration = {} # A hash with config options.
+ @configuration = {}
@similarity_strategy = similarity_strategy
end
@@ -35,16 +35,16 @@ def initialize name, index, options = {}
partial = options[:partial] || Generators::Partial::Default
similarity = options[:similarity] || Generators::Similarity::Default
- @indexing_exact = index.indexing_bundle_class.new :exact, self, weights, Generators::Partial::None.new, similarity, options
- @indexing_partial = index.indexing_bundle_class.new :partial, self, weights, partial, Generators::Similarity::None.new, options
+ @indexing_exact = Indexing::Bundle.new :exact, self, index.backend_class, weights, Generators::Partial::None.new, similarity, options
+ @indexing_partial = Indexing::Bundle.new :partial, self, index.backend_class, weights, partial, Generators::Similarity::None.new, options
# Indexed.
#
- @indexed_exact = index.indexed_bundle_class.new :exact, self, similarity
+ @indexed_exact = Indexed::Bundle.new :exact, self, index.backend_class, similarity
if partial.use_exact_for_partial?
@indexed_partial = @indexed_exact
else
- @indexed_partial = index.indexed_bundle_class.new :partial, self, similarity
+ @indexed_partial = Indexed::Bundle.new :partial, self, index.backend_class, similarity
end
# @exact = exact_lambda.call(@exact, @partial) if exact_lambda = options[:exact_lambda]
@@ -92,7 +92,7 @@ def prepared_index_path
# Note: If you don't use it with the block, do not forget to close it.
#
def prepared_index_file &block
- @prepared_index_file ||= Backend::File::Text.new prepared_index_path
+ @prepared_index_file ||= Backends::File::Text.new prepared_index_path
@prepared_index_file.open &block
end
# Creates the index directory including all necessary paths above it.
@@ -0,0 +1,112 @@
+module Picky
+
+ module Indexed # :nodoc:all
+
+ # An indexed bundle is a number of memory/redis
+ # indexes that compose the indexes for a single category:
+ # * core (inverted) index
+ # * weights index
+ # * similarity index
+ # * index configuration
+ #
+ # Indexed refers to them being indexed.
+ # This class notably offers the methods:
+ # * load
+ # * clear
+ #
+ # To (re)load or clear the current indexes.
+ #
+ class Bundle < Picky::Bundle
+
+ # Get the ids for the given symbol.
+ #
+ # Returns a (potentially empty) array of ids.
+ #
+ def ids sym
+ @inverted[sym] || []
+ end
+
+ # Get a weight for the given symbol.
+ #
+ # Returns a number, or nil.
+ #
+ def weight sym
+ @weights[sym]
+ end
+
+ # Get settings for this bundle.
+ #
+ # Returns an object.
+ #
+ def [] sym
+ @configuration[sym]
+ end
+
+ # Loads all indexes.
+ #
+ # Loading loads index objects from the backend.
+ # They should each respond to [].
+ #
+ def load
+ load_inverted
+ load_weights
+ load_similarity
+ load_configuration
+ end
+
+ # Loads the core index.
+ #
+ def load_inverted
+ self.inverted = @backend.load_inverted
+ end
+ # Loads the weights index.
+ #
+ def load_weights
+ self.weights = @backend.load_weights
+ end
+ # Loads the similarity index.
+ #
+ def load_similarity
+ self.similarity = @backend.load_similarity
+ end
+ # Loads the configuration.
+ #
+ def load_configuration
+ self.configuration = @backend.load_configuration
+ end
+
+ # Clears all indexes.
+ #
+ def clear
+ clear_inverted
+ clear_weights
+ clear_similarity
+ clear_configuration
+ end
+
+ # Clears the core index.
+ #
+ def clear_inverted
+ inverted.clear
+ end
+ # Clears the weights index.
+ #
+ def clear_weights
+ weights.clear
+ end
+ # Clears the similarity index.
+ #
+ def clear_similarity
+ similarity.clear
+ end
+ # Clears the configuration.
+ #
+ def clear_configuration
+ configuration.clear
+ end
+
+ end
+
+ end
+
+end
@@ -1,116 +0,0 @@
-module Picky
-
- module Indexed # :nodoc:all
-
- # An indexed bundle is a number of memory/redis
- # indexes that compose the indexes for a single category:
- # * core (inverted) index
- # * weights index
- # * similarity index
- # * index configuration
- #
- # Indexed refers to them being indexed.
- # This class notably offers the methods:
- # * load
- # * clear
- #
- # To (re)load or clear the current indexes.
- #
- module Bundle
-
- class Base < Picky::Bundle
-
- # Get the ids for the given symbol.
- #
- # Returns a (potentially empty) array of ids.
- #
- def ids sym
- @inverted[sym] || []
- end
-
- # Get a weight for the given symbol.
- #
- # Returns a number, or nil.
- #
- def weight sym
- @weights[sym]
- end
-
- # Get settings for this bundle.
- #
- # Returns an object.
- #
- def [] sym
- @configuration[sym]
- end
-
- # Loads all indexes.
- #
- # Loading loads index objects from the backend.
- # They should each respond to [].
- #
- def load
- load_inverted
- load_weights
- load_similarity
- load_configuration
- end
-
- # Loads the core index.
- #
- def load_inverted
- self.inverted = @backend.load_inverted
- end
- # Loads the weights index.
- #
- def load_weights
- self.weights = @backend.load_weights
- end
- # Loads the similarity index.
- #
- def load_similarity
- self.similarity = @backend.load_similarity
- end
- # Loads the configuration.
- #
- def load_configuration
- self.configuration = @backend.load_configuration
- end
-
- # Clears all indexes.
- #
- def clear
- clear_inverted
- clear_weights
- clear_similarity
- clear_configuration
- end
-
- # Clears the core index.
- #
- def clear_inverted
- inverted.clear
- end
- # Clears the weights index.
- #
- def clear_weights
- weights.clear
- end
- # Clears the similarity index.
- #
- def clear_similarity
- similarity.clear
- end
- # Clears the configuration.
- #
- def clear_configuration
- configuration.clear
- end
-
- end
-
- end
-
- end
-
-end
Oops, something went wrong.

0 comments on commit 536a852

Please sign in to comment.