sunspot_stats 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/dsl/field_query.rb +1 -1
 - data/lib/query/field_stat.rb +1 -1
 - data/lib/search/stat_facet.rb +8 -4
 - data/lib/search/stat_row.rb +4 -4
 - data/lib/search/stat_search.rb +12 -1
 - data/lib/sunspot_stats/version.rb +1 -2
 - data/sunspot_stats.gemspec +1 -1
 - metadata +53 -67
 
    
        data/lib/dsl/field_query.rb
    CHANGED
    
    
    
        data/lib/query/field_stat.rb
    CHANGED
    
    | 
         @@ -23,7 +23,7 @@ module Sunspot 
     | 
|
| 
       23 
23 
     | 
    
         
             
                      :stats  => 'true',
         
     | 
| 
       24 
24 
     | 
    
         
             
                      :"stats.field" => @field.indexed_name
         
     | 
| 
       25 
25 
     | 
    
         
             
                    }
         
     | 
| 
       26 
     | 
    
         
            -
                    params.merge!({:"stats.facet" 
     | 
| 
      
 26 
     | 
    
         
            +
                    params.merge!({:"stats.facet" => @options[:facet].indexed_name}) if !@options[:facet].nil?
         
     | 
| 
       27 
27 
     | 
    
         
             
                    params
         
     | 
| 
       28 
28 
     | 
    
         
             
                  end
         
     | 
| 
       29 
29 
     | 
    
         
             
                end
         
     | 
    
        data/lib/search/stat_facet.rb
    CHANGED
    
    | 
         @@ -11,7 +11,10 @@ module Sunspot 
     | 
|
| 
       11 
11 
     | 
    
         
             
                  end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
                  def rows
         
     | 
| 
      
 14 
     | 
    
         
            +
                    #sort options :count or :stat_field 
         
     | 
| 
      
 15 
     | 
    
         
            +
                    @options[:sort] ||= :count
         
     | 
| 
       14 
16 
     | 
    
         
             
                    @options[:type] ||= "sum"
         
     | 
| 
      
 17 
     | 
    
         
            +
                    @options[:limit] ||= -1
         
     | 
| 
       15 
18 
     | 
    
         
             
                    @sort = false
         
     | 
| 
       16 
19 
     | 
    
         
             
                    @rows ||=
         
     | 
| 
       17 
20 
     | 
    
         
             
                    begin
         
     | 
| 
         @@ -28,17 +31,18 @@ module Sunspot 
     | 
|
| 
       28 
31 
     | 
    
         
             
                      rows = []
         
     | 
| 
       29 
32 
     | 
    
         | 
| 
       30 
33 
     | 
    
         
             
                      data.collect do |stat, value|
         
     | 
| 
       31 
     | 
    
         
            -
                        rows << StatRow.new(stat, value[@options[:type]], self)
         
     | 
| 
      
 34 
     | 
    
         
            +
                        rows << StatRow.new(stat, value[@options[:type]], value, self)
         
     | 
| 
       32 
35 
     | 
    
         
             
                      end
         
     | 
| 
       33 
36 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                      if @options[:sort] == : 
     | 
| 
       35 
     | 
    
         
            -
                        rows.sort! { |lrow, rrow| rrow. 
     | 
| 
      
 37 
     | 
    
         
            +
                      if @options[:sort] == :count
         
     | 
| 
      
 38 
     | 
    
         
            +
                        rows.sort! { |lrow, rrow| rrow.value <=> lrow.value }
         
     | 
| 
       36 
39 
     | 
    
         
             
                      else
         
     | 
| 
       37 
40 
     | 
    
         
             
                        rows.sort! { |lrow, rrow| lrow.stat_field <=> rrow.stat_field }
         
     | 
| 
       38 
41 
     | 
    
         
             
                      end if @sort
         
     | 
| 
       39 
     | 
    
         
            -
                      rows
         
     | 
| 
      
 42 
     | 
    
         
            +
                      return rows.empty? ? [] : rows[0..@options[:limit]]
         
     | 
| 
       40 
43 
     | 
    
         
             
                    rescue Exception => e
         
     | 
| 
       41 
44 
     | 
    
         
             
                      puts "Error: #{e}"
         
     | 
| 
      
 45 
     | 
    
         
            +
                      return []
         
     | 
| 
       42 
46 
     | 
    
         
             
                    end
         
     | 
| 
       43 
47 
     | 
    
         
             
                  end
         
     | 
| 
       44 
48 
     | 
    
         
             
                end
         
     | 
    
        data/lib/search/stat_row.rb
    CHANGED
    
    | 
         @@ -1,11 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Sunspot
         
     | 
| 
       2 
2 
     | 
    
         
             
              module Search
         
     | 
| 
       3 
3 
     | 
    
         
             
                class StatRow
         
     | 
| 
       4 
     | 
    
         
            -
                  attr_reader :stat_field, :value
         
     | 
| 
      
 4 
     | 
    
         
            +
                  attr_reader :stat_field, :value, :all_values
         
     | 
| 
       5 
5 
     | 
    
         
             
                  attr_writer :instance #:nodoc:
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
                  def initialize(stat_field, value, stat) #:nodoc:
         
     | 
| 
       8 
     | 
    
         
            -
                    @stat_field, @value, @stat = stat_field, value, stat
         
     | 
| 
      
 7 
     | 
    
         
            +
                  def initialize(stat_field, value, all_values, stat) #:nodoc:
         
     | 
| 
      
 8 
     | 
    
         
            +
                    @stat_field, @value, @all_values, @stat = stat_field, value, all_values, stat
         
     | 
| 
       9 
9 
     | 
    
         
             
                  end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
                  # 
         
     | 
| 
         @@ -21,7 +21,7 @@ module Sunspot 
     | 
|
| 
       21 
21 
     | 
    
         
             
                  end
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
                  def inspect
         
     | 
| 
       24 
     | 
    
         
            -
                    "<Sunspot::Search::StatRow:#{stat_field.inspect} (#{value})>"
         
     | 
| 
      
 24 
     | 
    
         
            +
                    "<Sunspot::Search::StatRow:#{stat_field.inspect} (#{value} - #{all_values})>"
         
     | 
| 
       25 
25 
     | 
    
         
             
                  end
         
     | 
| 
       26 
26 
     | 
    
         
             
                end
         
     | 
| 
       27 
27 
     | 
    
         
             
              end
         
     | 
    
        data/lib/search/stat_search.rb
    CHANGED
    
    | 
         @@ -39,7 +39,18 @@ module Sunspot 
     | 
|
| 
       39 
39 
     | 
    
         
             
                  end
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
                  def stat_response #:nodoc:
         
     | 
| 
       42 
     | 
    
         
            -
                    @solr_result['stats']
         
     | 
| 
      
 42 
     | 
    
         
            +
                    @solr_result['stats']["stats_fields"].each_pair do |k, value|
         
     | 
| 
      
 43 
     | 
    
         
            +
                      if value && value.key?("facets")
         
     | 
| 
      
 44 
     | 
    
         
            +
                        value["facets"].each_pair do |k1, value1|
         
     | 
| 
      
 45 
     | 
    
         
            +
                          value1.each_pair do |k2, value2|
         
     | 
| 
      
 46 
     | 
    
         
            +
                            if @solr_result['stats']['stats_fields'][k]['facets'][k1][k2]['mean'].to_s == 'NaN'
         
     | 
| 
      
 47 
     | 
    
         
            +
                              @solr_result['stats']['stats_fields'][k]['facets'][k1][k2]['mean'] = 0.0
         
     | 
| 
      
 48 
     | 
    
         
            +
                            end
         
     | 
| 
      
 49 
     | 
    
         
            +
                          end
         
     | 
| 
      
 50 
     | 
    
         
            +
                        end
         
     | 
| 
      
 51 
     | 
    
         
            +
                      end
         
     | 
| 
      
 52 
     | 
    
         
            +
                    end
         
     | 
| 
      
 53 
     | 
    
         
            +
                    @solr_result['stats']||[]
         
     | 
| 
       43 
54 
     | 
    
         
             
                  end
         
     | 
| 
       44 
55 
     | 
    
         | 
| 
       45 
56 
     | 
    
         
             
                  def add_field_stat(field, options = {}) #:nodoc:
         
     | 
    
        data/sunspot_stats.gemspec
    CHANGED
    
    | 
         @@ -18,7 +18,7 @@ Gem::Specification.new do |gem| 
     | 
|
| 
       18 
18 
     | 
    
         
             
              gem.require_paths = ["lib"]
         
     | 
| 
       19 
19 
     | 
    
         
             
              gem.version       = SunspotStats::VERSION
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
              gem.add_dependency "sunspot", "~> 2.0.0 
     | 
| 
      
 21 
     | 
    
         
            +
              gem.add_dependency "sunspot", "~> 2.0.0"
         
     | 
| 
       22 
22 
     | 
    
         
             
              gem.add_development_dependency "rspec"
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
              gem.rdoc_options << '--webcvs=http://github.com/giovannelli/sunspot_stats/tree/master/%s' <<
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,65 +1,59 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            --- !ruby/object:Gem::Specification 
     | 
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: sunspot_stats
         
     | 
| 
       3 
     | 
    
         
            -
            version: !ruby/object:Gem::Version 
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.6
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
     | 
    
         
            -
              segments: 
         
     | 
| 
       7 
     | 
    
         
            -
              - 0
         
     | 
| 
       8 
     | 
    
         
            -
              - 0
         
     | 
| 
       9 
     | 
    
         
            -
              - 5
         
     | 
| 
       10 
     | 
    
         
            -
              version: 0.0.5
         
     | 
| 
       11 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       12 
     | 
    
         
            -
            authors: 
     | 
| 
      
 7 
     | 
    
         
            +
            authors:
         
     | 
| 
       13 
8 
     | 
    
         
             
            - duccio giovannelli
         
     | 
| 
       14 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       15 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       16 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
            dependencies: 
         
     | 
| 
       21 
     | 
    
         
            -
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2013-10-21 00:00:00.000000000 Z
         
     | 
| 
      
 13 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 14 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
       22 
15 
     | 
    
         
             
              name: sunspot
         
     | 
| 
       23 
     | 
    
         
            -
               
     | 
| 
       24 
     | 
    
         
            -
              requirement: &id001 !ruby/object:Gem::Requirement 
         
     | 
| 
      
 16 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       25 
17 
     | 
    
         
             
                none: false
         
     | 
| 
       26 
     | 
    
         
            -
                requirements: 
     | 
| 
      
 18 
     | 
    
         
            +
                requirements:
         
     | 
| 
       27 
19 
     | 
    
         
             
                - - ~>
         
     | 
| 
       28 
     | 
    
         
            -
                  - !ruby/object:Gem::Version 
     | 
| 
       29 
     | 
    
         
            -
                     
     | 
| 
       30 
     | 
    
         
            -
                    segments: 
         
     | 
| 
       31 
     | 
    
         
            -
                    - 2
         
     | 
| 
       32 
     | 
    
         
            -
                    - 0
         
     | 
| 
       33 
     | 
    
         
            -
                    - 0
         
     | 
| 
       34 
     | 
    
         
            -
                    - pre
         
     | 
| 
       35 
     | 
    
         
            -
                    - 120417
         
     | 
| 
       36 
     | 
    
         
            -
                    version: 2.0.0.pre.120417
         
     | 
| 
      
 20 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 21 
     | 
    
         
            +
                    version: 2.0.0
         
     | 
| 
       37 
22 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       38 
     | 
    
         
            -
              version_requirements: *id001
         
     | 
| 
       39 
     | 
    
         
            -
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       40 
     | 
    
         
            -
              name: rspec
         
     | 
| 
       41 
23 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       42 
     | 
    
         
            -
               
     | 
| 
      
 24 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       43 
25 
     | 
    
         
             
                none: false
         
     | 
| 
       44 
     | 
    
         
            -
                requirements: 
     | 
| 
       45 
     | 
    
         
            -
                - -  
     | 
| 
       46 
     | 
    
         
            -
                  - !ruby/object:Gem::Version 
     | 
| 
       47 
     | 
    
         
            -
                     
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
      
 26 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 27 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 28 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 29 
     | 
    
         
            +
                    version: 2.0.0
         
     | 
| 
      
 30 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 31 
     | 
    
         
            +
              name: rspec
         
     | 
| 
      
 32 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 33 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 34 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 35 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 36 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 37 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
       51 
38 
     | 
    
         
             
              type: :development
         
     | 
| 
       52 
     | 
    
         
            -
               
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
      
 39 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 40 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 41 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 42 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 43 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 44 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 45 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 46 
     | 
    
         
            +
            description: ! "      Sunspot is a library providing a powerful, all-ruby API for
         
     | 
| 
      
 47 
     | 
    
         
            +
              the Solr search engine. This gem extend sunspot adding the \n      statsComponent
         
     | 
| 
      
 48 
     | 
    
         
            +
              feature, which returns simple statistics for indexed numeric fields within the DocSet.
         
     | 
| 
      
 49 
     | 
    
         
            +
              Usually Suspot use the dismax\n      for searches, here we extend to edismax to
         
     | 
| 
      
 50 
     | 
    
         
            +
              manage also boolean logic searches.\n"
         
     | 
| 
      
 51 
     | 
    
         
            +
            email:
         
     | 
| 
       55 
52 
     | 
    
         
             
            - giovannelli@extendi.it
         
     | 
| 
       56 
53 
     | 
    
         
             
            executables: []
         
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
54 
     | 
    
         
             
            extensions: []
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
55 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
            files: 
         
     | 
| 
      
 56 
     | 
    
         
            +
            files:
         
     | 
| 
       63 
57 
     | 
    
         
             
            - .gitignore
         
     | 
| 
       64 
58 
     | 
    
         
             
            - Gemfile
         
     | 
| 
       65 
59 
     | 
    
         
             
            - LICENSE
         
     | 
| 
         @@ -92,45 +86,36 @@ files: 
     | 
|
| 
       92 
86 
     | 
    
         
             
            - spec/mocks/super_class.rb
         
     | 
| 
       93 
87 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       94 
88 
     | 
    
         
             
            - sunspot_stats.gemspec
         
     | 
| 
       95 
     | 
    
         
            -
            has_rdoc: true
         
     | 
| 
       96 
89 
     | 
    
         
             
            homepage: https://github.com/giovannelli/sunspot_stats
         
     | 
| 
       97 
90 
     | 
    
         
             
            licenses: []
         
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
91 
     | 
    
         
             
            post_install_message: 
         
     | 
| 
       100 
     | 
    
         
            -
            rdoc_options: 
     | 
| 
      
 92 
     | 
    
         
            +
            rdoc_options:
         
     | 
| 
       101 
93 
     | 
    
         
             
            - --webcvs=http://github.com/giovannelli/sunspot_stats/tree/master/%s
         
     | 
| 
       102 
94 
     | 
    
         
             
            - --title
         
     | 
| 
       103 
95 
     | 
    
         
             
            - Sunspot Stat - StatsComponent for sunspot - API Documentation
         
     | 
| 
       104 
96 
     | 
    
         
             
            - --main
         
     | 
| 
       105 
97 
     | 
    
         
             
            - README.rdoc
         
     | 
| 
       106 
     | 
    
         
            -
            require_paths: 
     | 
| 
      
 98 
     | 
    
         
            +
            require_paths:
         
     | 
| 
       107 
99 
     | 
    
         
             
            - lib
         
     | 
| 
       108 
     | 
    
         
            -
            required_ruby_version: !ruby/object:Gem::Requirement 
     | 
| 
      
 100 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
       109 
101 
     | 
    
         
             
              none: false
         
     | 
| 
       110 
     | 
    
         
            -
              requirements: 
     | 
| 
       111 
     | 
    
         
            -
              - -  
     | 
| 
       112 
     | 
    
         
            -
                - !ruby/object:Gem::Version 
     | 
| 
       113 
     | 
    
         
            -
                   
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
       115 
     | 
    
         
            -
                  - 0
         
     | 
| 
       116 
     | 
    
         
            -
                  version: "0"
         
     | 
| 
       117 
     | 
    
         
            -
            required_rubygems_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 102 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 103 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 104 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 105 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 106 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       118 
107 
     | 
    
         
             
              none: false
         
     | 
| 
       119 
     | 
    
         
            -
              requirements: 
     | 
| 
       120 
     | 
    
         
            -
              - -  
     | 
| 
       121 
     | 
    
         
            -
                - !ruby/object:Gem::Version 
     | 
| 
       122 
     | 
    
         
            -
                   
     | 
| 
       123 
     | 
    
         
            -
                  segments: 
         
     | 
| 
       124 
     | 
    
         
            -
                  - 0
         
     | 
| 
       125 
     | 
    
         
            -
                  version: "0"
         
     | 
| 
      
 108 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 109 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 110 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 111 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
       126 
112 
     | 
    
         
             
            requirements: []
         
     | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
113 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       129 
     | 
    
         
            -
            rubygems_version: 1. 
     | 
| 
      
 114 
     | 
    
         
            +
            rubygems_version: 1.8.23
         
     | 
| 
       130 
115 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       131 
116 
     | 
    
         
             
            specification_version: 3
         
     | 
| 
       132 
117 
     | 
    
         
             
            summary: Added the statsComponent to sunspot
         
     | 
| 
       133 
     | 
    
         
            -
            test_files: 
     | 
| 
      
 118 
     | 
    
         
            +
            test_files:
         
     | 
| 
       134 
119 
     | 
    
         
             
            - spec/api/query/spec_helper.rb
         
     | 
| 
       135 
120 
     | 
    
         
             
            - spec/api/query/stats_spec.rb
         
     | 
| 
       136 
121 
     | 
    
         
             
            - spec/api/search/spec_helper.rb
         
     | 
| 
         @@ -149,3 +134,4 @@ test_files: 
     | 
|
| 
       149 
134 
     | 
    
         
             
            - spec/mocks/mock_record.rb
         
     | 
| 
       150 
135 
     | 
    
         
             
            - spec/mocks/super_class.rb
         
     | 
| 
       151 
136 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
      
 137 
     | 
    
         
            +
            has_rdoc: 
         
     |