spree_sunspot_search icon indicating copy to clipboard operation
spree_sunspot_search copied to clipboard

order_by bugs

Open joshuakfarrar opened this issue 10 years ago • 0 comments

Hey folks,

I'm not sure what is going on here, but I followed the documentation to order my store's products by price and received the following error:

[21] pry(main)> @searcher = Spree::Config.searcher_class.new({:order_by => 'price, asc'})
  Spree::Preference Load (0.3ms)  SELECT `spree_preferences`.* FROM `spree_preferences` WHERE `spree_preferences`.`key` = 'spree/app_configuration/currency' LIMIT 1
  Spree::Preference Load (0.2ms)  SELECT `spree_preferences`.* FROM `spree_preferences` WHERE `spree_preferences`.`key` = 'spree/app_configuration/products_per_page' LIMIT 1
  Spree::Preference Load (0.2ms)  SELECT `spree_preferences`.* FROM `spree_preferences` WHERE `spree_preferences`.`key` = 'spree/app_configuration/total_similar_products' LIMIT 1
=> #<Spree::Sunspot::Search:0x007fd9a1af4100
 @current_currency="USD",
 @properties=
  {:taxon=>nil,
   :keywords=>nil,
   :search=>nil,
   :per_page=>39,
   :page=>1,
   :filters=>[],
   :order_by=>"price, asc",
   :location_coords=>nil,
   :total_similar_products=>10}>
[22] pry(main)> @searcher.retrieve_products                           (0.6ms)  SELECT COUNT(*) FROM `spree_products` WHERE (`spree_products`.deleted_at IS NULL)
ArgumentError: Unknown sort direction  asc. Acceptable input is: :asc, :ascending, :desc, :descending
from /Users/sent1nel/Apps/store/vendor/bundle/ruby/2.0.0/gems/sunspot-2.0.0/lib/sunspot/query/sort.rb:50:in `direction_for_solr'

I also tried playing around with "price, :asc", "price,:asc" (which obviously doesn't work because of the .split happening somewhere), and "price, desc" / its alternatives to no avail.

Thinking it might just be an issue with the field, I tried sorting my products by name...

[23] pry(main)> @searcher = Spree::Config.searcher_class.new({:order_by => 'name, desc'})
  Spree::Preference Load (0.3ms)  SELECT `spree_preferences`.* FROM `spree_preferences` WHERE `spree_preferences`.`key` = 'spree/app_configuration/currency' LIMIT 1
  Spree::Preference Load (0.2ms)  SELECT `spree_preferences`.* FROM `spree_preferences` WHERE `spree_preferences`.`key` = 'spree/app_configuration/products_per_page' LIMIT 1
  Spree::Preference Load (0.2ms)  SELECT `spree_preferences`.* FROM `spree_preferences` WHERE `spree_preferences`.`key` = 'spree/app_configuration/total_similar_products' LIMIT 1
=> #<Spree::Sunspot::Search:0x007fd99bbdd950
 @current_currency="USD",
 @properties=
  {:taxon=>nil,
   :keywords=>nil,
   :search=>nil,
   :per_page=>39,
   :page=>1,
   :filters=>[],
   :order_by=>"name, desc",
   :location_coords=>nil,
   :total_similar_products=>10}>
[24] pry(main)> @searcher.retrieve_products                        Sunspot::UnrecognizedFieldError: No field configured for Spree::Product with name 'name'
from /Users/sent1nel/Apps/store/vendor/bundle/ruby/2.0.0/gems/sunspot-2.0.0/lib/sunspot/setup.rb:113:in `field'

Am I doing it wrong?

joshuakfarrar avatar Dec 01 '14 16:12 joshuakfarrar