Skip to content
Browse files

+ internal rewrite finished, API polished

  • Loading branch information...
1 parent 18fd38d commit 85337588f5bb5aa8ad047de8dc4336a2dde44abf @floere committed Jul 4, 2011
View
2 server/lib/picky/categories.rb
@@ -56,7 +56,7 @@ def << category
end
def to_s
- categories.indented_to_s
+ categories.join(', ')
end
end
View
10 server/lib/picky/category.rb
@@ -1,13 +1,7 @@
class Category
attr_reader :name,
- :index,
-
- :indexing_exact,
- :indexing_partial,
-
- :indexed_exact,
- :indexed_partial
+ :index
# Mandatory params:
# * name: Category name to use as identifier and file names.
@@ -127,7 +121,7 @@ def to_info
end
def to_s
- "Category(#{name} in #{@index.name})"
+ "Category(#{name})"
end
end
View
12 server/lib/picky/category_indexed.rb
@@ -2,6 +2,8 @@
#
class Category
+ attr_reader :indexed_exact
+
# TODO Move to Index.
#
def generate_qualifiers_from options
@@ -23,8 +25,8 @@ def load_from_cache
#
def analyze collector
collector[identifier] = {
- :exact => Analyzer.new.analyze(exact),
- :partial => Analyzer.new.analyze(partial)
+ :exact => Analyzer.new.analyze(indexed_exact),
+ :partial => Analyzer.new.analyze(indexed_partial)
}
collector
end
@@ -44,13 +46,13 @@ def ids token
# Returns the right index bundle for this token.
#
def bundle_for token
- token.partial?? indexed_partial : indexed_exact
+ token.partial? ? indexed_partial : indexed_exact
end
# The partial strategy defines whether to really use the partial index.
#
- def partial
- @partial_strategy.use_exact_for_partial?? @indexed_exact : @indexed_partial
+ def indexed_partial
+ @partial_strategy.use_exact_for_partial? ? @indexed_exact : @indexed_partial
end
#
View
35 server/lib/picky/category_indexing.rb
@@ -1,7 +1,10 @@
#
#
class Category
-
+
+ attr_reader :indexing_exact,
+ :indexing_partial
+
# Prepares and caches this category.
#
# This one should be used by users.
@@ -10,13 +13,13 @@ def index
prepare
cache
end
-
+
# Return an appropriate source.
#
def source
@source || @index.source
end
-
+
# Return the key format.
#
# If the source has no key format, then
@@ -27,33 +30,33 @@ def source
def key_format
source.respond_to?(:key_format) && source.key_format || @key_format || @index.key_format
end
-
+
# Where the data is taken from.
#
def from
@from || name
end
-
+
# The indexer is lazily generated and cached.
#
def indexer
@indexer ||= source.respond_to?(:each) ? Indexers::Parallel.new(self) : Indexers::Serial.new(self)
end
-
- # TODO This is a hack to get the parallel indexer working.
+
+ # TODO This is a hack to get the parallel indexer working.
#
def categories
[self]
end
-
+
# Returns an appropriate tokenizer.
# If one isn't set on this category, will try the index,
# and finally the default index tokenizer.
#
def tokenizer
@tokenizer || @index.tokenizer || Tokenizers::Index.default
end
-
+
# Backup the caches.
# (Revert with restore_caches)
#
@@ -62,7 +65,7 @@ def backup_caches
indexing_exact.backup
indexing_partial.backup
end
-
+
# Restore the caches.
# (Revert with backup_caches)
#
@@ -71,23 +74,23 @@ def restore_caches
indexing_exact.restore
indexing_partial.restore
end
-
+
# Checks the caches for existence.
#
def check_caches
timed_exclaim "Checking #{identifier}."
indexing_exact.raise_unless_cache_exists
indexing_partial.raise_unless_cache_exists
end
-
+
# Deletes the caches.
#
def clear_caches
timed_exclaim "Deleting #{identifier}."
indexing_exact.delete
indexing_partial.delete
end
-
+
# We need to set what formatting method should be used.
# Uses the one defined in the indexer.
#
@@ -97,7 +100,7 @@ def configure
indexing_exact[:key_format] = self.key_format
indexing_partial[:key_format] = self.key_format
end
-
+
# Indexes, creates the "prepared_..." file.
#
# TODO This step could already prepare the id (if a
@@ -114,7 +117,7 @@ def cache
prepare_index_directory
generate_caches
end
-
+
# Generate the cache data.
#
def generate_caches
@@ -138,5 +141,5 @@ def dump_caches
indexing_exact.dump
indexing_partial.dump
end
-
+
end
View
2 server/lib/picky/index/base.rb
@@ -388,7 +388,7 @@ def method_name
#
#
def to_s
- "#{self.class}(#{name}, result id: #{result_identifier}, #{source}, #{categories})"
+ "#{self.class}(#{name}, result_id: #{result_identifier}, source: #{source}, categories: #{categories})"
end
def to_stats # :nodoc:
View
8 server/spec/lib/category_indexed_spec.rb
@@ -29,12 +29,12 @@
@partial_strategy.stub! :use_exact_for_partial? => true
end
it 'returns the partial index' do
- @category.partial.should be_kind_of(Indexed::Bundle::Memory)
+ @category.indexed_partial.should be_kind_of(Indexed::Bundle::Memory)
end
end
context 'with a partial strategy that uses the partial index (default)' do
it 'returns the partial index' do
- @category.partial.should be_kind_of(Indexed::Bundle::Memory)
+ @category.indexed_partial.should be_kind_of(Indexed::Bundle::Memory)
end
end
end
@@ -47,12 +47,12 @@
@partial_strategy.stub! :use_exact_for_partial? => true
end
it 'returns the partial index' do
- @category.partial.should be_kind_of(Indexed::Bundle::Redis)
+ @category.indexed_partial.should be_kind_of(Indexed::Bundle::Redis)
end
end
context 'with a partial strategy that uses the partial index (default)' do
it 'returns the partial index' do
- @category.partial.should be_kind_of(Indexed::Bundle::Redis)
+ @category.indexed_partial.should be_kind_of(Indexed::Bundle::Redis)
end
end
end
View
30 server/spec/lib/indexes_class_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+describe Indexes do
+
+ before(:each) do
+ @index = stub :some_index, :name => :some_index
+ @indexes = described_class.instance
+ end
+
+ describe 'clear' do
+ it 'clears the indexes' do
+ Indexes.register @index
+
+ Indexes.clear
+
+ @indexes.indexes.should == []
+ end
+ end
+
+ describe 'register' do
+ it 'adds the given index to the indexes' do
+ Indexes.clear
+
+ Indexes.register @index
+
+ @indexes.indexes.should == [@index]
+ end
+ end
+
+end
View
6 server/spec/lib/indexes_indexing_spec.rb
@@ -22,10 +22,8 @@
describe 'index_for_tests' do
it 'takes a snapshot, then indexes and caches each' do
indexes.should_receive(:take_snapshot).once.with.ordered
- @index1.should_receive(:prepare).once.with.ordered
- @index1.should_receive(:cache).once.with.ordered
- @index2.should_receive(:prepare).once.with.ordered
- @index2.should_receive(:cache).once.with.ordered
+ @index1.should_receive(:index).once.with.ordered
+ @index2.should_receive(:index).once.with.ordered
indexes.index_for_tests
end
View
2 server/spec/lib/indexes_spec.rb
@@ -28,6 +28,8 @@
describe 'register' do
it 'adds the given index to the indexes' do
+ @indexes.clear
+
@indexes.register @index
@indexes.indexes.should == [@index]
View
6 server/test_project/spec/integration_spec.rb
@@ -71,10 +71,8 @@
RedisChangingItem.new("3", 'third entry'),
RedisChangingItem.new("4", 'fourth entry') # Added.
]
- redis_changing_index = Indexes[:redis_changing]
- redis_changing_index.define_source new_source
- redis_changing_index.prepare
- redis_changing_index.cache
+ Indexes[:redis_changing].source new_source
+ Indexes[:redis_changing].reindex
redis_changing.search('entry').ids.should == ["2", "3", "4"]
end

0 comments on commit 8533758

Please sign in to comment.
Something went wrong with that request. Please try again.