Hi Pat

Thanks, this is a much cleaner solution.

Greg


On Feb 4, 3:00 am, Pat Allan <[email protected]> wrote:
> Hi Greg
>
> Here's the method in Thinking Sphinx that does the translation of values:
>
>   def underlying_value(key, value)
>     case value
>     when Array
>       value.collect { |item| underlying_value(key, item) }
>     when String
>       value.to_crc32
>     else
>       value
>     end
>   end
>
> I reckon the easiest solution is just to re-create it as a class method and 
> use that.
>
> As for auto-appending _facet, that *is* provided by TS in a reasonably open 
> way:
>   ThinkingSphinx::Facet.name_for(:size)
>
> Hope this helps dry things up a bit.
>
> --
> Pat
>
> On 02/02/2011, at 11:03 PM, Greg wrote:
>
>
>
>
>
>
>
> > 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 
> > athttp://groups.google.com/group/thinking-sphinx?hl=en.

-- 
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.

Reply via email to