DelSolr – Simplifying Solr Facets in Ruby

Get Version

0.0.2

What

delsolr is a light weight ruby wrapper for Solr. Its goal is to
preserve all the power of the Solr webservice while keeping the interface as simple and ruby-esque as possible.

Installing

sudo gem install delsolr

Demonstration of usage

See the rdoc for full documentation. Also, check out ruby-on-the-interrails for updates, news, tricks, etc…


c = DelSolr::Client.new(:server => 'solr1', :port => 8983)
rsp = c.query('dismax',
               :query => 'mp3 player',
               :filters => {:cost => (50..100)},
               :facets => [{:field => 'brand', :limit => 10},
                           {:query => {:onsale => true, :brand => 'Apple'},
                            :name => 'cheap_apple'}])

# output total matches
puts rsp.total

# output each id with score
rsp.docs.each { |doc| puts "#{doc[:id]} - #{doc[:score]}" }

# output each value for a facet
rsp.facet_field_values('brand').each do |brand|
  puts "#{brand}: #{rsp.facet_field_count('brand', brand}"
end

# output a query facet
puts "Cheap Apple stuff: #{rsp.facet_query_count_by_name('cheap_apple')}"

# adding things
doc = DelSolr::Document.new
doc.add_field('id', 'ABC-123')
doc.add_field('name', '8 Gig Shuffle')
doc.add_field('description', 'A crazy-tiny MP3 player')
c.update!(doc) # posts new document to solr
c.commit! # posts a commit to solr

rsp = c.query('dismax', :query => 'shuffle mp3 player')
puts rsp.ids[0]

Forum

http://groups.google.com/group/delsolr

How to submit patches

You can fetch the source from github: http://github.com/avvo/delsolr/tree/master

Or you can submit diffs via the google group and they may or may not make it in.

How to report bugs

Please use the tracker on rubyforge

Build and test instructions

cd delsolr
rake test
rake install_gem

License

This code is free to use under the terms of the MIT license.

Contact

Comments are welcome. Send an email to Ben VandenBos email via the google group

ruby-on-the-interrails
find a lawyer
Theme extended from Paul Battley