Created
January 21, 2014 19:29
-
-
Save jsqu99/8546606 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Spree::Core::Search | |
Base.class_eval do | |
def method_missing(name,*args,&block) | |
@properties[name] | |
end | |
end | |
class SpreeSunspot < defined?(Spree::Search::MultiDomain) ? Spree::Search::MultiDomain : Spree::Core::Search::Base | |
def retrieve_products | |
products = Sunspot.search(Spree::Product) do | |
# This is a little tricky to understand | |
# - we are sending the block value as a method | |
# - Spree::Search::Base is using method_missing() to return the param values | |
PRODUCT_OPTION_FACETS.each do |option| | |
with("#{option}_facet", send(option)) if send(option) | |
facet("#{option}_facet") | |
end | |
PRODUCT_PROPERTY_FACETS.each do |prop| | |
with("#{prop}_facet", send(prop)) if send(prop) | |
facet("#{prop}_facet") | |
end | |
with(:price, Range.new(price.split('-').first, price.split('-').last)) if price | |
facet(:price) do | |
PRODUCT_PRICE_RANGES.each do |range| | |
row(range) do | |
Rails.logger.debug("adding price facet w/ range: #{range.split('-').first}, #{range.split('-').last}") | |
with(:price, Range.new(range.split('-').first, range.split('-').last)) | |
end | |
end | |
end | |
with(:cost_per_ui_value, Range.new(cost_per_ui_value.split('-').first, cost_per_ui_value.split('-').last)) if cost_per_ui_value | |
facet(:cost_per_ui) do | |
PRODUCT_COST_PER_UI_RANGES.each do |range| | |
row(range) do | |
with(:cost_per_ui_value, Range.new(range.split('-').first, range.split('-').last)) | |
end | |
end | |
end | |
# Taxons by name | |
with(:taxon_name, taxon_name) if taxon_name | |
# Taxon via categories and the such | |
with(:taxon, taxon) if taxon | |
keywords(query) | |
paginate(:page => page, :per_page => per_page) | |
end | |
# get rid of products whose brands don't have an entry in dbzs | |
@properties[:products] = products # .except {|product| !(dbzs.map(&:brand).include? product.brand) } | |
end | |
protected | |
def prepare(params) | |
super | |
@properties[:taxon] = params[:taxon] unless params[:taxon].blank? | |
#@properties[:taxon_name] = params[:taxon] | |
@properties[:query] = params[:keywords] | |
@properties[:price] = params[:price] | |
PRODUCT_OPTION_FACETS.each do |option| | |
@properties[option] = params["#{option}_facet"] | |
end | |
PRODUCT_PROPERTY_FACETS.each do |prop| | |
@properties[prop] = params["#{prop}_facet"] | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment