Hi Brian

This is more a limitation in the generated SQL query - Sphinx indexes multiple 
records at once, so the order clause doesn't take effect (unless we involve 
subqueries - and even then, it's maybe not viable).

I know it's not ideal, but I'd probably be caching the latest search text in 
your document model instead. If you really want that indexed by Sphinx, any 
other way is probably too messy, if it is possible at all.

Cheers

-- 
Pat

On 25/08/2010, at 7:24 AM, Brian M wrote:

> I'm having trouble indexing a has_one association with order.  It
> seems like the order that makes my has_one work (and return the most
> recent one) isn't being carried though to the Sphinx SQL.
> 
> I have a document model that has_many revisions.  I'd like to include
> the search_text field from the current_revision on my document index.
> To do this, I setup an association on the document model and reflected
> the association in my index:
> 
> has_one :current_revision, :class_name => "Revision", :order =>
> 'position DESC'
> 
> define_index do
>  indexes title
>  indexes description
>  indexes current_revision(:search_text), :as => :revision_text
> end
> 
> Generating something like:
> 
> SELECT SQL_NO_CACHE `documents`.`id` * 2 + 1 AS `id` ,
> `documents`.`title` AS `title`, `documents`.`description` AS
> `description`, `revisions`.`search_text` AS `revision_text`,
> `documents`.`id` AS `sphinx_internal_id`, 555739168 AS `class_crc`, 0
> AS `sphinx_deleted` FROM `documents`    LEFT OUTER JOIN `revisions` ON
> revisions.document_id = documents.id  WHERE `documents`.`id` >= $start
> AND `documents`.`id` <= $end GROUP BY `documents`.`id`  ORDER BY NULL
> 
> When I test that it consistently returns the search_text from the
> earliest revision, ignorant of my position DESC statement.  Is this
> something that Sphinx can handle or should I hack around and add a
> is_current_revision field to the revisions table (conditions on a
> has_one worked in testing)?
> 
> -- 
> 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