you can add an attribute like
has 'day_of_week is NULL', :as => :no_event, :type => :boolean
then add in your search
Model.search :with => {:no_event => false}
On Wed, Aug 4, 2010 at 10:52 AM, alex <[email protected]> wrote:
> Hey Pat,
>
> Thanks for your reply!
>
> From your explanation, I understand where my problem comes from:
> Some courses are not associated to any event... so when I search for
> courses associated to events with day_of_week = 0 it also returns the
> courses that are not associated to any event.
>
> Is there any workaround so that when I search for 0 it doesn't return
> the courses not associated with any event? (if not, I'll have to
> migrate my events so that I don't use day_of_week = 0 anymore)
>
> Thanks again!
> Alex
>
>
>
> On Aug 3, 7:07 pm, Pat Allan <[email protected]> wrote:
> > Hi Alex
> >
> > A couple of suggestions:
> >
> > * Remove the :type => :integer from the attribute - you're dealing with
> an array of integers, not a single one, so this just confuses Sphinx. TS is
> smart enough to recognise arrays of integers.
> >
> > * Use actual integers, not integers-as-strings, in your filter.
> >
> > Also, it's worth noting that Sphinx treats NULLs as 0's - so if you have
> events attached to a course which have NULL for the day_of_week, it'll come
> through as 0.
> >
> > Hope this helps.
> >
> > --
> > Pat
> >
> > On 04/08/2010, at 11:47 AM, alex wrote:
> >
> >
> >
> > > Hello,
> >
> > > I'm having a problem searching for attributes with a value equal to 0.
> >
> > > Here is what happen in irb:
> >
> > >>> Course.search(:with=> {:days=>["2"]})
> > > returns the corresponding records
> >
> > >>> Course.search(:with=> {:days=>["0"]})
> > > returns all the records, while I'm expecting only a few records to
> > > be returned.
> >
> > > Here are the pieces of code I think are involved:
> >
> > > course.rb
> > > has_many :events, :through => :tracks
> > > ...
> > > define_index do
> > > has events(:day_of_week), :as => :days, :type => :integer
> > > end
> > > ...
> > > def self.advanced_search(search, sort = nil)
> > > with_params = {}
> > > ...
> > > if (!search.days.empty?)
> > > with_params[:days] = search.days
> > > end
> > > ...
> > > search(
> > > search.keywords,
> > > :with => with_params,
> > > :sort_mode => sort_params[:sort_mode],
> > > :order => sort_params[:order]).collect
> > > end
> > > end
> >
> > > Can anybody help me understand why I don't get the expected result?
> >
> > > Thanks!
> > > Alex
> >
> > > --
> > > 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]<thinking-sphinx%[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]<thinking-sphinx%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/thinking-sphinx?hl=en.
>
>
--
-------------------------------------------------------------
visit my blog at http://jimlabs.heroku.com
--
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.