Created
June 9, 2013 20:49
-
-
Save bplexico/5745152 to your computer and use it in GitHub Desktop.
latest update_index method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.update_index(observer_search_data) | |
# Would be nice to use AR here but not sure how to execut Postgres functions | |
# when inserting data like this. | |
rows = Post.exec_sql_row_count("UPDATE #{observer_search_data.table_name} SET search_data = TO_TSVECTOR('english', ?) WHERE #{observer_search_data.foreign_key} = ?", observer_search_data.search_data, observer_search_data.id) | |
if rows == 0 | |
Post.exec_sql("INSERT INTO #{observer_search_data.table_name} (#{observer_search_data.foreign_key}, search_data) VALUES (?, TO_TSVECTOR('english', ?))", observer_search_data.id, observer_search_data.search_data) | |
end | |
rescue | |
# don't allow concurrency to mess up saving a post | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment