Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save staycreativedesign/84151271e9b14ceed1997b2fb151a26c to your computer and use it in GitHub Desktop.
Save staycreativedesign/84151271e9b14ceed1997b2fb151a26c to your computer and use it in GitHub Desktop.
class Search < ApplicationRecord
def self.search_posts(keywords)
posts = Post.all
posts = posts.where(["title LIKE ?", "%#{keywords}%"]) if keywords.present?
return posts
end
end
@nilbus
Copy link

nilbus commented May 9, 2019

  1. The LIKE approach will get slower as the number of posts gets larger.

If you do #2, then performance may or may not get significantly worse when increasing the number of search terms. (Nothing is stopping a user from pasting in a paragraph, hoping it will match the body…) I'd test with that too. This could affect multiple LIKE searches but should be fine if you switch to fulltext search later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment