Rails: efficiently check if keywords in a model match content in another model?
How can I efficiently check several thousand rows against a table of keywords?
I have two tables, Essays and Tags. They are tied together by a has_and_belongs_to_many association.
Tags has around 250 keywords (rows) and several thousand essays are开发者_运维知识库 added every day.
I want to scan the essay subject and content against the keywords in the Tags table and if there is a match, associate the Tag with the essay
What would be the most efficient way to do this?
Is there any way of doing this aside from iterating through each essay and then regex matching the content against all of the tag keywords?
If you are looking at getting drastic performance improvement then my suggestion would be to go with some sort of indexing system like ultrasphinx.
https://github.com/fauna/ultrasphinx
Another good option is using acts_as_indexed plugin:
http://douglasfshearer.com/blog/rails-plugin-acts_as_indexed
精彩评论