0

I am using Propel 1.2 in a Symfony 1.0 project, with PostgreSQL db. I can use Criteria::CUSTOM in SELECT statements in order to use Postgres functions, like this (fulltext search):

`$c = new Criteria();

$c->add(MyTablePeer::FULLTEXT_COLUMN, MyTablePeer::FULLTEXT_COLUMN." @@ to_tsquery('english', 'text to search')", Criteria::CUSTOM);`

That's ok for selecting records, but what about INSERTing? I'm using raw SQL queries at the moment, but I would like to do it in a more elegant way. I saw this snippet on the Symfony website but it's a lot of code and it does not fit my needs. Performance is very important so maybe there isn't any solution better than writing raw SQL.

How can I write a custom setter like $object->setFulltextColumn($parameters)?

Thank you in advance

1 Answer 1

0

For insert/update on the fulltext column, why not use a trigger? Then the fulltext column will automatically be updated when you change the text for a row.

CREATE TRIGGER my_table_fulltext_trigger 
BEFORE INSERT OR UPDATE ON my_table 
FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger(
  'fulltext',
  'pg_catalog.english', 
  'column_with_text_1', 
  'column_with_text_2', 
  'column_with_text_N'
);

The parameters to the tsvector_update_trigger procedure are: name of tsvector fulltext column, language configuration, and then the names of all the columns to index.

1
  • OK, a trigger would be the solution, but it's raw SQL, as I said, no Propel tricks are suitable for this case. Thank you!
    – danieli
    Aug 3, 2009 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.