Sorting by Boolean Fields

34 views
Skip to first unread message

djfobbz

unread,
Dec 29, 2009, 12:44:26 PM12/29/09
to Thinking Sphinx
I have a Listings model that has description (text) and website
(string) columns along with corresponding has_description (boolean) &
has_website (boolean) columns to give precedence (0 for not present
and 1 for present) during search time accordingly. I have defined
these boolean columns as integer to allow be to sort them ASC or DESC
based on 1 or 0. My index setup is as below:

define_index do
has :has_description, :type => :integer
has :has_website, :type => :integer
set_property(:morphology => 'stem_en')
set_property(:ignore_chars => 'U+0027')
set_property(:enable_star => true)
end

Search Code:
@listings = Listing.search(params[:q], :order => "has_description
DESC, has_website DESC, name ASC, population DESC", :page => params
[:page])

My problem is that when I have both has_description and has_website as
columns to sort by, I get no results back. However, when I just list
1 or the other as below:

@listings = Listing.search(params[:q], :order => "has_description
DESC, name ASC, population DESC", :page => params[:page])

I get search results. Any ideas why?

djfobbz

unread,
Dec 29, 2009, 12:46:49 PM12/29/09
to Thinking Sphinx
Sorry, my index setup is the following (the one listed above is
incorrect):

define_index do
indexes :name, :sortable => true
has :population, :type => :integer


has :has_description, :type => :integer
has :has_website, :type => :integer
set_property(:morphology => 'stem_en')
set_property(:ignore_chars => 'U+0027')
set_property(:enable_star => true)
end

Pat Allan

unread,
Dec 29, 2009, 11:31:25 PM12/29/09
to thinkin...@googlegroups.com
I set up a pretty much identical model on my local machine, and everything worked fine... so I guess the first thing to check is, did you re-index and restart Sphinx after adding the explicit :type settings?

Mind you, it worked fine for me with and without the :type - are you using MySQL? Or PostgreSQL?

--
Pat

> --
>
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To post to this group, send email to thinkin...@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages