Hi,

I've converted (from UltraSphinx, previously ferret, to TS) an app
which uses some metaprogramming to support "user defined fields' -
called DynamicAttributes. Overall it's been easy, and TS is very
elegant (and fast). However, the dynamically attributes are giving me
grief. Could anyone point me to docs I've missed?

Some details for the curious: a Contact has some standard fields
like :first_name, :email, which TS indexes and searches just fine. A
bunch more fields may be defined for a Contact in tables
dynamic_attributes and dynamic_attribute_values, and then
Contact.create_attributes inserts definitions for these extra methods
into the Contact classdef. Code is here (please excuse the mess):
http://github.com/thomasn/forgetmenot/blob/b77cd69cbfdfb55de78695fba37e3aaf49e32273/app/models/contact.rb#L91

On line 127, there's a debug output line:
puts "#### #{Contact.find(2032).enquiry_codes}" # FIXME

With my local db, which defines "enquiry_codes" as a string
DynamicAttribute, and has a value for this field (for this row), it
successfully prints the value. The SQL (pgsql) to get to it is:

SELECT * FROM "dynamic_attribute_values" WHERE
("dynamic_attribute_values"."contact_id" = 2032 AND
"dynamic_attribute_values"."dynamic_attribute_id" = 16) LIMIT 1

where
forgetmenot_development=# SELECT * from dynamic_attributes WHERE id =
16;
 id |     name      | type_name
----+---------------+-----------
 16 | enquiry_codes | string
(1 row)

When I uncomment line 129 I get:
ERROR: index 'contact_delta': sql_range_query: ERROR:  column
contacts.enquiry_codes does not exist

... because sphinx is trying to "SELECT enquiry_codes FROM contacts"
or similar, where I need to tell TS that this is an indirect
association, not a standard has-many-through one but a custom one.

(Full output at http://pastie.org/597171 , error at line 22).


So... is there any way I am going to be able to tell TS to index on
these dynamic attributes? I'm looking at the custom SQL approach, but
don't yet see daylight. The examples, and the comments in the TS code
in builder.rb "# Adding SQL Fragment Fields", are discussing SQL
fragments like "age < 18" and "LOWER(first_name)". How can I use a
SELECT as the actual value to index? Is there some trick with
subselects I'm missing here?

Thanks all for this very classy piece of kit.

-- Thomas

--~--~---------~--~----~------------~-------~--~----~
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