spree_solr_search 0.40.0 → 0.40.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ Jeweler::Tasks.new do |s|
22
22
  s.homepage = "http://github.com/romul/spree-solr-search"
23
23
  s.authors = ["Roman Smirnov"]
24
24
  s.add_dependency 'spree_core', ['>= 0.30.1']
25
- s.add_dependency 'acts_as_solr_reloaded', ['>= 1.5.0']
25
+ s.add_dependency 'acts_as_solr_reloaded', ['>= 1.6.0']
26
26
  s.has_rdoc = false
27
27
  #s.extra_rdoc_files = [ "README.rdoc"]
28
28
  #s.rdoc_options = ["--main", "README.rdoc", "--inline-source", "--line-numbers"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.40.0
1
+ 0.40.3
@@ -1,4 +1,4 @@
1
- module SolrHelper
1
+ Spree::BaseHelper.module_eval do
2
2
  def link_to_facet(name, value, count)
3
3
  facets_hash = params[:facets]
4
4
  facets_hash = {} unless facets_hash.is_a?(Hash)
@@ -1,9 +1,5 @@
1
1
  Product.class_eval do
2
- acts_as_solr :fields => [:name, :description, :is_active, {:price => :float},
3
- :taxon_ids, :price_range, :taxon_names,
4
- :brand_property, :color_option, :size_option],
5
- :facets=>[:price_range, :taxon_names,
6
- :brand_property, :color_option, :size_option]
2
+ acts_as_solr :fields => PRODUCT_SOLR_FIELDS, :facets => PRODUCT_SOLR_FACETS
7
3
 
8
4
  def taxon_ids
9
5
  taxons.map(&:id)
@@ -17,24 +13,25 @@ Product.class_eval do
17
13
 
18
14
  private
19
15
 
16
+ def store_ids
17
+ if self.respond_to? :stores
18
+ stores.map(&:id)
19
+ else
20
+ []
21
+ end
22
+ end
23
+
20
24
  def taxon_names
21
25
  taxons.map(&:name)
22
26
  end
23
27
 
24
28
  def price_range
25
- price_ranges = YAML.load(Spree::Config[:product_price_ranges])
26
- case price
27
- when 0..25
28
- price_ranges[0]
29
- when 25..50
30
- price_ranges[1]
31
- when 50..100
32
- price_ranges[2]
33
- when 100..200
34
- price_ranges[3]
35
- else
36
- price_ranges[4]
29
+ max = 0
30
+ PRODUCT_PRICE_RANGES.each do |range, name|
31
+ return name if range.include?(price)
32
+ max = range.max if range.max > max
37
33
  end
34
+ I18n.t(:price_and_above, :price => max)
38
35
  end
39
36
 
40
37
  def brand_property
@@ -1,9 +1,13 @@
1
- <%
1
+ <%
2
2
  facets = @searcher.facets || []
3
3
  taxon_names = @taxon ? @taxon.self_and_descendants.map(&:name) : []
4
4
  for facet in facets
5
5
  options = facet.options
6
- options = options.sort{|x,y| y.count <=> x.count} unless facet.name == "price_range"
6
+ if facet.name == "price_range"
7
+ options = options.sort{|x, y| x.name <=> y.name}
8
+ else
9
+ options = options.sort{|x, y| y.count <=> x.count}
10
+ end
7
11
  unless options.empty? %>
8
12
  <h4><%= t "#{facet.name}_facet" %></h4>
9
13
  <ul><%
@@ -0,0 +1,13 @@
1
+ unless defined?(PRODUCT_PRICE_RANGES)
2
+ PRODUCT_PRICE_RANGES = {0..25 => " Under $25", 25..50 => " $25 to $50",
3
+ 50..100 => " $50 to $100", 100..200 => "$100 to $200"}
4
+ end
5
+ unless defined?(PRODUCT_SOLR_FIELDS)
6
+ PRODUCT_SOLR_FIELDS = [:name, :description, :is_active, {:price => :float},
7
+ :taxon_ids, :price_range, :taxon_names, :store_ids,
8
+ :brand_property, :color_option, :size_option]
9
+ end
10
+ unless defined?(PRODUCT_SOLR_FACETS)
11
+ PRODUCT_SOLR_FACETS = [:price_range, :taxon_names,
12
+ :brand_property, :color_option, :size_option]
13
+ end
@@ -4,3 +4,4 @@ en:
4
4
  brand_property_facet: "Brand"
5
5
  color_option_facet: "Color"
6
6
  size_option_facet: "Size"
7
+ price_and_above: "$%{price} and above"
@@ -4,3 +4,4 @@ ru:
4
4
  brand_property_facet: "Бренд"
5
5
  color_option_facet: "Цвет"
6
6
  size_option_facet: "Размер"
7
+ price_and_above: "%{price} руб. и выше"
@@ -1,10 +1,10 @@
1
1
  module Spree::Search
2
- class Solr < Spree::Search::Base
2
+ class Solr < defined?(Spree::Search::MultiDomain) ? Spree::Search::MultiDomain : Spree::Search::Base
3
3
  protected
4
4
 
5
5
  def get_products_conditions_for(base_scope, query)
6
6
  facets = {
7
- :fields => [:price_range, :taxon_names, :brand_property, :color_option, :size_option],
7
+ :fields => PRODUCT_SOLR_FACETS,
8
8
  :browse => @properties[:facets_hash].map{|k,v| "#{k}:#{v}"},
9
9
  :zeros => false
10
10
  }
@@ -17,6 +17,8 @@ module Spree::Search
17
17
  taxons_query = taxon.self_and_descendants.map{|t| "taxon_ids:(#{t.id})"}.join(" OR ")
18
18
  full_query += " AND (#{taxons_query})"
19
19
  end
20
+
21
+ full_query += " AND store_ids:(#{current_store_id})" if current_store_id
20
22
 
21
23
  result = Product.find_by_solr(full_query, search_options)
22
24
 
@@ -48,20 +50,12 @@ module Spree::Search
48
50
 
49
51
  def parse_facets_hash(facets_hash = {"facet_fields" => {}})
50
52
  facets = []
51
- price_ranges = YAML::load(Spree::Config[:product_price_ranges])
52
53
  facets_hash["facet_fields"].each do |name, options|
53
54
  options = Hash[*options.flatten] if options.is_a?(Array)
54
55
  next if options.size <= 1
55
56
  facet = Facet.new(name.sub('_facet', ''))
56
- if name == 'price_range_facet'
57
- price_ranges.each do |price_range|
58
- count = options[price_range]
59
- facet.options << FacetOption.new(price_range, count) if count
60
- end
61
- else
62
- options.each do |value, count|
63
- facet.options << FacetOption.new(value, count)
64
- end
57
+ options.each do |value, count|
58
+ facet.options << FacetOption.new(value, count)
65
59
  end
66
60
  facets << facet
67
61
  end
@@ -9,13 +9,12 @@ module SpreeSolrSearch
9
9
 
10
10
  if Spree::Config.instance
11
11
  Spree::Config.searcher_class = Spree::Search::Solr
12
- Spree::Config.set(:product_price_ranges =>
13
- ["Under $25", "$25 to $50", "$50 to $100", "$100 to $200", "$200 and above"])
14
12
  end
15
13
 
16
14
  Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
17
15
  Rails.env == "production" ? require(c) : load(c)
18
16
  end
17
+
19
18
  end
20
19
  config.to_prepare &method(:activate).to_proc
21
20
  config.autoload_paths += %W(#{config.root}/lib)
@@ -2,7 +2,7 @@ begin
2
2
  ENV['ONLY'] = "Product"
3
3
  SOLR_PATH = ENV['SOLR_PATH']
4
4
  RAILS_DEFAULT_LOGGER = Logger.new(Rails.root.join("log", Rails.env + ".log"))
5
- RAILS_ROOT = Rails.root.to_s
5
+ RAILS_ROOT = Rails.root.to_s unless defined?(RAILS_ROOT)
6
6
  require 'acts_as_solr_reloaded'
7
7
  load 'tasks/solr.rake'
8
8
  rescue LoadError
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{spree_solr_search}
8
- s.version = "0.40.0"
8
+ s.version = "0.40.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Roman Smirnov"]
12
- s.date = %q{2011-02-22}
12
+ s.date = %q{2011-03-21}
13
13
  s.description = %q{Provides search via Apache Solr for a Spree store.}
14
14
  s.email = %q{roman@railsdog.com}
15
15
  s.extra_rdoc_files = [
@@ -20,11 +20,11 @@ Gem::Specification.new do |s|
20
20
  "README.md",
21
21
  "Rakefile",
22
22
  "VERSION",
23
- "app/controllers/spree/base_controller_decorator.rb",
24
- "app/helpers/solr_helper.rb",
23
+ "app/helpers/spree/base_helper_decorator.rb",
25
24
  "app/models/product_decorator.rb",
26
25
  "app/views/products/_facets.html.erb",
27
26
  "app/views/products/_suggestion.html.erb",
27
+ "config/initializers/solr_config.rb",
28
28
  "config/locales/en.yml",
29
29
  "config/locales/ru-RU.yml",
30
30
  "config/locales/ru.yml",
@@ -49,14 +49,14 @@ Gem::Specification.new do |s|
49
49
 
50
50
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
51
  s.add_runtime_dependency(%q<spree_core>, [">= 0.30.1"])
52
- s.add_runtime_dependency(%q<acts_as_solr_reloaded>, [">= 1.5.0"])
52
+ s.add_runtime_dependency(%q<acts_as_solr_reloaded>, [">= 1.6.0"])
53
53
  else
54
54
  s.add_dependency(%q<spree_core>, [">= 0.30.1"])
55
- s.add_dependency(%q<acts_as_solr_reloaded>, [">= 1.5.0"])
55
+ s.add_dependency(%q<acts_as_solr_reloaded>, [">= 1.6.0"])
56
56
  end
57
57
  else
58
58
  s.add_dependency(%q<spree_core>, [">= 0.30.1"])
59
- s.add_dependency(%q<acts_as_solr_reloaded>, [">= 1.5.0"])
59
+ s.add_dependency(%q<acts_as_solr_reloaded>, [">= 1.6.0"])
60
60
  end
61
61
  end
62
62
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 40
8
- - 0
9
- version: 0.40.0
8
+ - 3
9
+ version: 0.40.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Roman Smirnov
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-22 00:00:00 +03:00
17
+ date: 2011-03-21 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -40,9 +40,9 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  segments:
42
42
  - 1
43
- - 5
43
+ - 6
44
44
  - 0
45
- version: 1.5.0
45
+ version: 1.6.0
46
46
  type: :runtime
47
47
  version_requirements: *id002
48
48
  description: Provides search via Apache Solr for a Spree store.
@@ -58,11 +58,11 @@ files:
58
58
  - README.md
59
59
  - Rakefile
60
60
  - VERSION
61
- - app/controllers/spree/base_controller_decorator.rb
62
- - app/helpers/solr_helper.rb
61
+ - app/helpers/spree/base_helper_decorator.rb
63
62
  - app/models/product_decorator.rb
64
63
  - app/views/products/_facets.html.erb
65
64
  - app/views/products/_suggestion.html.erb
65
+ - config/initializers/solr_config.rb
66
66
  - config/locales/en.yml
67
67
  - config/locales/ru-RU.yml
68
68
  - config/locales/ru.yml
@@ -1,4 +0,0 @@
1
- Spree::BaseController.class_eval do
2
- helper :solr
3
- RAILS_ROOT = Rails.root.to_s
4
- end