Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added attributes, views and view reference in class
- Loading branch information
Showing
5 changed files
with
215 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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 (doc.doctype == "tweet" && meta.type == "json") { | ||
emit(doc.tweet_id, null); | ||
} | ||
} | ||
|
||
// 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}); | ||
// } | ||
// } | ||
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// 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 (doc.doctype == "tweet" && meta.type == "json") { | ||
var dt = new Date(0); | ||
dt.setUTCSeconds(doc.created); | ||
da = dateToArray(dt); | ||
emit(dt, 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}); | ||
// } | ||
// } | ||
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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 |