I have just run into further difficulty with this.
To clarify by way of example, what I would like to achieve is the
equivalent to the following by using scopes:
> @facets = Items.facets
> @items = @facets.for(:size => 'Medium', :colour => ['Red', 'Green', 'Blue'])
This is what I have so far:
sphinx_scope(:by_size) do |size|
{:with => {:size_facet => size.to_crc32}}
end
sphinx_scope(:by_colour) do |colour|
{:with => {:colour_facet => colour.to_crc32}}
end
The above works fine when called with a single value, e.g.
> Items.by_size('Medium').by_colour('Red')
However, passing an array of values causes a problem:
> Items.by_size('Medium').by_colour( ['Red', 'Green', 'Blue'] )
> NoMethodError: undefined method `to_crc32' for ["Red", "Green", "Blue"]:Array
I guess I need to use the 'collect' method on the array and 'to_crc32'
each string individually. This is all starting to get very messy and
unDRY.
Getting back to my original question: The 'for' method provided by TS
handles CRC32ing (including array handling) and the appending of
'_facet' to the attribute name automatically. Is it possible to
utilise this logic within a sphinx_scope rather than re-writing the
functionality from scratch?
Many thanks
Greg
--
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/thinking-sphinx?hl=en.