Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
tell thinking sphinx to only index the latest element in a has_many relationship
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alexander Casassovici  
View profile  
 More options Oct 29 2012, 11:32 am
From: Alexander Casassovici <alexk...@gmail.com>
Date: Mon, 29 Oct 2012 08:32:52 -0700 (PDT)
Local: Mon, Oct 29 2012 11:32 am
Subject: tell thinking sphinx to only index the latest element in a has_many relationship

More details here :
http://stackoverflow.com/questions/13124082/tell-thinking-sphinx-to-o...

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 idend

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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pat Allan  
View profile  
 More options Nov 5 2012, 5:08 am
From: "Pat Allan" <p...@freelancing-gods.com>
Date: Mon, 05 Nov 2012 05:08:23 -0500
Local: Mon, Nov 5 2012 5:08 am
Subject: Re: [ts] tell thinking sphinx to only index the latest element in a has_many relationship
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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »