Skip to content

Commit

Permalink
+ Redis, T-1 :)
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Feb 21, 2011
1 parent 1e6d1e0 commit ed045df
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion server/lib/picky/api/index/memory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Memory < Base
# a memory index backend.
#
def initialize name, source, options = {}
options[:bundle_class] ||= Indexed::Bundle::Memory
options[:indexing_bundle_class] ||= Indexing::Bundle::Memory

super name, source, options
end
Expand Down
2 changes: 1 addition & 1 deletion server/lib/picky/api/index/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Redis < Base
# a Redis index backend.
#
def initialize name, source, options = {}
options[:bundle_class] ||= Indexed::Bundle::Redis
options[:indexing_bundle_class] ||= Indexing::Bundle::Redis

super name, source, options
end
Expand Down
2 changes: 1 addition & 1 deletion server/lib/picky/indexing/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def initialize name, index, options = {}

# TODO The bundle needs to be an option.
#
bundle_class = options[:bundle_class] || Bundle::Memory
bundle_class = options[:indexing_bundle_class] || Bundle::Memory
@exact = bundle_class.new(:exact, configuration, similarity, Cacher::Partial::None.new, weights)
@partial = bundle_class.new(:partial, configuration, Cacher::Similarity::None.new, partial, weights)
end
Expand Down
10 changes: 8 additions & 2 deletions server/lib/picky/indexing/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def initialize name, source, options = {}
@source = source

@after_indexing = options[:after_indexing]
@bundle_class = options[:indexing_bundle_class] # TODO This should actually be a fixed parameter.

@categories = Categories.new
end
Expand All @@ -38,10 +39,15 @@ def define_category category_name, options = {}
new_category
end

# By default, the category uses the index's source.
# By default, the category uses
# * the index's source.
# * the index's bundle type.
#
def default_category_options
{ :source => @source }
{
:source => @source,
:indexing_bundle_class => @bundle_class
}
end

# Indexing.
Expand Down
31 changes: 21 additions & 10 deletions server/test_project/app/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ class BookSearch < Application
isbn_index = index :isbn, Sources::DB.new("SELECT id, isbn FROM books", :file => 'app/db.yml')
isbn_index.define_category :isbn, :qualifiers => [:i, :isbn]

geo_index = index :geo, Sources::CSV.new(:location, :north, :east, file: 'data/ch.csv', col_sep: ',')
geo_index.define_category :location
geo_index.define_map_location(:north1, 1, precision: 3, from: :north)
.define_map_location(:east1, 1, precision: 3, from: :east)
mgeo_index = index :memory_geo, Sources::CSV.new(:location, :north, :east, file: 'data/ch.csv', col_sep: ',')
mgeo_index.define_category :location
mgeo_index.define_map_location(:north1, 1, precision: 3, from: :north)
.define_map_location(:east1, 1, precision: 3, from: :east)

rgeo_index = API::Index::Redis.new :redis_geo, Sources::CSV.new(:location, :north, :east, file: 'data/ch.csv', col_sep: ',')
rgeo_index.define_category :location
rgeo_index.define_map_location(:north1, 1, precision: 3, from: :north)
.define_map_location(:east1, 1, precision: 3, from: :east)

csv_test_index = index(:csv_test, Sources::CSV.new(:title,:author,:isbn,:year,:publisher,:subjects, file: 'data/books.csv'))
.define_category(:title,
Expand Down Expand Up @@ -71,8 +76,11 @@ class BookSearch < Application
full_isbn = Query::Full.new isbn_index
live_isbn = Query::Live.new isbn_index

full_geo = Query::Full.new geo_index
live_geo = Query::Live.new geo_index
full_mgeo = Query::Full.new mgeo_index
live_mgeo = Query::Live.new mgeo_index

full_rgeo = Query::Full.new rgeo_index
live_rgeo = Query::Live.new rgeo_index

route %r{\A/admin\Z} => LiveParameters.new

Expand All @@ -84,11 +92,14 @@ class BookSearch < Application

%r{\A/isbn/full\Z} => full_isbn,

%r{\A/geo/full\Z} => full_geo,
%r{\A/geo/live\Z} => live_geo,
%r{\A/geo/full\Z} => full_mgeo,
%r{\A/geo/live\Z} => live_mgeo,

%r{\A/rgeo/full\Z} => full_rgeo,
%r{\A/rgeo/live\Z} => live_rgeo,

%r{\A/all/full\Z} => Query::Full.new(main_index, csv_test_index, isbn_index, geo_index, options),
%r{\A/all/live\Z} => Query::Live.new(main_index, csv_test_index, isbn_index, geo_index, options)
%r{\A/all/full\Z} => Query::Full.new(main_index, csv_test_index, isbn_index, mgeo_index, options),
%r{\A/all/live\Z} => Query::Live.new(main_index, csv_test_index, isbn_index, mgeo_index, options)

root 200

Expand Down
2 changes: 1 addition & 1 deletion server/test_project/spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Indexes.load_from_cache
@sym = Query::Full.new Indexes[:symbol_keys]
@csv = Query::Full.new Indexes[:csv_test]
@geo = Query::Full.new Indexes[:geo]
@geo = Query::Full.new Indexes[:memory_geo]
end

def self.it_should_find_ids_in_sym text, expected_ids
Expand Down

0 comments on commit ed045df

Please sign in to comment.