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