I forgot to mention that this works fine with :order, solving your problem.

On Sun, Jan 4, 2009 at 9:57 PM, Alex Caudill <[email protected]> wrote:
> Currently I'm using a named_scope with this as the conditions:
>
> class Array
> def to_date_range(colname = "users.dob")
>    return map{ |x|
>      t = x.split("-")
>      a = Date.new(t.last.to_i.years.ago.year).to_s(:db)
>      b = t.first.to_i.years.ago.to_s(:db)
>      "#{colname} BETWEEN '#{a}' AND '#{b}'"
>    }.join(" OR ")
>  end
> end
>
> It takes an array like: ["18-22", "23-27", "30-40"] and it respects holes
> in the age range. Yeah, it's hideous, and no error checking. It works.
>
> Then you can do:
>
> res = User.date_range(my_array.to_date_range).search conditions_hash
>
> This returns an array of Users which is then #search'd, but if an item in the
> date_range named scope doesn't match the search results, it becomes nil
> in the results. So if that date_range scope returned [1,2,3] and only 1 was
> a match for conditions_hash, the results would be [1,nil,nil]. I use a simple
> Array#delete_if block to get rid of the nils.
>
>
> On Sun, Jan 4, 2009 at 9:20 PM, Pat Allan <[email protected]> wrote:
>>
>> Hi Oli
>>
>> The last pastie's syntax isn't going to work, as Thinking Sphinx
>> doesn't build a big string, but has to send the attribute name and
>> range values through to Sphinx as a string and integers, respectively.
>>
>> The middle one, as we've discussed on Twitter, the range elements need
>> to be reversed - but it sounds like that doesn't help anyway.
>>
>> You don't need :sortable => true on any attribute - they're sortable
>> by default, it's only fields that need it.
>>
>> What's the underlying column type? datetime or date? And using MySQL?
>> or PostgreSQL?
>>
>> Cheers
>>
>> --
>> Pat
>>
>> On 05/01/2009, at 10:02 AM, Oli wrote:
>>
>> >
>> > Hi Y'all
>> >
>> > so given this model definition
>> >
>> > http://pastie.org/352604
>> >
>> > i get this
>> >
>> > http://pastie.org/352592
>> >
>> > or this
>> >
>> > http://pastie.org/352596
>> >
>> > and in that last one the ordering is completely ignored ..
>> >
>> > any suggestions?
>> > >
>>
>>
>> >>
>

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