Jeff,
Not sure I am understanding what you are suggesting.
I can confirm that, if I check the second row of options for the search,
which is "$10.00-$50.00", the search returns items that are exactly $10.00.
If I also check the third row, which reads "$50.00-$100.00", the search
returns items that are exactly $10.00 and exactly $50.00.
Since I have not items that are $0.00 or $2500.00, choosing those search
options return nothing.
Another display of this behavior. I changed the filter to read as follows.
The searches now return nothing since I have nothing in the catalog that is
exactly $10.01 or $50.01 or $500.01.
# Ranges can be Dates, Ints, or Floats
filters.add do |f|
f.search_param = 'price'
# Can be :any (||) or :all (&&)
f.search_condition = :all
f.display_name = 'Price'
f.values { [
0..10,
10.01..50,
50.01..100,
100.01..500,
500.01..2499.99,
2500..0
] }
end
Is the issue that the Spree::Sunspot::Setup is not correct? Should this
take the price range in the filter and search something like
Spree::Variant.find(:price)?
Any examples of what this should be? Here is what I have in
initializers/spree_sunspot.rb
Spree::Sunspot::Setup.configure do
searchable :auto_index => true, :auto_remove => true do
text :name, :boost => 2.0
text :description, :boost => 1.2
time :available_on
integer :taxon_names, :references => Spree::Taxon, :multiple => true do
taxons.collect{|t| t.self_and_ancestors.map(&:id) }.flatten
end
string :taxon_names, :multiple => true do
taxons.collect{|t| t.self_and_ancestors.map(&:name) }.flatten
end
float :price
# Additional Examples
#
string :category_names, :multiple => true do
category = Spree::Taxon.find_by_permalink('categories')
taxons.select{|t| t.ancestors.include?(category)}.collect{|t| t.
self_and_ancestors.map(&:name)}.flatten - [category.name]
end
string :brand_name do
brand = Spree::Taxon.find_by_permalink('brand')
t = taxons.select{|t| t.ancestors.include?(brand)}.first
t.name unless t.nil?
end
end
end
On Thursday, March 21, 2013 10:18:52 AM UTC-6, jdutil wrote:The last ranges value should be something higher than 2500 also I believe.
I think doing 2500..00 would match everything from 2500 down to 0 so maybe
your always matching the last value not the first.
On Wednesday, March 20, 2013 4:56:55 PM UTC-4, Randy Terbush wrote:That is what I have been doing all along and getting results for exact
match of first value in range. The Range.new was just an attempt to figure
this out...
This is what I have currently for price filter:
filters.add do |f|
f.search_param = 'price'
# Can be :any (||) or :all (&&)
f.search_condition = :all
f.display_name = 'Price'
f.values { [
0..10,
10..50,
50..100,
100..500,
500..2500,
2500..0
] }
end
On Wednesday, March 20, 2013 2:54:21 PM UTC-6, jdutil wrote:Randy,
Don't define Range.new within f.values. That is causing your values
array to only have a single value which is the range object. What you want
is for values to be an array of the the various price ranges.
So change it to:
f.values {[
0..10,
10..50,
50..100,
100..500,
500..2500,
2500..0
]}
JDutil
On Wednesday, March 20, 2013 1:55:22 PM UTC-4, Randy Terbush wrote:I am guessing that this range issue may have something to do with the
filter setup.
This code from lib/spree/sunspot/filter/filter.rb
def html_values
case param_type.to_s
when "Proc"
values.first.call.collect do |value|
{ :display => value[0], :value => value[1] }
end
when "Range"
values.collect do |range|
if range.first == 0
{ :display => "Under #{number_to_currency(range.last,
:precision => 0)}", :value => "#{range.first},
#{range.last}" }
elsif range.last == 0
{ :display => "#{number_to_currency(range.first,
:precision => 0)}+", :value => "#{range.first},*" }
else
{ :display => "#{number_to_currency(range.first,
:precision => 0)} - #{number_to_currency(range.last
, :precision => 0)}",
:value => "#{range.first},#{range.last}" }
end
end
else
values.collect do |value|
{ :display => value, :value => value }
end
end
end
And this example:
# Using a Proc to evaluate values at runtime rather than eager loading:
# filters.add do |f|
# f.display_name = 'Categories'
# f.search_condition = :any
# f.search_param = 'category_ids'
# f.values {[
# Proc.new {
# Spree::Taxon.select{ |t| t.root.name.eql?('Categories')
and t != t.root }.collect{ |taxon| [taxon.name, taxon.id] }
# }
# ]}
# end
Lead me to believe I need to do something like this, but have yet to
figure out the proper construct.
filters.add do |f|
f.search_param = 'price'
# Can be :any (||) or :all (&&)
f.search_condition = :any
f.display_name = 'Price'
f.values { [
Range.new {
[0..10],
[10..50],
[50..100],
[100..500],
[500..2500],
[2500..0]
}
] }
end
Help would be greatly appreciated...
On Wednesday, March 20, 2013 11:32:52 AM UTC-6, Randy Terbush wrote:And am now learning that this breaks the ability to select multiple
ranges, so I am still stuck. If preserving the two dimensional array, the
search returns only items that are exactly the same value as the first
value in the price range. ie. if selecting $10-50, the items returned are
exactly $10.
On Wednesday, March 20, 2013 10:57:37 AM UTC-6, Randy Terbush wrote:After some more fiddling here, I've figured out that I can get a
search to return results within the price range by removing the second
array dimension. I still seem to be having trouble if picking two or more
price ranges or two or more taxons.
http:
//localhost:3000/products?utf8=%E2%9C%93&s[price]=50%2C100&commit=Search
On Tuesday, March 19, 2013 6:21:38 PM UTC-6, Randy Terbush wrote:I've given this another try thanks to Jeff's efforts to get this
back to usable state. Running into some problems I hope he or someone can
help with.
Having configured a price filter like so:
filters.add do |f|
f.search_param = 'price'
# Can be :any (||) or :all (&&)
f.search_condition = :any
f.display_name = 'Price'
f.values { [
0..10,
10..50,
50..100,
100..500,
500..2500,
2500..0
] }
end
When I select a price range for example, the 50-100, the
_filter.html.erb constructs a URL that looks like:
http:
//localhost:3000/products?utf8=%E2%9C%93&s[price][]=50%2C100&commit=Search
And the only things returned are those that are exactly 50.00.
BTW, the utf8 value in the url is actually a checkmark... not sure
how to preserve that in the quote above.
On Thursday, March 7, 2013 2:37:40 PM UTC-7, Randy Terbush wrote:I would love for someone to prove me wrong, but after taking a few
minutes to give the jbrien repo a try again, I can only conclude that it is
badly broken and seems to be in the middle of a refactoring. I sent a pull
request to fix a basic problem with bundle install failing because of a
name issue, but after getting even deeper, seems that the installation
instructions do not work: "Could not find generator
spree_sunspot_search:install"
Would like to help get that back in shape but I cannot figure out
what direction it is going right now.
On Thursday, March 7, 2013 1:40:35 PM UTC-7, Randy Terbush wrote:Thanks Jeff! I'll have a look.
I had tried this repo a few weeks ago and found it fairly broken
and wasn't clear if he had a name change in process or what. I'll give it
another try. Would like to base off of that repo if possible.
FWIW, I have worked through setting up a standalone solr server,
so let me know if you hit snags there.
--
Randy
Randy I'm actually just starting to dig into spree_sunspot_search
myself so I can't really answer your questions at the moment. Would like
to point out though that the canonical repositories README has just been
updated by the author about an hour ago.
https://github.com/jbrien/spree_sunspot_searchHopefully that helps some and if not it probably wouldn't hurt to
try opening issues on the main repo.
On Thursday, March 7, 2013 12:26:02 PM UTC-5, Randy Terbush wrote:Struggling a bit to get my head around a spree_sunspot_search
setup. I would appreciate any suggestions on how to configure search and
how to replace some of the search forms on a spree site. I am currently
using Michael Bianco's fork:
https://github.com/**iloveitaly/spree_sunspot_**search<
https://github.com/iloveitaly/spree_sunspot_search>
1. I discovered that spree_sunspot_filters.rb is not getting
installed into my Spree app. Is that intended? If not, should this live in
config/initializers?
2. Depending on search paramemeters, I am still seeing some of
the original Spree search price ranges and search button in the sidebar. I
also have views/spree/shared/_filters.**html.erb and with
spree_sunspot_search I get views/spree/shared/_filter.**html.erb.
Is one of these supposed to replace the other, or do I truly have two
places to tweak this stuff?
3. If I were to create an "advanced search" page where all
parameters are available to craft searches, is there a standard route for
that, or is this something I need to setup?
4. Running into problem on a few pages like some static pages
and home page which have Search bars on them giving the following error
when you access them. I suspect I need to include the Sunspot code somehow,
but finding it difficult to solve that issue.
NoMethodError in Spree/home#index
Showing */raid/src/Website/www.fma/app/views/spree/shared/_
taxonomies.html.erb* where line *#9* raised:
undefined method `sunspot' for nil:NilClass
Extracted source (around line *#9*):
6: if @taxon
7: display_list = @taxon.leaf? ? [@taxon.id] : @taxon.children.map(&:id)
8: else
9: display_list = @searcher.sunspot.facet(:**taxon_ids).rows.slice(0..**limit).map { |r| r.instance.id }
10: end
11:
12: taxon_rows = @searcher.sunspot.facet(:**taxon_ids).rows.select { |t| display_list.include? t.instance.id }.slice(0..limit)
Trace of template inclusion: app/views/spree/home/index.**
html.erb
Rails.root: /raid/src/Website/www.fma
Application Trace <
http://localhost:3000/#> | Framework Trace<
http://localhost:3000/#>
app/views/spree/shared/_**taxonomies.html.erb:9:in `_**7a738ccc3f3dd3c5cd60532aaac8ad**9e'
app/views/spree/home/index.**html.erb:5:in `block in _**61f938529d78b5e87f71f6c3f586a5**8a'
app/views/spree/home/index.**html.erb:3:in `_**61f938529d78b5e87f71f6c3f586a5**8a'
Clearly some clueless questions there but would sincerely
appreciate someone giving me a couple of clues.
Thanks
--
You received this message because you are subscribed to a topic
in the Google Groups "Spree" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/spree-user/XFkvtyD1r20/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email
to spree-user+
unsubscribe@googlegroups.com<
https://mail.google.com/mail/u/0/?view=cm&fs=1&tf=1&to=spree-user%2Bunsubscribe@googlegroups.com>
.
For more options, visit
https://groups.google.com/groups/opt_out. --
You received this message because you are subscribed to the Google Groups "Spree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spree-user+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.