Question

In the documentation of the Rails gem oracle-enhanced i found this to create an index on multiple tables:

add_context_index :posts,
[:title, :body,
 "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
],
:name => 'post_and_comments_index',
:index_column => :all_text,
:index_column_trigger_on => [:updated_at, :comments_count],
:sync => 'ON COMMIT'

This works if a post has many comments. But how would i write this if a post has only one comment (belongs_to)? Or what about a has_many trough relation?

Thanks for your help.

-e- Just to try something out i did

add_context_index :posts, [:title, :body]

and got this exception:

NativeException: java.sql.SQLException: ORA-06550: line 2, column 13:
PLS-00201: identifier 'CTX_DDL' must be declared
Was it helpful?

Solution

Instead of doing one Index with joins over multiple tables to do the search, i decided to index each column on it's own, searching in each table separately and copy the matching id's into a temporary look-up table. This is pretty straight forward and fast.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top