hey Alex, sorry, I can't seem to see what's wrong with this. do you mind
giving me a copy of your application? i'll see what I can do when I get home
from work.

On Wed, Aug 4, 2010 at 3:50 PM, alex <[email protected]> wrote:

> here it is:
>
>  define_index do
>    indexes :name, :sortable => :true
>    indexes objectives
>    indexes topics.name, :as => :topic_name, :sortable => true
>    indexes lectures.title, :as => :lecture_title
>    indexes school.name, :as => :school_name, :sortable => true
>    indexes school.about, :as => :school_about
>    indexes school.short_names, :as => :school_short_names
>    indexes school.address.city, :as => :school_city
>
>    has school(:id), :as => :school_id
>    has topics(:id), :as => :topic_ids
>    has career_levels(:id), :as => :career_level_ids
>     has events(:day_of_week), :as => :days
>     has ('day_of_week is NOT NULL'), :as => :has_event, :type
> => :boolean
>
>    set_property :delta => true
>  end
>
>
> On Aug 3, 11:20 pm, Jim Ruther Nill <[email protected]> wrote:
> > what's your current define_index block?
> >
> >
> >
> >
> >
> > On Wed, Aug 4, 2010 at 1:44 PM, alex <[email protected]>
> wrote:
> > > Actually.... ... after a little testing I found a bug and would love
> > > your help!
> >
> > >  I believe the problem I'm now facing comes from the fact that not all
> > > tracks (thus not all courses) have events): I can have courses
> > > associated to 0..n track(s), each with an event with day = X, and to
> > > 0..n track(s) with no event.
> >
> > > Here are the 2 kinds of bugs I found (compare result from mysql with
> > > the ones I get with sphinx):
> >
> > > *** Bug type 1.
> >
> > > mysql> SELECT id, name FROM courses WHERE id IN (SELECT course_id FROM
> > > tracks WHERE id IN (SELECT track_id FROM events WHERE day_of_week IN
> > > (4)));
> > > +----+-------------------------+
> > > | id | name                    |
> > > +----+-------------------------+
> > > | 58 | Deleniti Doloremque Sit |
> >
> > > ?> Course.search(:with=> {:days=>[4], :has_event => true})
> > > => []
> >
> > > Course id = 58 is associated to
> > > * one track associated to an event with day_of_week = 4
> > > * two tracks not associated to any event
> >
> > > *** Bug type 2.
> >
> > > mysql> SELECT id, name FROM courses WHERE id IN (SELECT course_id FROM
> > > tracks WHERE id IN (SELECT track_id FROM events WHERE day_of_week IN
> > > (0)));
> > > +----+-------------------------------------------------+
> > > | id | name                                            |
> > > +----+-------------------------------------------------+
> > > |  7 | Et Voluptatem                                   |
> > > | 64 | Sunt Ipsam Vero Non Doloremque Voluptatem Autem |
> >
> > > >> Course.search(:with=> {:days=>[0], :has_event => true})
> > > => [#<Course id: 3, name: "Dignissimos Quasi", ...>, #<Course id: 33,
> > > name: "Minus Aut Enim Et Dolor Sed", ...>, #<Course id: 34, name:
> > > "Pariatur Repellat Ea Alias Qui Occaecati Quam", ...>, #<Course id:
> > > 64, name: "Sunt Ipsam Vero Non Doloremque Voluptatem Autem", ...>]
> >
> > > Except for course id = 64 which is accurate, all the other courses
> > > don't have an event on day_of_week = 0 (but they all have a mix of
> > > tracks associated with events and tracks not associated to any event).
> >
> > > Here are more details about the models:
> >
> > > The model is:
> >
> > > course   (0..n tracks, 0..n events)
> > >   has_many :tracks
> > >    has_many :events, :through :tracks
> >
> > > track
> > >   belongs_to :course
> > >   has_many :events
> >
> > > event
> > >   belongs_to :track
> > >   has_one :course, :through :track
> >
> > > * an event is a frequency, day_of_week, start_time and end_time (for
> > > instance: frequency = 7 days, day of week = Tuesday, from 14:00 to
> > > 16:00)
> > > * a track has a type, a start_date and an end_date (Workshop from
> > > 08/15/2010 to 08/30/2010)
> > > * a course has a title, a description, etc
> >
> > > I'm a little confused and can't figure out a way to make this work...
> > > can you help?
> >
> > > Thanks!
> > > Alex
> >
> > > On Aug 3, 8:12 pm, Jim Ruther Nill <[email protected]> wrote:
> > > > sure. I'm happy to take some load off Pat's shoulders :D
> >
> > > > On Wed, Aug 4, 2010 at 11:08 AM, alex <[email protected]>
> > > wrote:
> > > > > uuuhhh!  It works perfectly!
> >
> > > > > Thank you so much for the help!
> > > > > Have a great day.
> >
> > > > > Cheers,
> > > > > Alex
> >
> > > > > On Aug 3, 7:56 pm, Jim Ruther Nill <[email protected]> wrote:
> > > > > > 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]>
> <thinking-sphinx%2Bunsubscribe@ googlegroups.com>
> > > <thinking-sphinx%2Bunsubscribe@ googlegroups.com>
> > > > > <thinking-sphinx%2Bunsubscribe@ googlegroups.com>
> > > > > > > .
> > > > > > > > > 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]>
> <thinking-sphinx%2Bunsubscribe@ googlegroups.com>
> > > <thinking-sphinx%2Bunsubscribe@ googlegroups.com>
> > > > > <thinking-sphinx%2Bunsubscribe@ googlegroups.com>
> > > > > > > .
> > > > > > > For more options, visit this group at
> > > > > > >http://groups.google.com/group/thinking-sphinx?hl=en.
> >
> > > > > > --
> > > > > > -------------------------------------------------------------
> > > > > > visit my blog athttp://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]<thinking-sphinx%[email protected]>
> <thinking-sphinx%2Bunsubscribe@ googlegroups.com>
> > > <thinking-sphinx%2Bunsubscribe@ googlegroups.com>
> > > > > .
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/thinking-sphinx?hl=en.
> >
> > > > --
> > > > -------------------------------------------------------------
> > > > visit my blog athttp://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]<thinking-sphinx%[email protected]>
> <thinking-sphinx%2Bunsubscribe@ googlegroups.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/thinking-sphinx?hl=en.
> >
> > --
> > -------------------------------------------------------------
> > visit my blog athttp://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]<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.

Reply via email to