Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added default sort field configuration. Moved all configuration over …

…to the configuration model.
  • Loading branch information...
commit d118a44a4a3ec0dfa8e7bf2f26d17728ac6e6e6c 1 parent 42de821
@iloveitaly authored
View
10 app/models/spree/search/spree_sunspot/search.rb
@@ -47,6 +47,8 @@ def prepare(params)
# as well as handles pagination
super
+ conf = Spree::Search::SpreeSunspot.configuration
+
# TODO should do some parameter cleaning here: only allow valid search params to be passed through
# the faceting partial is kind of 'dumb' about the params object: doesn't clean it out and just
# dumps all the params into the query string
@@ -54,14 +56,14 @@ def prepare(params)
@properties[:query] = params[:keywords]
@properties[:price] = params[:price]
- @properties[:sort] = params[:sort].try(:to_sym) || :score
- @properties[:order] = params[:order].try(:to_sym) || :desc
+ @properties[:sort] = params[:sort] || conf.default_sort_key
+ @properties[:order] = params[:order] || conf.default_sort_order
# ensure that :sort and :order are legit
- @properties[:sort] = :score unless Spree::Search::SpreeSunspot.configuration.sort_fields.keys.include? @properties[:sort]
+ @properties[:sort] = :score unless conf.sort_fields.keys.include? @properties[:sort]
@properties[:order] = :desc unless [:desc, :asc].include? @properties[:sort]
- Spree::Search::SpreeSunspot.configuration.display_facets.each do |name|
+ conf.display_facets.each do |name|
@properties[name] ||= params["#{name}_facet"]
end
end
View
5 app/models/spree/sunspot_search_configuration.rb
@@ -1,5 +0,0 @@
-module Spree
- class SunspotSearchConfiguration < Preferences::Configuration
- preference :facet_display_limit, :integer, :default => -1
- end
-end
View
5 app/views/spree/products/_facets.html.erb
@@ -1,6 +1,7 @@
<%
-facets_arr = Spree::Search::SpreeSunspot.configuration.display_facets
-limit = Spree::SunspotSearch::Config[:facet_display_limit]
+conf = Spree::Search::SpreeSunspot.configuration
+facets_arr = conf.display_facets
+limit = conf.facet_display_limit
if @taxon
display_list = @taxon.leaf? ? [@taxon.id] : @taxon.children.map(&:id)
View
10 lib/spree/search/spree_sunspot/configuration.rb
@@ -8,7 +8,10 @@ class Configuration
:other_facets,
:show_facets,
:fields,
- :sort_fields
+ :sort_fields,
+ :default_sort_key,
+ :default_sort_order,
+ :facet_display_limit
def initialize
# Price ranges to be used for faceting
@@ -37,10 +40,15 @@ def initialize
# facets that have already been created and should be displayed in the suggestions partial
self.show_facets = []
+ self.facet_display_limit = 1
+
self.sort_fields = {
:score => :desc,
:price => [:asc, :desc],
}
+
+ self.default_sort_key = :score
+ self.default_sort_order = :desc
end
def display_facets
View
3  lib/spree_sunspot_search.rb
@@ -2,8 +2,6 @@
require 'sunspot_rails'
require 'spree/search/spree_sunspot/configuration'
-module Spree::SunspotSearch; end
-
module SpreeSunspotSearch
class Engine < Rails::Engine
engine_name 'spree_sunspot_search'
@@ -12,7 +10,6 @@ class Engine < Rails::Engine
initializer "spree.sunspot_search.preferences", :after => "spree.environment" do |app|
Spree::Config.searcher_class = Spree::Search::SpreeSunspot::Search
- Spree::SunspotSearch::Config = Spree::SunspotSearchConfiguration.new
end
def self.activate
Please sign in to comment.
Something went wrong with that request. Please try again.