Class: Redmine::Search::Fetcher
- Inherits:
-
Object
- Object
- Redmine::Search::Fetcher
- Defined in:
- lib/redmine/search.rb
Instance Attribute Summary collapse
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
-
#initialize(question, user, scope, projects, options = {}) ⇒ Fetcher
constructor
A new instance of Fetcher.
-
#result_count ⇒ Object
Returns the total result count.
-
#result_count_by_type ⇒ Object
Returns the result count by type.
-
#result_ids ⇒ Object
Returns the results ids, sorted by rank.
-
#results(offset, limit) ⇒ Object
Returns the results for the given offset and limit.
Constructor Details
#initialize(question, user, scope, projects, options = {}) ⇒ Fetcher
Returns a new instance of Fetcher.
53 54 55 56 57 58 59 60 61 |
# File 'lib/redmine/search.rb', line 53 def initialize(question, user, scope, projects, ={}) @user = user @question = question.strip @scope = scope @projects = projects @cache = .delete(:cache) @options = @tokens = Tokenizer.new(@question).tokens end |
Instance Attribute Details
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
51 52 53 |
# File 'lib/redmine/search.rb', line 51 def tokens @tokens end |
Instance Method Details
#result_count ⇒ Object
Returns the total result count
64 65 66 |
# File 'lib/redmine/search.rb', line 64 def result_count result_ids.size end |
#result_count_by_type ⇒ Object
Returns the result count by type
69 70 71 72 73 74 75 |
# File 'lib/redmine/search.rb', line 69 def result_count_by_type ret = Hash.new {|h, k| h[k] = 0} result_ids.group_by(&:first).each do |scope, ids| ret[scope] += ids.size end ret end |
#result_ids ⇒ Object
Returns the results ids, sorted by rank
91 92 93 |
# File 'lib/redmine/search.rb', line 91 def result_ids @ranks_and_ids ||= load_result_ids_from_cache end |
#results(offset, limit) ⇒ Object
Returns the results for the given offset and limit
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/redmine/search.rb', line 78 def results(offset, limit) result_ids_to_load = result_ids[offset, limit] || [] results_by_scope = Hash.new {|h, k| h[k] = []} result_ids_to_load.group_by(&:first).each do |scope, scope_and_ids| klass = scope.singularize.camelcase.constantize results_by_scope[scope] += klass.search_results_from_ids(scope_and_ids.map(&:last)) end result_ids_to_load.map do |scope, id| results_by_scope[scope].detect {|record| record.id == id} end.compact end |