[groonga-commit:2869] ranguba/ranguba [scoring] use Ranguba::Searcher
null+ranguba at clear-code.com
null+ranguba at clear-code.com
Tue Dec 21 22:46:51 EST 2010
Kenji Okimoto 2010-11-17 06:18:20 +0000 (Wed, 17 Nov 2010)
New Revision: ac991c13f855cf3403ff751527fe434db0d056d5
Log:
use Ranguba::Searcher
Modified files:
app/models/search_request.rb
Modified: app/models/search_request.rb (+4 -33)
===================================================================
--- app/models/search_request.rb 2010-11-17 06:17:42 +0000 (579f8e1)
+++ app/models/search_request.rb 2010-11-17 06:18:20 +0000 (eefd6ac)
@@ -240,9 +240,10 @@ class SearchRequest
end
def handle
- set = Ranguba::Entry.select do |record|
- apply_conditions(record)
- end
+ searcher = Ranguba::Searcher.new(:query => @request.query,
+ :type => @request.type,
+ :category => @request.category)
+ set = searcher.search
set.extend(CachedResultSet)
drilldown_targets = [:category, :type].find_all do |column|
@request.send(column).blank?
@@ -252,36 +253,6 @@ class SearchRequest
set
end
- private
- def apply_conditions(record)
- conditions = []
- apply_query_condition(record, conditions)
- apply_category_condition(record, conditions)
- apply_type_condition(record, conditions)
- conditions
- end
-
- def apply_query_condition(record, conditions)
- query = @request.query
- return if query.blank?
- query.split.each do |term|
- conditions << ((record.key.key =~ term) |
- (record["title"] =~ term) |
- (record["body"] =~ term))
- end
- end
-
- def apply_category_condition(record, conditions)
- category = @request.category
- return if category.blank?
- conditions << (record["category"] == category)
- end
-
- def apply_type_condition(record, conditions)
- type = @request.type
- return if type.blank?
- conditions << (record["type"] == type)
- end
end
end
More information about the groonga-commit
mailing list