Permalink
Browse files

new version and such

  • Loading branch information...
1 parent 5a9bc20 commit d83d81f5c7b7c3c5c57829bacdf75649729e8643 @hybridindie committed Dec 4, 2012
Showing with 694 additions and 2,768 deletions.
  1. +11 −1 Gemfile
  2. +11 −8 LICENSE
  3. +11 −58 README.md
  4. +22 −67 Rakefile
  5. +0 −3 app/assets/javascripts/store/solr_sort_by.js.coffee
  6. +0 −12 app/helpers/spree/base_helper_decorator.rb
  7. +0 −85 app/models/product_decorator.rb
  8. +5 −0 app/models/spree/app_configuration_decorator.rb
  9. +0 −5 app/models/spree/sunspot_configuration.rb
  10. +20 −0 app/models/spree_product_decorator.rb
  11. +0 −5 app/overrides/add_search_facets.rb
  12. +0 −5 app/overrides/add_search_pagination.rb
  13. +0 −4 app/overrides/add_search_sort.rb
  14. +0 −8 app/overrides/add_search_suggestion.rb
  15. +0 −42 app/views/spree/products/_facets.html.erb
  16. +0 −18 app/views/spree/products/_sort_bar.html.erb
  17. +0 −6 app/views/spree/products/_suggestion.html.erb
  18. +6 −5 config/locales/en.yml
  19. +0 −31 lib/conf/admin-extra.html
  20. +0 −36 lib/conf/elevate.xml
  21. +0 −246 lib/conf/mapping-ISOLatin1Accent.txt
  22. +0 −21 lib/conf/protwords.txt
  23. +0 −238 lib/conf/schema.xml
  24. +0 −24 lib/conf/scripts.conf
  25. +0 −934 lib/conf/solrconfig.xml
  26. +0 −2 lib/conf/spellings.txt
  27. +0 −58 lib/conf/stopwords.txt
  28. +0 −31 lib/conf/synonyms.txt
  29. +0 −132 lib/conf/xslt/example.xsl
  30. +0 −67 lib/conf/xslt/example_atom.xsl
  31. +0 −66 lib/conf/xslt/example_rss.xsl
  32. +0 −337 lib/conf/xslt/luke.xsl
  33. +44 −0 lib/generators/spree/sunspot/install/install_generator.rb
  34. +48 −0 lib/generators/spree/sunspot/install/templates/config/initializers/spree_sunspot.rb
  35. +0 −15 lib/generators/spree_sunspot_search/install/install_generator.rb
  36. +0 −12 lib/generators/templates/spree_sunspot_search.rb
  37. +0 −64 lib/spree/search/configuration.rb
  38. +0 −22 lib/spree/search/engine.rb
  39. +0 −65 lib/spree/search/sunspot.rb
  40. +36 −0 lib/spree/sunspot/engine.rb
  41. +62 −0 lib/spree/sunspot/filter/condition.rb
  42. +62 −0 lib/spree/sunspot/filter/filter.rb
  43. +54 −0 lib/spree/sunspot/filter/param.rb
  44. +36 −0 lib/spree/sunspot/filter/query.rb
  45. +73 −0 lib/spree/sunspot/filter_support.rb
  46. +30 −0 lib/spree/sunspot/filters.rb
  47. +100 −0 lib/spree/sunspot/search.rb
  48. +27 −0 lib/spree/sunspot/setup.rb
  49. +2 −0 lib/spree_sunspot.rb
  50. +0 −13 lib/spree_sunspot_search.rb
  51. +8 −0 lib/tasks/spree_sunspot.rake
  52. +13 −13 spec/spec_helper.rb
  53. +13 −9 spree_sunspot_search.gemspec
View
12 Gemfile
@@ -1,3 +1,13 @@
source 'http://rubygems.org'
-gemspec
+group :test do
+ gem 'ffaker'
+end
+
+if RUBY_VERSION < "1.9"
+ gem "ruby-debug"
+else
+ gem "ruby-debug19"
+end
+
+gemspec
View
19 LICENSE
@@ -1,14 +1,17 @@
-Redistribution and use in source and binary forms, with or without modification,
+Copyright (c) 2012 [name of plugin creator]
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice,
+ * Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- * Neither the name of the Rails Dog LLC nor the names of its
- contributors may be used to endorse or promote products derived from this
- software without specific prior written permission.
+ * Neither the name Spree nor the names of its contributors may be used to
+ endorse or promote products derived from this software without specific
+ prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -20,4 +23,4 @@ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -1,68 +1,21 @@
-SpreeSunspotSearch
-==================
+Spree::Sunspot
+==============
-Adds Solr search to Spree using [Sunspot](https://github.com/sunspot/sunspot). This is a moving targer and is very beta and should be treated as such.
+Introduction goes here.
-This is compatible with Spree 1.2. I haven't tested it below that.
-
-Install
-=======
-
-I make the assumption that you have a functioning Spree store and are just extending the search capabilities with Sunspot/Solr
-
-Add spree_sunspot_search to your Gemfile and run bundler.
-
-`gem 'spree_sunspot_search', git: 'git://github.com/jbrien/spree_sunspot_search.git'`
-
-add the following to the Gemfile if you are not using another solr install locally for testing and development. The rake tasks for starting and stop this for development are included automatically for your use.
-
- group :test, :development do
- gem 'sunspot_solr'
- end
-
-
-Install the solr.yml file from Sunspot.
-
-`rails g sunspot_rails:install`
-
-Copy the initializer and add `solr_sort_by` to `all.js`
-
-`rails g spree_sunspot_search:install`
-
-Running
+Example
=======
-Start up Solr (bundled with Sunspot's install)
-
-`rake sunspot:solr:run`
-
-Build the index for the first time
-
-`rake sunspot:reindex`
-
-Customise the Facets Shown
---------------------------
-
-Edit the initializer and specify you Product Properties, Product Options, and Price Ranges as an array.
-The initializer should provide enough examples to get you started.
+Example goes here.
Testing
-=======
-
-TODO
+-------
-TODOs
-=====
+Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.
-* Add an automatic MAX value for price facets (e.g. Above <max_said_value>)
-* Sorting by facet criteria and Solr analytics (Best result, Popular, etc.)
-* Open the Sunspot DSL to utilise all the additional data and analytics available through Solr
-* Get the Taxon browsing (e.g. Categories) to utilise the Solr data for speed boosts
-
-Authors
-=======
-* @jbrien
-* @iloveitaly
+ $ bundle
+ $ bundle exec rake test app
+ $ bundle exec rspec spec
-Copyright (c) 2011 John Brien Dilts, released under the New BSD License
+Copyright (c) 2012 [name of extension creator], released under the New BSD License
View
@@ -1,75 +1,30 @@
-require 'rubygems'
-require 'rake'
-require 'rake/testtask'
-require 'rake/packagetask'
-require 'rake/gempackagetask'
-
-gemfile = File.expand_path('../spec/test_app/Gemfile', __FILE__)
-if File.exists?(gemfile) && (%w(spec cucumber).include?(ARGV.first.to_s) || ARGV.size == 0)
- require 'bundler'
- ENV['BUNDLE_GEMFILE'] = gemfile
- Bundler.setup
-
- require 'rspec'
- require 'rspec/core/rake_task'
- RSpec::Core::RakeTask.new
-
- require 'cucumber/rake/task'
- Cucumber::Rake::Task.new do |t|
- t.cucumber_opts = %w{--format progress}
- end
-end
-
-desc "Default Task"
-task :default => [:spec, :cucumber ]
-
-spec = eval(File.read('spree_sunspot_search.gemspec'))
-
-Rake::GemPackageTask.new(spec) do |p|
- p.gem_spec = spec
+#!/usr/bin/env rake
+begin
+ require 'bundler/setup'
+rescue LoadError
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
-
-desc "Release to gemcutter"
-task :release => :package do
- require 'rake/gemcutter'
- Rake::Gemcutter::Tasks.new(spec).define
- Rake::Task['gem:push'].invoke
+begin
+ require 'rdoc/task'
+rescue LoadError
+ require 'rdoc/rdoc'
+ require 'rake/rdoctask'
+ RDoc::Task = Rake::RDocTask
end
-desc "Default Task"
-task :default => [ :spec ]
-
-desc "Regenerates a rails 3 app for testing"
-task :test_app do
- require '../spree/lib/generators/spree/test_app_generator'
- class SpreeSunspotSearchTestAppGenerator < Spree::Generators::TestAppGenerator
-
- def install_gems
- inside "test_app" do
- run 'bundle exec rake spree_core:install'
- run 'bundle exec rake spree_sunspot_search:install'
- end
- end
+Bundler::GemHelper.install_tasks
- def migrate_db
- run_migrations
- end
+require 'rspec/core/rake_task'
+require 'spree/core/testing_support/common_rake'
- protected
- def full_path_for_local_gems
- <<-gems
-gem 'spree_core', :path => \'#{File.join(File.dirname(__FILE__), "../spree/", "core")}\'
-gem 'spree_sunspot_search', :path => \'#{File.dirname(__FILE__)}\'
- gems
- end
+RSpec::Core::RakeTask.new
- end
- SpreeSunspotSearchTestAppGenerator.start
-end
+task :default => [:spec]
-namespace :test_app do
- desc 'Rebuild test and cucumber databases'
- task :rebuild_dbs do
- system("cd spec/test_app && bundle exec rake db:drop db:migrate RAILS_ENV=test && rake db:drop db:migrate RAILS_ENV=cucumber")
+task :test_app do
+ %w( spree_sunspot ).each do |engine|
+ ENV['LIB_NAME'] = File.join(engine)
+ ENV['DUMMY_PATH'] = File.expand_path("../../#{engine}/spec/dummy", __FILE__)
+ Rake::Task['common:test_app'].execute
end
-end
+end
@@ -1,3 +0,0 @@
-$ ->
- $('#product_sort_by').change ->
- window.location.href = @value
@@ -1,12 +0,0 @@
-Spree::BaseHelper.module_eval do
- def link_to_facet(facet_name, facet_row)
- # if we are just linking to taxon, link to the permalink instead of query string
-
- if facet_name == :taxon_id
- # use seo_url when linking to a taxon
- link_to(facet_row.instance.name, nested_taxons_path(facet_row.instance.permalink, params.merge("page" => nil))) + " (#{facet_row.count})"
- else
- link_to(facet_row.value, params.merge("#{facet_name}_facet" => facet_row.value, "page" => nil)) + " (#{facet_row.count})"
- end
- end
-end
@@ -1,85 +0,0 @@
-Spree::Product.class_eval do
- searchable do
- boolean :is_active, :using => :is_active?
-
- conf = Spree::Search::Sunspot.configuration
-
- conf.fields.each do |field|
- if field.class == Hash
- field = { :opts => {} }.merge(field)
-
- if field[:opts][:block]
- block = field[:opts][:block]
- field[:opts].delete(:block)
- send field[:type], field[:name], field[:opts], &block
- else
- send field[:type], field[:name], field[:opts]
- end
- else
- text(field)
- end
- end
-
- # pull the product's taxon, and all its ancestors: this allows us to intersect the display with the current taxon's
- # children and allow the user to intuitively 'dig down' into the product heirarchy
- # root taxon is excluded: doesn't really allow for intuitive navigation
- integer :taxon_ids, :multiple => true, :references => Spree::Taxon do
- taxons.map { |t| t.self_and_ancestors.select { |tx| !tx.root? }.map(&:id) }.flatten(1).uniq
- end
-
- conf.option_facets.each do |option|
- string "#{option}_facet", :multiple => true do
- get_option_values(option.to_s).map(&:presentation)
- end
- end
-
- conf.property_facets.each do |prop|
- string "#{prop}_facet", :multiple => true do
- property(prop.to_s)
- end
- end
-
- conf.other_facets.each do |method|
- string "#{method}_facet", :multiple => true do
- send(method)
- end
- end
-
- if respond_to?(:stores)
- integer :store_ids, :multiple => true, :references => Store
- end
-
- end
-
- def is_active?
- !deleted_at && available_on &&
- (available_on <= Time.zone.now) &&
- (Spree::Config[:allow_backorders] || count_on_hand > 0)
- end
-
- private
-
- def price_range
- max = 0
- Spree::Search::Sunspot.configuration.price_ranges.each do |range, name|
- return name if range.include?(price)
- max = range.max if range.max > max
- end
- I18n.t(:price_and_above, :price => max)
- end
-
- def get_option_values(option_name)
- # in the next 1.1.x release this should be replaced with the option value accessors
-
- sql = <<-eos
- SELECT DISTINCT ov.id, ov.presentation
- FROM spree_option_values AS ov
- LEFT JOIN spree_option_types AS ot ON (ov.option_type_id = ot.id)
- LEFT JOIN spree_option_values_variants AS ovv ON (ovv.option_value_id = ov.id)
- LEFT JOIN spree_variants AS v ON (ovv.variant_id = v.id)
- LEFT JOIN spree_products AS p ON (v.product_id = p.id)
- WHERE (ot.name = '#{option_name}' AND p.id = #{self.id});
- eos
- Spree::OptionValue.find_by_sql(sql)
- end
-end
@@ -0,0 +1,5 @@
+module Spree
+ AppConfiguration.class_eval do
+ preference :total_similar_products, :integer, :default => 10
+ end
+end
@@ -1,5 +0,0 @@
-module Spree
- class SunspotConfiguration < Preferences::Configuration
- preference :facet_display_limit, :integer, :default => -1
- end
-end
@@ -0,0 +1,20 @@
+Spree::Product.class_eval do
+ def get_option_values(option_name)
+ sql = <<-eos
+ SELECT DISTINCT ov.id, ov.presentation
+ FROM spree_option_values AS ov
+ LEFT JOIN spree_option_types AS ot ON (ov.option_type_id = ot.id)
+ LEFT JOIN spree_option_values_variants AS ovv ON (ovv.option_value_id = ov.id)
+ LEFT JOIN spree_variants AS v ON (ovv.variant_id = v.id)
+ LEFT JOIN spree_products AS p ON (v.product_id = p.id)
+ WHERE ((ot.name = '#{option_name}' OR ot.presentation = '#{option_name}')
+ AND p.id = #{self.id});
+ eos
+ Spree::OptionValue.find_by_sql(sql).map(&:presentation)
+ end
+end
+
+unless Spree::Sunspot::Setup.configuration.nil?
+ Spree::Product.class_eval &Spree::Sunspot::Setup.configuration
+end
+
@@ -1,5 +0,0 @@
-Deface::Override.new(:virtual_path => "spree/shared/_taxonomies",
- :name => "show_search_partials_facets",
- :insert_top => "nav#taxonomies",
- :partial => "spree/products/facets",
- :disabled => false)
@@ -1,5 +0,0 @@
-Deface::Override.new(:virtual_path => "spree/shared/_products",
- :name => "add_sunspot_search_pagination",
- :replace => "code[erb-silent]:contains('if paginated_products.respond_to')",
- :closing_selector => "code[erb-silent]:contains('end')",
- :text => "<%= paginate @searcher.sunspot.hits %>")
@@ -1,4 +0,0 @@
-Deface::Override.new(:virtual_path => "spree/shared/_products",
- :name => "add_sort_bar",
- :insert_before => "#products",
- :partial => 'spree/products/sort_bar')
@@ -1,8 +0,0 @@
-# unfortunately it doesn't look like sunspot has spell check support yet
-# https://github.com/sunspot/sunspot/pull/43
-
-# Deface::Override.new(:virtual_path => "spree/products/index",
-# :name => "show_search_partials_suggestion",
-# :insert_top => "[data-hook='search_results']",
-# :partial => "spree/products/suggestion",
-# :disabled => false)
Oops, something went wrong.

0 comments on commit d83d81f

Please sign in to comment.