Using Thinking Sphinx with Polymorphic Associations

12 views
Skip to first unread message

admkrm

unread,
Aug 1, 2008, 4:40:52 AM8/1/08
to Thinking Sphinx
Dear listmembers (and Pat of course),

I'm having a bit of trouble using Thinking Sphinx in a specific case
involving polymorpic associatons, and I hope you can help me out here.
I'm building a lifestreaming application.

I have an Element model, i.e. the elements of the lifestream, with
(amongst others) the following properties:
id
title
elementable_id
elementable_type
(belongs_to :elementable, :polymorphic => true, :dependent
=> :destroy)

The elements in question can be of the type Note / Photo / Event,
hence e.g. the following model Note
id
body
created_at
updated_at
(has_one :element, :as => :elementable)

I'm using Thinking Sphinx to perform full-text search on the
elements:
define_index do
indexes title
indexes comments.body, :as => :comment_content (KM: for a related
comments table)
has user_id
has :private
end

This all works splendidly, until I want to index e.g. the body from
the notes table, the caption from the videos table ... I'm going to
spare you all the combinations I've tried, but each give an error when
I'm trying to re-index...

Thanks in advance for looking at this problem, kind regards, Kristof

Pat Allan

unread,
Aug 1, 2008, 11:56:01 AM8/1/08
to thinkin...@googlegroups.com
Hi Kristof

What's the error (or errors) you're getting when you index?

--
Pat

admkrm

unread,
Aug 1, 2008, 3:31:44 PM8/1/08
to Thinking Sphinx
Pat,

When I add the following to define_index: 'indexes elementable.body'

I get the following error:

ERROR: index 'element_core': sql_range_query: Unknown column
'photos.body' in 'field list' (DSN=mysql://root:***@localhost:3306/
xxx_development).

Because indeed the photos table does not have a body column (the Notes
table has).

When I add 'indexes notes.body' to define_index

I get the following error:

ERROR: index 'element_core': sql_range_query: Unknown column
'elements.body' in 'field list' (DSN=mysql://root:***@localhost:3306/
xxx_development).

In neither cases the content of the body field is being indexed.

Thanks for looking at this issue, kind regards, Kristof

Pat Allan

unread,
Aug 1, 2008, 4:08:12 PM8/1/08
to thinkin...@googlegroups.com
Hi Kristof

There was a bug - I've just pushed through a fix to Github. If you
could try that out, see if it helps, that'd be great.

Cheers

--
Pat

admkrm

unread,
Aug 1, 2008, 4:54:21 PM8/1/08
to Thinking Sphinx
Pat,

Works like a charm now! I owe you one.

Kind regards, keep up the splendid work, Kristof
Reply all
Reply to author
Forward
0 new messages