Hi Peter

Firstly, I was a little confused with your example, but attribute_names is an 
AR method, not something Thinking Sphinx adds.

Secondly, while you can access the attribute values returned by Sphinx using 
the sphinx_attributes hash (see below), Sphinx doesn't store string attributes 
as strings, but as integers - they're useful for sorting, but not much else.

  Post.search.first.sphinx_attributes

You can pass in :includes to your search call though, and it will be handed to 
ActiveRecord in the underlying find call when instantiating search results. 
This may keep the extra queries down instead?

-- 
Pat

On 19/12/2009, at 1:18 PM, peter wrote:

> On Dec 18, 5:18 pm, Pat Allan <[email protected]> wrote:
>> Hi Peter
>> 
>> Are you wanting those two columns as fields or attributes?
> 
> Thanks for the reply Pat. I actually just want attributes. Don't need
> to search the text of the topic_title or forum_name. But I do need
> those two to appear as "special guest star" attributes of the Post
> objects returned by Post.search.
> 
> I did try turning those two data elements into fields, rather than
> attributes, just as you described. But this didn't seem to cause them
> to appear as part of the Post object search results. i.e. After
> changing these two to fields as your describe, and rebuilding the
> index, here is a Ruby console request showing that these two are
> missing:
> 
>>> Post.search.first.attribute_names
> => ["body", "body_html", "created_at", "forum_id", "id", "topic_id",
> "updated_at", "user_id"]
> 
> The attributes that are present in the resulting Post objects are
> simply the columns from the posts table. "body" is one of those
> columns. And define_index instructs Sphinx to index that field.
> 
> But although Sphinx is also instructed to index topic_title and
> forum_name, and even though I can sort on those two (e.g. Post.search
> ('blah', :order => :topic_title), I can't access them as attributes of
> the search result objects.
> 
> Doesn't it seem like the search objects returned by TS should contain
> as attributes all of the "indexes" and "has" attributes declared in
> "define_index"? Or, at least, it seems there should be an option to
> include when running TS search to have all of the define_index
> attributes included as attributes present in the resulting objects.
> 
> For now, I have to hack up some ugly code, taking the TS array of Post
> objects returned by Post.search, and, for each object, adding back in
> those two dynamic attributes. It's not that painful in terms of
> performance since only 20 results are returned at a time (meaning an
> extra 40 quick database hits per results page -- i.e. 20 hits on Topic
> + 20 hits on Forum), and my site has low traffic. But still, like I
> said: ugly. Hopefully temporary. :)
> 
> Thanks for your help.
> 
> Peter
> 
> --
> 
> 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