Skip to content

Commit

Permalink
updated to hack in geodistance
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridindie committed Apr 18, 2013
1 parent e9f0eed commit 019ac63
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
47 changes: 30 additions & 17 deletions lib/spree/sunspot/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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 }
Expand Down
6 changes: 3 additions & 3 deletions spree_sunspot_search.gemspec
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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.