Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 4321f8e51919968f7c5eec9156cb7439d7cd9775 @romul committed Jan 29, 2010
Showing with 249 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +136 −0 Rakefile
  3. +5 −0 config/routes.rb
  4. +15 −0 config/solr.yml
  5. +21 −0 lib/spree/search/solr.rb
  6. +2 −0 lib/tasks/acts_as_solr.rake
  7. +24 −0 solr_search_extension.rb
  8. +43 −0 solr_search_hooks.rb
@@ -0,0 +1,3 @@
+solr
+log/*.log
+tmp/pids/*
136 Rakefile
@@ -0,0 +1,136 @@
+# I think this is the one that should be moved to the extension Rakefile template
+
+# In rails 1.2, plugins aren't available in the path until they're loaded.
+# Check to see if the rspec plugin is installed first and require
+# it if it is. If not, use the gem version.
+
+# Determine where the RSpec plugin is by loading the boot
+unless defined? SPREE_ROOT
+ ENV["RAILS_ENV"] = "test"
+ case
+ when ENV["SPREE_ENV_FILE"]
+ require File.dirname(ENV["SPREE_ENV_FILE"]) + "/boot"
+ when File.dirname(__FILE__) =~ %r{vendor/SPREE/vendor/extensions}
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
+ else
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
+ end
+end
+
+require 'rake'
+require 'rake/rdoctask'
+require 'rake/testtask'
+
+rspec_base = File.expand_path(SPREE_ROOT + '/vendor/plugins/rspec/lib')
+$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
+require 'spec/rake/spectask'
+# require 'spec/translator'
+
+# Cleanup the SPREE_ROOT constant so specs will load the environment
+Object.send(:remove_const, :SPREE_ROOT)
+
+extension_root = File.expand_path(File.dirname(__FILE__))
+
+task :default => :spec
+task :stats => "spec:statsetup"
+
+desc "Run all specs in spec directory"
+Spec::Rake::SpecTask.new(:spec) do |t|
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
+ t.spec_files = FileList["#{extension_root}/spec/**/*_spec.rb"]
+end
+
+namespace :spec do
+ desc "Run all specs in spec directory with RCov"
+ Spec::Rake::SpecTask.new(:rcov) do |t|
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.rcov = true
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
+ end
+
+ desc "Print Specdoc for all specs"
+ Spec::Rake::SpecTask.new(:doc) do |t|
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ end
+
+ [:models, :controllers, :views, :helpers].each do |sub|
+ desc "Run the specs under spec/#{sub}"
+ Spec::Rake::SpecTask.new(sub) do |t|
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
+ end
+ end
+
+ # Hopefully no one has written their extensions in pre-0.9 style
+ # desc "Translate specs from pre-0.9 to 0.9 style"
+ # task :translate do
+ # translator = ::Spec::Translator.new
+ # dir = RAILS_ROOT + '/spec'
+ # translator.translate(dir, dir)
+ # end
+
+ # Setup specs for stats
+ task :statsetup do
+ require 'code_statistics'
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
+ ::CodeStatistics::TEST_TYPES << "Model specs"
+ ::CodeStatistics::TEST_TYPES << "View specs"
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
+ end
+
+ namespace :db do
+ namespace :fixtures do
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
+ task :load => :environment do
+ require 'active_record/fixtures'
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
+ end
+ end
+ end
+ end
+end
+
+desc 'Generate documentation for the xapit_search extension.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'XapitSearchExtension'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+# For extensions that are in transition
+desc 'Test the xapit_search extension.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+namespace :test do
+ desc 'Functional test the xapit_search extension.'
+ Rake::TestTask.new(:functionals) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/functional/*_test.rb'
+ t.verbose = true
+ end
+
+ desc 'Unit test the xapit_search extension.'
+ Rake::TestTask.new(:units) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/unit/*_test.rb'
+ t.verbose = true
+ end
+end
+
+# Load any custom rakefiles for extension
+Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
@@ -0,0 +1,5 @@
+# Put your extension routes here.
+
+# map.namespace :admin do |admin|
+# admin.resources :whatever
+# end
@@ -0,0 +1,15 @@
+# Config file for the acts_as_solr plugin.
+#
+# If you change the host or port number here, make sure you update
+# them in your Solr config file
+
+development:
+ url: http://127.0.0.1:8982/solr
+
+production:
+ url: http://127.0.0.1:8983/solr
+ jvm_options: -server -d64 -Xmx1024M -Xms64M
+
+test:
+ url: http://127.0.0.1:8981/solr
+
@@ -0,0 +1,21 @@
+module Spree::Search
+ class Solr < Spree::Search::Base
+ # method should return hash with conditions {:conditions=> "..."} for Product model
+ def get_products_conditions_for(query)
+ result = Product.find_by_solr(query)
+
+ @properties[:products] = result.records
+
+ {:conditions=> ["products.id IN (?)", products.map(&:id)]}
+ end
+
+ def prepare(params)
+ @properties[:facets_hash] = params[:facets]
+ @properties[:taxon] = params[:taxon].blank? ? nil : Taxon.find(params[:taxon])
+ @properties[:per_page] = params[:per_page]
+ @properties[:page] = params[:page]
+ @properties[:manage_pagination] = true
+ @properties[:order_by_price] = params[:order_by_price]
+ end
+ end
+end
@@ -0,0 +1,2 @@
+require "acts_as_solr/tasks"
+
@@ -0,0 +1,24 @@
+# Uncomment this if you reference any of your controllers in activate
+# require_dependency 'application'
+
+class SolrSearchExtension < Spree::Extension
+ version "1.0"
+ description "Describe your extension here"
+ url "http://yourwebsite.com/solr_search"
+
+ # Please use solr_search/config/routes.rb instead for extension routes.
+
+ def self.require_gems(config)
+ config.gem "acts_as_solr_reloaded", :version => '1.2.0'
+ end
+
+ def activate
+ require 'acts_as_solr'
+
+ Product.class_eval do
+ acts_as_solr :fields => [:name, :description]
+ end
+
+ Spree::Config.searcher = Spree::Search::Solr.new
+ end
+end
@@ -0,0 +1,43 @@
+class SolrSearchHooks < Spree::ThemeSupport::HookListener
+
+ #
+ # In this file you can modify the content of the hooks available in the default templates
+ # and avoid overriding a template in many situations. Multiple extensions can modify the
+ # same hook, the changes being applied cumulatively based on extension load order
+ #
+ # Most hooks are defined with blocks so they span a region of the template, allowing content
+ # to be replaced or removed as well as added to.
+ #
+ # Usage
+ #
+ # The following methods are available
+ #
+ # * insert_before
+ # * insert_after
+ # * replace
+ # * remove
+ #
+ # All accept a block name symbol followed either by arguments that would be valid for 'render'
+ # or a block which returns the string to be inserted. The block will have access to any methods
+ # or instance variables accessible in your views
+ #
+ # Examples
+ #
+ # insert_before :homepage_products, :text => "<h1>Welcome!</h1>"
+ # insert_after :homepage_products, 'shared/offers' # renders a partial
+ # replace :taxon_sidebar_navigation, 'shared/my_sidebar
+ #
+ # adding a link below product details:
+ #
+ # insert_after :product_description do
+ # '<p>' + link_to('Back to products', products_path) + '</p>'
+ # end
+ #
+ # adding a new tab to the admin navigation
+ #
+ # insert_after :admin_tabs do
+ # tab(:taxonomies)
+ # end
+ #
+
+end

0 comments on commit 4321f8e

Please sign in to comment.