Permalink
Browse files

added twitter id as the doc id, and updated to use exists

  • Loading branch information...
1 parent 582a064 commit 088ab796b2408bf0d8ba1e90d3a405e39b53afe6 @scalabl3 committed Dec 15, 2012
View
BIN .DS_Store
Binary file not shown.
View
Binary file not shown.
@@ -136,7 +136,7 @@ PLATFORMS
DEPENDENCIES
coffee-rails (~> 3.2.1)
- couchbase (>= 1.2.0.z.beta3)
+ couchbase (>= 1.2.0)
couchbase-model
grackle
html2haml
Binary file not shown.
@@ -19,9 +19,9 @@ def self.get_latest
created = DateTime.parse(t.created_at)
tweet_id = t.id_str.to_i
# create the tweet if it doesn't already exist
- #unless Tweet.exists?(["tweet_id=?", tweet_id])
- Tweets.create({:doctype => "tweet", :content => t.text, :tweet_id => tweet_id, :created => created.getutc.to_i })
- #end
+ unless Tweets.exists?("tw::#{tweet_id}")
+ Tweets.create({:id => "tw::#{tweet_id}", :doctype => "tweet", :content => t.text, :tweet_id => tweet_id, :created => created.getutc.to_i })
+ end
end
end
@@ -37,5 +37,3 @@ def self.client
end
end
-
-Tweets.ensure_design_document!
@@ -1,43 +1,6 @@
-// The map function is the most critical part of any view as it provides the
-// logical mapping between the input fields of the individual objects stored
-// within Couchbase to the information output when the view is accessed.
-//
-// Read more about how to write map functions at:
-// http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-writing-map.html
-
function(doc, meta) {
// list tweets by id
if (doc.doctype == "tweet" && meta.type == "json") {
emit(doc.tweet_id, doc.content);
}
}
-
-// You can also check out following examples
-//
-// The simplest example of a map function:
-//
-// function(doc, meta) {
-// emit(meta.id, doc);
-// }
-//
-// Slightly more complex example of a function that defines a view on values
-// computed from customer documents:
-//
-// function(doc, meta) {
-// if (doc.type == "customer") {
-// emit(meta.id, {last_name: doc.last_name, first_name: doc.first_name});
-// }
-// }
-//
-// To be able to filter or sort the view by some document property, you
-// would use that property for the key. For example, the following view
-// would allow you to lookup customer documents by the last_name or
-// first_name fields (your keys could be compound, e.g. arrays):
-//
-// function(doc, meta) {
-// if (doc.type == "customer") {
-// emit(doc.last_name, {first_name: doc.first_name});
-// emit(doc.first_name, {last_name: doc.last_name});
-// }
-// }
-//
@@ -1,61 +0,0 @@
-// If a view has a reduce function, it is used to produce aggregate results
-// for that view. A reduce function is passed a set of intermediate values
-// and combines them to a single value. Reduce functions must accept, as
-// input, results emitted by its corresponding map function as well as
-// results returned by the reduce function itself. The latter case is
-// referred to as a rereduce.
-//
-// function (key, values, rereduce) {
-// return sum(values);
-// }
-//
-// Reduce functions must handle two cases:
-//
-// 1. When rereduce is false:
-//
-// reduce([ [key1,id1], [key2,id2], [key3,id3] ], [value1,value2,value3], false)
-//
-// * key will be an array whose elements are arrays of the form [key,id],
-// where key is a key emitted by the map function and id is that of the
-// document from which the key was generated.
-// * values will be an array of the values emitted for the respective
-// elements in keys
-//
-// 2. When rereduce is true:
-//
-// reduce(null, [intermediate1,intermediate2,intermediate3], true)
-//
-// * key will be null
-// * values will be an array of values returned by previous calls to the
-// reduce function
-//
-// Reduce functions should return a single value, suitable for both the
-// value field of the final view and as a member of the values array passed
-// to the reduce function.
-//
-// NOTE: If this file is empty, reduce part will be skipped in design document
-//
-// There is number of built-in functions, which could be used instead of
-// javascript implementation of reduce function.
-//
-// The _count function provides a simple count of the input rows from the
-// map function, using the keys and group level to provide to provide a
-// count of the correlated items. The values generated during the map()
-// stage are ignored.
-//
-// _count
-//
-// The built-in _sum function collates the output from the map function
-// call. The information can either be a single number or an array of numbers.
-//
-// _sum
-//
-// The _stats built-in produces statistical calculations for the input data.
-// Like the _sum call the source information should be a number. The
-// generated statistics include the sum, count, minimum (min), maximum (max)
-// and sum squared (sumsqr) of the input rows.
-//
-// _stats
-//
-// Read more about how to write reduce functions at:
-// http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-writing-reduce.html
@@ -1,46 +1,9 @@
-// The map function is the most critical part of any view as it provides the
-// logical mapping between the input fields of the individual objects stored
-// within Couchbase to the information output when the view is accessed.
-//
-// Read more about how to write map functions at:
-// http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-writing-map.html
-
function(doc, meta) {
+ // if its a tweet document, sort by created timestamp (epoch)
if (doc.doctype == "tweet" && meta.type == "json") {
var dt = new Date(0);
dt.setUTCSeconds(doc.created);
da = dateToArray(dt);
emit(da, doc.content);
- }
-
-}
-
-// You can also check out following examples
-//
-// The simplest example of a map function:
-//
-// function(doc, meta) {
-// emit(meta.id, doc);
-// }
-//
-// Slightly more complex example of a function that defines a view on values
-// computed from customer documents:
-//
-// function(doc, meta) {
-// if (doc.type == "customer") {
-// emit(meta.id, {last_name: doc.last_name, first_name: doc.first_name});
-// }
-// }
-//
-// To be able to filter or sort the view by some document property, you
-// would use that property for the key. For example, the following view
-// would allow you to lookup customer documents by the last_name or
-// first_name fields (your keys could be compound, e.g. arrays):
-//
-// function(doc, meta) {
-// if (doc.type == "customer") {
-// emit(doc.last_name, {first_name: doc.first_name});
-// emit(doc.first_name, {last_name: doc.last_name});
-// }
-// }
-//
+ }
+}
@@ -1,61 +0,0 @@
-// If a view has a reduce function, it is used to produce aggregate results
-// for that view. A reduce function is passed a set of intermediate values
-// and combines them to a single value. Reduce functions must accept, as
-// input, results emitted by its corresponding map function as well as
-// results returned by the reduce function itself. The latter case is
-// referred to as a rereduce.
-//
-// function (key, values, rereduce) {
-// return sum(values);
-// }
-//
-// Reduce functions must handle two cases:
-//
-// 1. When rereduce is false:
-//
-// reduce([ [key1,id1], [key2,id2], [key3,id3] ], [value1,value2,value3], false)
-//
-// * key will be an array whose elements are arrays of the form [key,id],
-// where key is a key emitted by the map function and id is that of the
-// document from which the key was generated.
-// * values will be an array of the values emitted for the respective
-// elements in keys
-//
-// 2. When rereduce is true:
-//
-// reduce(null, [intermediate1,intermediate2,intermediate3], true)
-//
-// * key will be null
-// * values will be an array of values returned by previous calls to the
-// reduce function
-//
-// Reduce functions should return a single value, suitable for both the
-// value field of the final view and as a member of the values array passed
-// to the reduce function.
-//
-// NOTE: If this file is empty, reduce part will be skipped in design document
-//
-// There is number of built-in functions, which could be used instead of
-// javascript implementation of reduce function.
-//
-// The _count function provides a simple count of the input rows from the
-// map function, using the keys and group level to provide to provide a
-// count of the correlated items. The values generated during the map()
-// stage are ignored.
-//
-// _count
-//
-// The built-in _sum function collates the output from the map function
-// call. The information can either be a single number or an array of numbers.
-//
-// _sum
-//
-// The _stats built-in produces statistical calculations for the input data.
-// Like the _sum call the source information should be a number. The
-// generated statistics include the sum, count, minimum (min), maximum (max)
-// and sum squared (sumsqr) of the input rows.
-//
-// _stats
-//
-// Read more about how to write reduce functions at:
-// http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-writing-reduce.html

0 comments on commit 088ab79

Please sign in to comment.