Forum: Ruby on Rails != not working in search query (thinking sphinx)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2c49cd424ddb3b3c9cef6ef7f45c8534?d=identicon&s=25 Sam Ginko (ginkod)
on 2009-05-24 17:13
I have a int field in my database and would like to check if it's not
0. Apparently the != in the condition is not working. I'm I doing
something wrong? I tried different ways with no luck. Can anyone help?

these are the options I tried

@allPost = Post.search params[:search], :conditions => 
["account_status
!= 0"]
@ allPost = Post.search params[:search], :conditions =>

["account_status != ?", 0]
@ allPost = Post.search params[:search], :conditions =>

["account_status IS NOT ?", 0]
@ allPost = Post.search params[:search], :conditions =>

["account_status < ?", 1]

thanks
68814ed988eee4f21b2cd07353e5e445?d=identicon&s=25 Mk 27 (mk27)
on 2009-05-24 17:20
Looks like I am one step ahead of you Sam, I learned this one yesterday:

http://www.ruby-forum.com/topic/187676#new

Look a few posts down for the series of "67 != 67"

Anyway, the problem is that w/ a HTTP request everything is received as
a string. So:

account_status.to_i
2c49cd424ddb3b3c9cef6ef7f45c8534?d=identicon&s=25 Sam Ginko (ginkod)
on 2009-05-24 18:22
Still not working. I tried


@ allPost = Post.search params[:search], :conditions
=>["account_status.to_i != ?", 0]

@ allPost = Post.search params[:search], :conditions
=>"account_status.to_i != 0"


Mk 27 wrote:
> Looks like I am one step ahead of you Sam, I learned this one yesterday:
>
> http://www.ruby-forum.com/topic/187676#new
>
> Look a few posts down for the series of "67 != 67"
>
> Anyway, the problem is that w/ a HTTP request everything is received as
> a string. So:
>
> account_status.to_i
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-24 20:06
(Received via mailing list)
On May 24, 5:22 pm, Sam Ginko <rails-mailing-l...@andreas-s.net>
wrote:
> Still not working. I tried
>
> @ allPost = Post.search params[:search], :conditions
> =>["account_status.to_i != ?", 0]
>
> @ allPost = Post.search params[:search], :conditions
> =>"account_status.to_i != 0"
>

Have a look at the documentation for sphinx/thinking sphinx - this
isn't activerecord any more, or SQL. To quote the thinking sphinx
docs:

> Please keep in mind that Sphinx does not support SQL comparison operators – it has its 
own query language. The
> :conditions option must be a hash, with each key a field and each value a string.

In addition, :conditions is for doing full text searches against
specific columns you have indexed - for filtering on attribute values
you need to use the :with option.

Fred
This topic is locked and can not be replied to.