Skip to content

Commit

Permalink
! Indexing of a single category using #each.
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Jul 1, 2011
1 parent 93f7bd5 commit 029c435
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions server/lib/picky/internals/indexers/parallel.rb
Expand Up @@ -6,6 +6,8 @@ module Indexers
#
# The tokenizer is taken from each category if specified, from the index, if not.
#
# TODO Think about this one more. It should work on an index, but also a single category.
#
class Parallel < Base

delegate :categories, :source, :to => :@index
Expand Down
7 changes: 6 additions & 1 deletion server/lib/picky/internals/indexing/category.rb
Expand Up @@ -62,7 +62,12 @@ def key_format
# The indexer is lazily generated and cached.
#
def indexer
@indexer ||= Indexers::Serial.new self
@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.
#
def categories
[self]
end
# Returns an appropriate tokenizer.
# If one isn't set on this category, will try the index,
Expand Down
2 changes: 2 additions & 0 deletions server/lib/picky/internals/indexing/index.rb
Expand Up @@ -98,6 +98,8 @@ def find category_name
# delegate to each category to index themselves.
#
def index!
# TODO Duplicated in category.rb def indexer.
#
if source.respond_to?(:each)
warn %Q{\n\033[1mWarning\033[m, source for index "#{name}" is empty: #{source} (responds true to empty?).\n} if source.respond_to?(:empty?) && source.empty?
index_parallel
Expand Down
10 changes: 9 additions & 1 deletion server/test_project/spec/integration_spec.rb
Expand Up @@ -17,7 +17,11 @@
let(:geo) { Picky::TestClient.new(described_class, :path => '/geo') }
let(:simple_geo) { Picky::TestClient.new(described_class, :path => '/simple_geo') }
let(:indexing) { Picky::TestClient.new(described_class, :path => '/indexing') }


it 'can generate a single index category without failing' do
Indexes.generate_index_only :book_each, :title
end

it 'is has the right amount of results' do
csv.search('alan').total.should == 3
end
Expand Down Expand Up @@ -177,5 +181,9 @@
it { csv.search("history fergus").ids.should == [4, 4] }
it { csv.search("HISTORY FERGUS").ids.should == [] }
it { csv.search("history AND OR fergus").ids.should == [4, 4] }

# Specific indexing.
#


end

0 comments on commit 029c435

Please sign in to comment.