17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'app/models/concen/visit/referral.rb', line 17
def self.aggregate_count_by_domain(*args)
options = args.
map = " function() {\n if (this.domain != null) {\n emit(this.domain, this.count);\n };\n }\n EOF\n\n reduce = <<-EOF\n function(time, counts) {\n var count = 0;\n for (index in counts) { count += counts[index]; };\n return count;\n }\n EOF\n\n results = self.collection.map_reduce(map, reduce, :out => {:inline => 1}, :raw => true)[\"results\"]\n results = results.sort {|x,y| y[\"value\"] <=> x[\"value\"]}\n results = results[0..options[:limit]-1] if options[:limit]\n results = results.map do |result|\n [result[\"_id\"], result[\"value\"].to_i]\n end\nend\n"
|