Hi,

Assuming you're using MySQL, you can try adding a boolean attribute to
your index like so:

    has "IF(expired_at IS NOT NULL AND expired_at < now(), 1, 0)", :as => 
:expired_user, :type => :boolean

And then only search for products from non-expired users like so:

    @products = Product.search(params[:search], :page => params[:page] || 1,
                                                :include => :user,
                                                :with => {:expired_user => 0})

James

nugatowy wrote:
> 
> Hello, I've just started using Thinking Sphinx and I need Your help.
> 
> I have 2 models:
> 
> def user
>  has_many :products
> end
> 
> def product
>  belongs_to :user
> (...)
>   #TS
>   define_index do
>     indexes :name, :sortable => true
>     indexes description
>     indexes user.name
>     has user_id
>   end
> (...)
> end
> 
> In products_controller I have something like this:
> 
> def index
>         @products = Product.search params[:search], :page => params
> [:page], :include => :user
> end
> 
> Users have a column with date of their account expiry. I would like to
> list all products that belong to users whose accounts are not expired.
> 
> Calculation of account expiry that I'm using in some places of the
> application is like below (in User model):
> 
>   attr_accessor :has_premium_account
> 
>   def has_premium_account
>     true if expired_at and expired_at.to_date - Time.now.to_date >= 0
>   end
> 
> So, is there any way (elegant or not) to write conditions that will
> select just the products of not-expired users via Thinking Sphinx?
> 
> Thank You for any help.
> 
> > 

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