lib/picky/bundle.rb in picky-4.0.0pre2 vs lib/picky/bundle.rb in picky-4.0.0pre3
- old
+ new
@@ -33,23 +33,24 @@
:backend_inverted,
:backend_weights,
:backend_similarity,
:backend_configuration,
+ :backend_realtime,
- :weights_strategy,
+ :weight_strategy,
:partial_strategy,
:similarity_strategy
delegate :[], :[]=, :to => :configuration
delegate :index_directory, :to => :category
- def initialize name, category, weights_strategy, partial_strategy, similarity_strategy, options = {}
+ def initialize name, category, weight_strategy, partial_strategy, similarity_strategy, options = {}
@name = name
@category = category
- @weights_strategy = weights_strategy
+ @weight_strategy = weight_strategy
@partial_strategy = partial_strategy
@similarity_strategy = similarity_strategy
@key_format = options.delete :key_format
@backend = options.delete :backend
@@ -68,58 +69,65 @@
end
# Initializes all necessary indexes from the backend.
#
def reset_backend
- # Extract specific indexes from backend.
- #
- @backend_inverted = backend.create_inverted self
- @backend_weights = backend.create_weights self
- @backend_similarity = backend.create_similarity self
+ create_backends
+ initialize_backends
+ end
+
+ # Extract specific indexes from backend.
+ #
+ def create_backends
+ @backend_inverted = backend.create_inverted self
+ @backend_weights = backend.create_weights self
+ @backend_similarity = backend.create_similarity self
@backend_configuration = backend.create_configuration self
- @backend_realtime = backend.create_realtime self
+ @backend_realtime = backend.create_realtime self
+ end
- # Initial indexes.
- #
- # Note that if the weights strategy doesn't need to be saved,
- # the strategy itself pretends to be an index.
- #
+ # Initial indexes.
+ #
+ # Note that if the weights strategy doesn't need to be saved,
+ # the strategy itself pretends to be an index.
+ #
+ def initialize_backends
+ # @inverted, @weights, @similarity, @configuration, @realtime = backend.initial weight_strategy
@inverted = @backend_inverted.initial
- @weights = @weights_strategy.saved?? @backend_weights.initial : @weights_strategy
+ # TODO @weights = @weight_strategy.initial || @backend_weights.initial
+ #
+ @weights = @weight_strategy.saved?? @backend_weights.initial : @weight_strategy
@similarity = @backend_similarity.initial
@configuration = @backend_configuration.initial
@realtime = @backend_realtime.initial
end
# "Empties" the index(es) by getting a new empty
# internal backend instance.
#
def empty
- empty_inverted
- empty_weights
- empty_similarity
- empty_configuration
- empty_realtime
- end
- def empty_inverted
@inverted = @backend_inverted.empty
- end
- def empty_weights
# THINK about this. Perhaps the strategies should implement the backend methods?
#
- @weights = @weights_strategy.saved?? @backend_weights.empty : @weights_strategy
- end
- def empty_similarity
+ @weights = @weight_strategy.saved? ? @backend_weights.empty : @weight_strategy
@similarity = @backend_similarity.empty
- end
- def empty_configuration
@configuration = @backend_configuration.empty
- end
- def empty_realtime
@realtime = @backend_realtime.empty
end
+ # Delete all index files.
+ #
+ def delete
+ @backend_inverted.delete if @backend_inverted.respond_to? :delete
+ # THINK about this. Perhaps the strategies should implement the backend methods?
+ #
+ @backend_weights.delete if @backend_weights.respond_to?(:delete) && @weight_strategy.saved?
+ @backend_similarity.delete if @backend_similarity.respond_to? :delete
+ @backend_configuration.delete if @backend_configuration.respond_to? :delete
+ @backend_realtime.delete if @backend_realtime.respond_to? :delete
+ end
+
# Get a list of similar texts.
#
# Note: Does not return itself.
#
def similar text
@@ -152,21 +160,9 @@
# Returns just the part without subindex type,
# if none given.
#
def index_path type = nil
::File.join index_directory, "#{category.name}_#{name}#{ "_#{type}" if type }"
- end
-
- # Delete all index files.
- #
- def delete
- @backend_inverted.delete if @backend_inverted.respond_to? :delete
- # THINK about this. Perhaps the strategies should implement the backend methods?
- #
- @backend_weights.delete if @backend_weights.respond_to?(:delete) && @weights_strategy.saved?
- @backend_similarity.delete if @backend_similarity.respond_to? :delete
- @backend_configuration.delete if @backend_configuration.respond_to? :delete
- @backend_realtime.delete if @backend_realtime.respond_to? :delete
end
def to_s
"#{self.class}(#{identifier})"
end
\ No newline at end of file