Skip to content

Commit

Permalink
Added basic search to posts.
Browse files Browse the repository at this point in the history
  • Loading branch information
robwilliams committed May 21, 2012
1 parent 4ca570c commit af35ddc
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/active_press/models/post.rb
Expand Up @@ -17,6 +17,19 @@ class ActivePress::Post < ActivePress::Base
scope :published, lambda { by_post_status('publish').before_now }
scope :most_recent, order("post_date_gmt DESC")

# Basic post search.
# Requires FULLTEXT indexes on post_name and post_content
# ALTER TABLE wp_posts ADD FULLTEXT(post_name);
# ALTER TABLE wp_posts ADD FULLTEXT(post_content);
def self.search(query)
where(
['(MATCH(post_name) against ?) OR (MATCH(post_content) against ?)',
query,
query
]
)
end

def self.by_year(d)
where(:post_date_gmt => (d.beginning_of_year..d.end_of_year))
end
Expand Down

0 comments on commit af35ddc

Please sign in to comment.