Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+ handle dynamic weights, + integration spec for "indexing" dynamic w…

…eights
  • Loading branch information...
commit 4ac45a11a10d8c287066b2e3e9cb20fed0af58f4 1 parent 28e2083
@floere authored
View
14 server/lib/picky/bundle.rb
@@ -93,6 +93,8 @@ 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
@@ -138,7 +140,9 @@ def index_path type = nil
#
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
@@ -147,7 +151,9 @@ def backup
#
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
@@ -156,7 +162,9 @@ def restore
#
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
View
8 server/lib/picky/bundle_indexed.rb
@@ -62,7 +62,9 @@ def load_inverted
# Loads the weights index.
#
def load_weights
- self.weights = @backend_weights.load
+ # TODO THINK about this. Perhaps the strategies should implement the backend methods?
+ #
+ self.weights = @backend_weights.load if @weights_strategy.saved?
end
# Loads the similarity index.
#
@@ -92,7 +94,9 @@ def clear_inverted
# Clears the weights index.
#
def clear_weights
- weights.clear
+ # TODO THINK about this. Perhaps the strategies should implement the backend methods?
+ #
+ weights.clear if @weights_strategy.saved?
end
# Clears the similarity index.
#
View
10 server/lib/picky/bundle_indexing.rb
@@ -46,22 +46,24 @@ def dump
# Dumps the core index.
#
def dump_inverted
- @backend_inverted.dump self.inverted
+ @backend_inverted.dump @inverted
end
# Dumps the weights index.
#
def dump_weights
- @backend_weights.dump self.weights
+ # TODO THINK about this. Perhaps the strategies should implement the backend methods?
+ #
+ @backend_weights.dump @weights if @weights_strategy.saved?
end
# Dumps the similarity index.
#
def dump_similarity
- @backend_similarity.dump self.similarity
+ @backend_similarity.dump @similarity
end
# Dumps the similarity index.
#
def dump_configuration
- @backend_configuration.dump self.configuration
+ @backend_configuration.dump @configuration
end
end
View
16 server/test_project_sinatra/app.rb
@@ -329,6 +329,22 @@ def tokenize nonstring
category :none, partial: Picky::Partial::None.new
end
+ # This just tests indexing.
+ #
+ WeightsItem = Struct.new :id, :logarithmic, :constant_default, :constant, :dynamic
+ Picky::Index.new(:weights) do
+ source do
+ [
+ WeightsItem.new(1, "octopussy", "octopussy", "octopussy", "octopussy"),
+ WeightsItem.new(2, "abracadabra", "abracadabra", "abracadabra", "abracadabra")
+ ]
+ end
+ category :logarithmic, weights: Picky::Weights::Logarithmic.new
+ category :constant_default, weights: Picky::Weights::Constant.new
+ category :constant, weights: Picky::Weights::Constant.new(3.14)
+ category :dynamic, weights: Picky::Weights::Dynamic.new { |token| token.size }
+ end
+
weights = {
[:author] => +6,
[:title, :author] => +5,
Please sign in to comment.
Something went wrong with that request. Please try again.