Class: Ace::Search::Organisms::ResultAggregator
- Inherits:
-
Object
- Object
- Ace::Search::Organisms::ResultAggregator
- Defined in:
- lib/ace/search/organisms/result_aggregator.rb
Overview
Aggregates and deduplicates search results This is an organism - business logic for result aggregation
Class Method Summary collapse
-
.aggregate(results_list) ⇒ Hash
Aggregate results from multiple sources.
-
.count_by_type(results) ⇒ Object
Count results by type.
-
.group_by_file(results) ⇒ Object
Group results by file.
-
.result_key(result) ⇒ Object
Generate unique key for a result.
Class Method Details
.aggregate(results_list) ⇒ Hash
Aggregate results from multiple sources
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ace/search/organisms/result_aggregator.rb', line 12 def self.aggregate(results_list) all_results = [] seen_results = Set.new results_list.each do |result_set| next unless result_set[:success] result_set[:results].each do |result| key = result_key(result) next if seen_results.include?(key) seen_results.add(key) all_results << result end end { success: true, results: all_results, count: all_results.size } end |
.count_by_type(results) ⇒ Object
Count results by type
61 62 63 64 65 66 67 68 69 |
# File 'lib/ace/search/organisms/result_aggregator.rb', line 61 def self.count_by_type(results) counts = Hash.new(0) results.each do |result| counts[result[:type]] += 1 end counts end |
.group_by_file(results) ⇒ Object
Group results by file
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ace/search/organisms/result_aggregator.rb', line 48 def self.group_by_file(results) grouped = {} results.each do |result| path = result[:path] grouped[path] ||= [] grouped[path] << result end grouped end |
.result_key(result) ⇒ Object
Generate unique key for a result
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ace/search/organisms/result_aggregator.rb', line 36 def self.result_key(result) case result[:type] when :file "file:#{result[:path]}" when :match "match:#{result[:path]}:#{result[:line] || result[:line_number]}" else "#{result[:type]}:#{result[:path]}" end end |