Kouhei Sutou
null+****@clear*****
Sun May 25 16:39:33 JST 2014
Kouhei Sutou 2014-05-25 16:39:33 +0900 (Sun, 25 May 2014) New Revision: f5c4bf2d3a41f53be3de58cb7065a35331551504 https://github.com/groonga/heroku-sample-rroonga-blog/commit/f5c4bf2d3a41f53be3de58cb7065a35331551504 Message: Support multiple keywords Modified files: lib/post_searcher.rb Modified: lib/post_searcher.rb (+11 -1) =================================================================== --- lib/post_searcher.rb 2014-05-25 16:29:26 +0900 (7a59af9) +++ lib/post_searcher.rb 2014-05-25 16:39:33 +0900 (b236017) @@ -6,11 +6,21 @@ class PostSearcher def search matched_posts =****@posts***** do |record| - (record.title =~ @query) | (record.content =~ @query) + match_target = record.match_target do |match_record| + (match_record.title * 5) | (match_record.content) + end + words.collect do |word| + match_target =~ word + end end post_ids = matched_posts.sort(['_score']).collect do |matched_post| matched_post._key end Post.where(id: post_ids) end + + private + def words + @query.split(/\s+/) + end end -------------- next part -------------- HTML����������������������������... ダウンロード