Hi Pat,

Thanks.  Yes I saw that part of the documentation, and have used that for
strings within the same model.  However I could not find any way to apply
it for a string in an associated model.  So I'll just stick to the
:conditions.  Good thing the association in question is just a belongs_to
so it's quite simple -- just feels overkill because the string was really
for gender - "M" and "F".

Thanks again!

Johann


On Wed, Nov 28, 2012 at 7:39 PM, Pat Allan <[email protected]> wrote:

> Hi Johann
>
> If it needs to be an attribute filter, rather than the previous examples
> using :conditions on a field, then you should read through this item in the
> docs:
> http://pat.github.com/ts/en/common_issues.html#string_filters
>
> But I think using :conditions and fields is perhaps the way to go. These
> approaches are valid whether it's via an association or not. The only
> tricky part is matching on exact values from a field in a has_many
> association - all values get combined together.
>
> --
> Pat
>
> On 28/11/2012, at 6:55 PM, Johann Tagle wrote:
>
> > Hi.  I'm just wondering, since this thread is more than two years old,
> if this is still the way to filter by a string from an associated model, or
> if there is already a way to compute a string ordinal for it.  Thanks.
> >
> > Johann
> >
> > On Sunday, March 28, 2010 12:54:24 PM UTC+8, Pat Allan wrote:
> > Hi Carson
> > You can search on all fields and specific fields at once:
> >
> >   Post.search 'whatever', :conditions => {:user => 'Carson'}
> >
> > Or even:
> >
> >   Post.search :conditions => {:user => 'Carson', :title => 'Whatever'}
> >
> > Hope this helps
> >
> > --
> > Pat
> >
> > On 25/03/2010, at 3:31 AM, Carson wrote:
> >
> > > That will allow me to search for user.first_name, and works, but what
> > > about searching for that plus text from a post.
> > >
> > > In other words, I want all posts by an author with the first name
> > > 'carson' that has a post title 'whatever'
> > >
> > > Thanks for the help!
> > >
> > > On Mar 24, 1:52 am, Amir Yalon <[email protected]> wrote:
> > >> In stead of:
> > >>   has user(:id), :as => :author
> > >> try to declare:
> > >>   indexes user.first_name, :as => :author
> > >> and adjust your query accordingly.
> > >>
> > >>
> > >>
> > >> On Wed, Mar 24, 2010 at 00:30, Carson <[email protected]> wrote:
> > >>> Very new to this, so please stick with me.  I have 2 models:
> > >>
> > >>> User:
> > >>> id, first_name, last_name, created_at
> > >>
> > >>> define_index do
> > >>>    indexes user.first_name, user.last_name
> > >>> end
> > >>
> > >>> Post:
> > >>> id, user_id, title, post, created_at
> > >>
> > >>> define_index do
> > >>>    indexes title, post
> > >>
> > >>>    has user(:id), :as => :author
> > >>
> > >>>    set_property :enable_star => 1
> > >>>    set_property :min_prefix_len => 3
> > >>>  end
> > >>
> > >>> I'm trying to search all Posts with "page" in the title, that have
> > >>> been authored by a certain user.  I can get it to work by passing in
> > >>> the ID of a user with conditions on the search.  But how can I do it
> > >>> by passing in a string of the first_name of the user?  Is it
> possible?
> > >>
> > >>> Thanks in advance.
> > >>
> > >>> following is the actual search, that uses the user_id:
> > >>
> > >>> @per_page = 20
> > >>
> > >>>      conditions = Hash.new
> > >>
> > >>>      if params[:start_date] != nil && params[:end_date] != nil
> > >>>        start_date = Time.parse(params[:start_date])
> > >>>        end_date = Time.parse(params[:end_date])
> > >>>        conditions.merge!({ :created_at => start_date..end_date })
> > >>>      end
> > >>
> > >>>      authors = Array.new
> > >>>      authors.push(16)
> > >>
> > >>>      conditions.merge!({:author => authors})
> > >>
> > >>>      @classes.push(User)
> > >>>      @classes.push(Post)
> > >>
> > >>>  if @classes.count > 0
> > >>>        @results = ThinkingSphinx::Search.search '*' + params[:query]
> > >>> + '*', :with => conditions, :classes => @classes, :index_weights =>
> > >>> { School => 10, User => 10, UserWallpost => 70, GroupDiscussion =>
> 90,
> > >>> GroupDiscussionComment => 80, Item => 100 }, :retry_stale =>
> > >>> true, :per_page => @per_page, :page => params[:page]
> > >>>  end
> > >>
> > >>> --
> > >>> 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%2Bunsubscribe@
> googlegroups.com>
> > >>> .
> > >>> For more options, visit this group at
> > >>> http://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].
> > > For more options, visit this group at
> http://groups.google.com/group/thinking-sphinx?hl=en.
> > >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Thinking Sphinx" group.
> > To view this discussion on the web visit
> https://groups.google.com/d/msg/thinking-sphinx/-/vKDcNSz-c70J.
> > 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.
>
>
> --
> 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.
>
>

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