Sha256: bc0e464f18c22ea528b1cef0168adc64fb97e2bf1cb33df9ecfc36010df39c07

Contents?: true

Size: 1.32 KB

Versions: 143

Compression:

Stored size: 1.32 KB

Contents

require 'rubygems'
require 'couchrest'

couch = CouchRest.new("http://127.0.0.1:5984")
db = couch.database('word-count-example')

puts "Now that we've parsed all those books into CouchDB, the queries we can run are incredibly flexible."
puts "\nThe simplest query we can run is the total word count for all words in all documents:"
puts "this will take a few minutes the first time. if it times out, just rerun this script in a few few minutes."
puts db.view('word_count/words').inspect

puts "\nWe can also narrow the query down to just one word, across all documents. Here is the count for 'flight' in all three books:"

word = 'flight'
params = {
  :startkey => [word], 
  :endkey => [word,{}]
  }

puts db.view('word_count/words',params).inspect

puts "\nWe scope the query using startkey and endkey params to take advantage of CouchDB's collation ordering. Here are the params for the last query:"
puts params.inspect

puts "\nWe can also count words on a per-title basis."

title = 'da-vinci'
params = {
  :key => [word, title]
  }
  
puts db.view('word_count/words',params).inspect


puts "\nHere are the params for 'flight' in the da-vinci book:"
puts params.inspect
puts
puts 'The url looks like this:'
puts 'http://127.0.0.1:5984/word-count-example/_view/word_count/count?key=["flight","da-vinci"]'
puts "\nTry dropping that in your browser..."

Version data entries

143 entries across 143 versions & 26 rubygems

Version Path
couchrest-2.0.0.rc2 examples/word_count/word_count_query.rb
couchrest-2.0.0.rc1 examples/word_count/word_count_query.rb
couchrest-2.0.0.beta2 examples/word_count/word_count_query.rb
couchrest-2.0.0.beta1 examples/word_count/word_count_query.rb
couchrest-1.2.1 examples/word_count/word_count_query.rb
dpla-couchrest-1.2.1.pre.dpla examples/word_count/word_count_query.rb
brianmario-couchrest-0.23 examples/word_count/word_count_query.rb
derfred-couchrest-0.12.6.3 examples/word_count/word_count_query.rb
derfred-couchrest-0.12.6 examples/word_count/word_count_query.rb
gbuesing-couchrest-0.23 examples/word_count/word_count_query.rb
glasner-couchrest-0.2.2 examples/word_count/word_count_query.rb
gohanlonllc-couchrest-0.2.3.1 examples/word_count/word_count_query.rb
halfninja-couchrest-0.23.2 examples/word_count/word_count_query.rb
halfninja-couchrest-0.23.3 examples/word_count/word_count_query.rb
jchris-couchrest-0.12.4 examples/word_count/word_count_query.rb
jchris-couchrest-0.12.5 examples/word_count/word_count_query.rb
jchris-couchrest-0.12.6 examples/word_count/word_count_query.rb
jchris-couchrest-0.16 examples/word_count/word_count_query.rb
jchris-couchrest-0.17.0 examples/word_count/word_count_query.rb
jchris-couchrest-0.2.1 examples/word_count/word_count_query.rb