I'm afraid this is a limitation with ActiveRecord, as that's what's used to 
generate the underlying SQL queries in the Sphinx configuration file. At this 
point in time, I can't think of any ways around it that would work within 
Thinking Sphinx - you may need to modify the query by hand (and probably use an 
inner SELECT statement as a join table?)

-- 
Pat

On 30/10/2012, at 2:32 AM, Alexander Casassovici wrote:

> More details here : 
> http://stackoverflow.com/questions/13124082/tell-thinking-sphinx-to-only-index-the-latest-element-in-a-has-many-relationship
> 
> A post has many wiki entries... but only the latests makes sense to be 
> searchable. Unfortunately, while the has_many and has_one relationships work 
> fine, Thinking sphinx will always index the OLDEST wikis on each post... any 
> hint ?
> 
> has_many :wikis, :as => :source, :order => "updated_at DESC"
> 
> has_one 
> :latest_wiki, :class_name => "Wiki", :conditions => "source_type = 
> 'BlogPost'", :foreign_key => :source_id, :order => "wikis.updated_at 
> DESC"##used for sphinx to only index the latest revision
> 
> 
> 
> define_index 
> do
> 
>   indexes latest_wiki
> .data, :as => :
> post_data
>   indexes latest_wiki
> .title , :as => :
> post_title
>   indexes blob
>   has published
> , :type => :
> boolean
>   has id
> 
> end
> this will generate the following conf.. which clearly shows the has_one is 
> not understood properly :
> 
>     source blog_post_core_0
>     
> {
> 
>       type 
> =
>  mysql
>       sql_host 
> =
>  localhost
>       sql_user 
> =
>  root
>       sql_pass 
> =
>  diveboard
>       sql_db 
> =
>  diveboard
>       sql_query_pre 
> =
>  SET NAMES utf8
>       sql_query_pre 
> = SET TIME_ZONE = '+0:00'
> 
>       sql_query 
> = SELECT SQL_NO_CACHE `blog_posts`.`id` * CAST(10 AS SIGNED) + 0 AS `id` , 
> `wikis`.`data` AS `post_data`, `wikis`.`title` AS `post_title`, 
> `blog_posts`.`blob` AS `blob`, `blog_posts`.`id` AS `sphinx_internal_id`, 0 
> AS `sphinx_deleted`, 1270887957 AS `class_crc`, `blog_posts`.`published` AS 
> `published`, `blog_posts`.`id` AS `id` FROM `blog_posts` LEFT OUTER JOIN 
> `wikis` ON `wikis`.`source_id` = `blog_posts`.`id` AND source_type = 
> 'BlogPost' WHERE (`blog_posts`.`id` >= $start AND `blog_posts`.`id` <= $end) 
> GROUP BY `blog_posts`.`id`
>  ORDER BY NULL
>       sql_query_range 
> = SELECT IFNULL(MIN(`id`), 1), IFNULL(MAX(`id`), 1) FROM `blog_posts`
> 
>       sql_attr_uint 
> =
>  sphinx_internal_id
>       sql_attr_uint 
> =
>  sphinx_deleted
>       sql_attr_uint 
> =
>  class_crc
>       sql_attr_uint 
> =
>  id
>       sql_attr_bool 
> =
>  published
>       sql_query_info 
> = SELECT * FROM `blog_posts` WHERE `id` = (($id - 0) / 10)
> 
>     
> }
> 
> -- 
> 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/-/WGU_n8SYMKkJ.
> 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