Created
May 9, 2019 14:52
-
-
Save staycreativedesign/84151271e9b14ceed1997b2fb151a26c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Search < ApplicationRecord | |
def self.search_posts(keywords) | |
posts = Post.all | |
posts = posts.where(["title LIKE ?", "%#{keywords}%"]) if keywords.present? | |
return posts | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.