lib/picky/bundle.rb in picky-3.5.0 vs lib/picky/bundle.rb in picky-3.5.1
- old
+ new
@@ -64,21 +64,48 @@
@backend_similarity = backend.create_similarity self
@backend_configuration = backend.create_configuration self
# Initial indexes.
#
+ # Note that if the weights strategy doesn't need to be saved,
+ # the strategy itself pretends to be an index.
+ #
@inverted = @backend_inverted.initial
- @weights = @backend_weights.initial
+ @weights = @weights_strategy.saved?? @backend_weights.initial : @weights_strategy
@similarity = @backend_similarity.initial
@configuration = @backend_configuration.initial
@realtime_mapping = {} # id -> ary of syms. TODO Always instantiate?
end
def identifier
"#{category.identifier}:#{name}"
end
+ # "Empties" the index(es) by getting a new empty
+ # internal backend instance.
+ #
+ def empty
+ empty_inverted
+ empty_weights
+ empty_similarity
+ empty_configuration
+ end
+ def empty_inverted
+ @inverted = @backend_inverted.empty
+ end
+ def empty_weights
+ # TODO THINK about this. Perhaps the strategies should implement the backend methods?
+ #
+ @weights = @weights_strategy.saved?? @backend_weights.empty : @weights_strategy
+ end
+ def empty_similarity
+ @similarity = @backend_similarity.empty
+ end
+ def empty_configuration
+ @configuration = @backend_configuration.empty
+ end
+
# Get a list of similar texts.
#
# Note: Does not return itself.
#
def similar text
@@ -111,28 +138,34 @@
# Copies the indexes to the "backup" directory.
#
def backup
@backend_inverted.backup if @backend_inverted.respond_to? :backup
- @backend_weights.backup if @backend_weights.respond_to? :backup
+ # TODO THINK about this. Perhaps the strategies should implement the backend methods?
+ #
+ @backend_weights.backup if @backend_weights.respond_to? :backup && @weights_strategy.saved?
@backend_similarity.backup if @backend_similarity.respond_to? :backup
@backend_configuration.backup if @backend_configuration.respond_to? :backup
end
# Restores the indexes from the "backup" directory.
#
def restore
@backend_inverted.restore if @backend_inverted.respond_to? :restore
- @backend_weights.restore if @backend_weights.respond_to? :restore
+ # TODO THINK about this. Perhaps the strategies should implement the backend methods?
+ #
+ @backend_weights.restore if @backend_weights.respond_to? :restore && @weights_strategy.saved?
@backend_similarity.restore if @backend_similarity.respond_to? :restore
@backend_configuration.restore if @backend_configuration.respond_to? :restore
end
# Delete all index files.
#
def delete
@backend_inverted.delete if @backend_inverted.respond_to? :delete
- @backend_weights.delete if @backend_weights.respond_to? :delete
+ # TODO 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
end
# Alerts the user if an index is missing.
\ No newline at end of file