Permalink
Browse files

updated to hack in geodistance

  • Loading branch information...
1 parent e9f0eed commit 019ac63ed0514f2b7fffa461e41326fc139779ab @hybridindie committed Apr 18, 2013
Showing with 33 additions and 20 deletions.
  1. +30 −17 lib/spree/sunspot/search.rb
  2. +3 −3 spree_sunspot_search.gemspec
@@ -66,6 +66,7 @@ def get_base_scope
base_scope = add_search_scopes(base_scope)
end
+ # TODO: This method is shit; clean it up John. At least you were paid to write this =P
def get_products_conditions_for(base_scope, query)
@solr_search = ::Sunspot.new_search(Spree::Product) do |q|
q.keywords(query)
@@ -85,23 +86,7 @@ def get_products_conditions_for(base_scope, query)
end
@solr_search.build do |query|
- Setup.query_filters.filters.each do |filter|
- if filter.values.any? && filter.values.first.is_a?(Range)
- query.facet(filter.search_param) do
- filter.values.each do |value|
- row(value) do
- with(filter.search_param, value)
- end
- end
- end
- else
- query.facet(
- filter.search_param,
- exclude: property_exclusion( filter.exclusion )
- )
- end
-
- end
+ build_facet_query(query)
end
@solr_search.execute
@@ -119,11 +104,39 @@ def prepare(params)
super
@properties[:filters] = params[:s] || params['s'] || []
@properties[:order_by] = params[:order_by] || params['order_by'] || []
+ @properties[:location_coords] = params[:location_coords] || params['location_coords'] || nil
@properties[:total_similar_products] = params[:total_similar_products].to_i > 0 ?
params[:total_similar_products].to_i :
Spree::Config[:total_similar_products]
end
+ def build_facet_query(query)
+ Setup.query_filters.filters.each do |filter|
+ if filter.values.any? && filter.values.first.is_a?(Range)
+ query.facet(filter.search_param) do
+ filter.values.each do |value|
+ row(value) do
+ with(filter.search_param, value)
+ end
+ end
+ end
+ else
+ query.facet(
+ filter.search_param,
+ exclude: property_exclusion( filter.exclusion )
+ )
+ end
+ # Temporary hack to allow for geodistancing
+ unless @properties[:location_coords].nil?
+ coords = @properties[:location_coords].split(',')
+ coords.flatten
+ lat = coords[0]
+ long = coords[1]
+ query.with(:location).in_radius( lat, long, 50 )
+ end
+ end
+ end
+
def property_exclusion(filter)
return nil if filter.blank?
prop = @properties[:filters].select{ |f| f == filter.to_s }
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'spree_sunspot'
- s.version = '1.2'
+ s.version = '1.3'
s.summary = 'Add Solr search to Spree via the Sunspot gem'
s.description = 'Sunspot and Spree have a wonderful baby'
s.required_ruby_version = '>= 1.9.3'
@@ -16,12 +16,12 @@ Gem::Specification.new do |s|
s.requirements << 'none'
s.add_dependency 'spree_core', '>= 1.1.0'
- s.add_dependency 'sunspot_rails', '>= 1.3.0'
+ s.add_dependency 'sunspot_rails', '>= 2.0.0'
s.add_development_dependency 'capybara', '1.0.1'
s.add_development_dependency 'factory_girl'
s.add_development_dependency 'ffaker'
s.add_development_dependency 'rspec-rails', '~> 2.8'
s.add_development_dependency 'sqlite3'
- s.add_development_dependency 'sunspot_solr', '>= 1.3.0'
+ s.add_development_dependency 'sunspot_solr', '>= 2.0.0'
end

0 comments on commit 019ac63

Please sign in to comment.