Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

! small fix for custom weight objects, + slight change to ignore_unas…

…signed_tokens (no parameter needed to set it to true)
  • Loading branch information...
commit 29e81c36d3f39b8748c26ffc8490c348b8e0fbd4 1 parent df6d5a3
Florian R. Hanke authored
4 history.textile
View
@@ -1,5 +1,9 @@
h2. Upcoming Version
+h2. Version 4.0.1
+
+* hanke: (server) Customized @weight@ and @similarity@ do not need the @saved?@ method anymore.
+
h2. Version 4.0.0
* hanke: No changes from 4.0.0pre7.
6 server/APIs.textile
View
@@ -22,7 +22,7 @@ h2. CharacterSubstituter (Picky::API::Tokenizer::CharacterSubstituter)
Has methods
-* @substitute(text)@ => @new text@ (with characters replaced)
+* @substitute(text)@ => @substituted_text@ (with characters replaced)
Accepted as
@@ -77,9 +77,9 @@ Has methods
h2. Search option boost (Picky::API::Search::Boosts)
-Hash methods
+Has methods
-* @weight_for(array_of_category_names)@ => @float@ (A negative or positive weight)
+* @boost_for(array_of_combinations)@ => @float@ (A negative or positive weight)
Accepted as parameter for the @boost@ method in a @Search.new@ block.
14 server/lib/picky/bundle.rb
View
@@ -92,7 +92,7 @@ def create_backends
#
def initialize_backends
@inverted = @backend_inverted.initial
- @weights = @weight_strategy.saved? ? @backend_weights.initial : @weight_strategy
+ @weights = @weight_strategy.respond_to?(:saved?) && !@weight_strategy.saved? ? @weight_strategy : @backend_weights.initial
@similarity = @backend_similarity.initial
@configuration = @backend_configuration.initial
@realtime = @backend_realtime.initial
@@ -102,11 +102,11 @@ def initialize_backends
# internal backend instance.
#
def empty
- @inverted = @backend_inverted.empty
- @weights = @weight_strategy.saved? ? @backend_weights.empty : @weight_strategy
- @similarity = @backend_similarity.empty
+ @inverted = @backend_inverted.empty
+ @weights = @weight_strategy.respond_to?(:saved?) && !@weight_strategy.saved? ? @weight_strategy : @backend_weights.empty
+ @similarity = @backend_similarity.empty
@configuration = @backend_configuration.empty
- @realtime = @backend_realtime.empty
+ @realtime = @backend_realtime.empty
end
# Delete all index files.
@@ -115,10 +115,10 @@ 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_weights.delete if @backend_weights.respond_to?(:delete) && @weight_strategy.respond_to?(:saved?) && @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
+ @backend_realtime.delete if @backend_realtime.respond_to? :delete
end
# Get a list of similar texts.
4 server/lib/picky/bundle_indexed.rb
View
@@ -79,12 +79,12 @@ def load_inverted
# Loads the weights index.
#
def load_weights
- self.weights = @backend_weights.load if @weight_strategy.saved?
+ self.weights = @backend_weights.load unless @weight_strategy.respond_to?(:saved?) && !@weight_strategy.saved?
end
# Loads the similarity index.
#
def load_similarity
- self.similarity = @backend_similarity.load if @similarity_strategy.saved?
+ self.similarity = @backend_similarity.load unless @similarity_strategy.respond_to?(:saved?) && !@similarity_strategy.saved?
end
# Loads the configuration.
#
4 server/lib/picky/bundle_indexing.rb
View
@@ -34,8 +34,8 @@ def dump
@backend_inverted.dump @inverted
# THINK about this. Perhaps the strategies should implement the backend methods? Or only the internal index ones?
#
- @backend_weights.dump @weights if @weight_strategy.saved?
- @backend_similarity.dump @similarity if @similarity_strategy.saved?
+ @backend_weights.dump @weights if @weight_strategy.respond_to?(:saved?) && @weight_strategy.saved?
+ @backend_similarity.dump @similarity if @similarity_strategy.respond_to?(:saved?) && @similarity_strategy.saved?
@backend_configuration.dump @configuration
@backend_realtime.dump @realtime
end
10 server/lib/picky/search.rb
View
@@ -19,7 +19,8 @@ class Search
include Helpers::Measuring
- attr_reader :indexes
+ attr_reader :indexes,
+ :ignore_unassigned
attr_accessor :tokenizer,
:boosts
@@ -44,7 +45,6 @@ def initialize *index_definitions
@tokenizer ||= Tokenizer.searching # THINK Not dynamic. Ok?
@boosts ||= Query::Boosts.new
- @ignore_unassigned = false if @ignore_unassigned.nil?
self
end
@@ -156,14 +156,14 @@ def boost boosts
#
# Example:
# search = Search.new(books_index, dvd_index, mp3_index) do
- # ignore_unassigned_tokens true
+ # ignore_unassigned_tokens
# end
#
- # With this set to true, if in "Peter Flunder", "Flunder"
+ # With this set (to true), if in "Peter Flunder", "Flunder"
# couldn't be assigned to any category, it will simply be
# ignored. This is done for each categorization.
#
- def ignore_unassigned_tokens value
+ def ignore_unassigned_tokens value = true
@ignore_unassigned = value
end
33 server/spec/lib/search_spec.rb
View
@@ -111,6 +111,39 @@
end
end
+ describe 'ignore_unassigned_tokens' do
+ let(:search) { described_class.new @index }
+ context 'by default' do
+ it 'is falsy' do
+ search.ignore_unassigned.should be_false
+ end
+ end
+ context 'set to nothing' do
+ before(:each) do
+ search.ignore_unassigned_tokens
+ end
+ it 'is truey' do
+ search.ignore_unassigned.should be_true
+ end
+ end
+ context 'set to true' do
+ before(:each) do
+ search.ignore_unassigned_tokens true
+ end
+ it 'is truey' do
+ search.ignore_unassigned.should be_true
+ end
+ end
+ context 'set to false' do
+ before(:each) do
+ search.ignore_unassigned_tokens false
+ end
+ it 'is falsy' do
+ search.ignore_unassigned.should be_false
+ end
+ end
+ end
+
describe 'initializer' do
context 'with tokenizer' do
before(:each) do
2  version.rb
View
@@ -1,3 +1,3 @@
module Picky
- VERSION = '4.0.0'
+ VERSION = '4.0.1'
end
Please sign in to comment.
Something went wrong with that request. Please try again.