Sunspot is a Ruby library for expressive, powerful interaction with the Solr search engine. I use the latest version 2.0.0.pre.120417 but i need the statsComponent in order to get the sum on a given indexed field.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install sunspot_stats
The statComponent let you to have min, max, count, missing, sum, sumOfsquare, mean and stdev.
An usage example
Model.search do #Filters ... #Facets ... #Stats stat(:your_field, :facet => :your_facet_filed, :type => "min") ... end
:facet and :type are optional the default type is the "sum" (you can pass: min, max, count, missing, sum, sumOfsquare, mean, stdev as string)
Remember to stats on a non multi valued field and update to the solr3.6, because the solr3.5 has a bug with stats.
the Sunspot::SearchStatRow has the method stat_field and the value.
If you enable faceting on stats the stat_field is the facet and the value is the type defined.
Usually Suspot use the dismax for searches, here we extend to edismax to manage also boolean logic searches
a OR (b AND c) works.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Added some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request