word count example
This commit is contained in:
parent
92873935fc
commit
4639893303
|
@ -48,6 +48,6 @@ db.save({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
puts "The books have been stored in your CouchDB. To initiate the MapReduce process, visit http://localhost:5984/_utils/ in your browser and click 'word-count-example', then select view 'words' or 'count'. The process could take around an hour on an average MacBook."
|
puts "The books have been stored in your CouchDB. To initiate the MapReduce process, visit http://localhost:5984/_utils/ in your browser and click 'word-count-example', then select view 'words' or 'count'. The process could take about 15 minutes on an average MacBook."
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,12 @@ couch = CouchRest.new("http://localhost:5984")
|
||||||
db = couch.database('word-count-example')
|
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 "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 "\nThe simplest query we can run is the total word count for all words in all documents:"
|
||||||
|
|
||||||
puts db.view('word_count/count').inspect
|
puts db.view('word_count/count').inspect
|
||||||
|
|
||||||
puts "\nWe can also narrow the query down to just one word, across all documents. Here is the count for 'flight':"
|
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'
|
word = 'flight'
|
||||||
params = {
|
params = {
|
||||||
:startkey => [word],
|
:startkey => [word],
|
||||||
|
@ -21,11 +22,15 @@ puts "\nWe scope the query using startkey and endkey params to take advantage of
|
||||||
puts params.inspect
|
puts params.inspect
|
||||||
|
|
||||||
puts "\nWe can also count words on a per-title basis."
|
puts "\nWe can also count words on a per-title basis."
|
||||||
|
|
||||||
title = 'da-vinci'
|
title = 'da-vinci'
|
||||||
params = {
|
params = {
|
||||||
:key => [word, title]
|
:key => [word, title]
|
||||||
}
|
}
|
||||||
|
|
||||||
puts db.view('word_count/count',params).inspect
|
puts db.view('word_count/count',params).inspect
|
||||||
|
|
||||||
|
|
||||||
puts "\nHere are the params for 'flight' in the da-vinci book:"
|
puts "\nHere are the params for 'flight' in the da-vinci book:"
|
||||||
puts params.inspect
|
puts params.inspect
|
||||||
puts
|
puts
|
||||||
|
|
Loading…
Reference in a new issue