This repository has been archived by the owner on Nov 25, 2024. It is now read-only.
forked from ryanramage/garden
-
Notifications
You must be signed in to change notification settings - Fork 2
/
views.js
108 lines (90 loc) · 2.85 KB
/
views.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
exports.apps = {
map: function (doc) {
var meta = doc.couchapp || doc.kanso;
if (!/^_design\//.test(doc._id) && meta) {
emit([doc._id], meta);
}
}
};
exports.apps_by_category = {
map: function (doc) {
var meta = doc.couchapp || doc.kanso;
if (!/^_design\//.test(doc._id) && meta) {
var cfg = meta.config;
if (cfg.categories && cfg.categories.length) {
for (var i = 0; i < cfg.categories.length; i++) {
emit([cfg.categories[i]], meta);
}
}
else {
emit(['uncategorized'], meta);
}
emit('total', 1);
}
},
reduce: function (keys, values, rereduce) {
if (rereduce) {
return sum(values);
}
return values.length;
}
};
exports.apps_by_user = {
map: function (doc) {
var meta = doc.couchapp || doc.kanso;
if (!/^_design\//.test(doc._id) && meta) {
emit([meta.pushed_by], meta);
}
}
};
exports.hosting = {
map : function(doc) {
if (doc.type && doc.type === 'hosting') {
emit(doc.name, null);
}
}
}
exports.keyword_search = {
map : function(doc) {
var meta = doc.couchapp || doc.kanso;
if (!meta || !meta.config) return;
var Tokenizer = require('views/lib/tokenizer');
var _ = require('views/lib/underscore')._;
var filter_junk = function(tokens) {
var map = [];
for (i in tokens) {
var t = tokens[i];
t = t.toLowerCase();
// filter some junk
if ((t.length !== 1) && (t.indexOf('_') < 0)) {
map.push(t);
}
}
return map;
}
var tokenizer = new Tokenizer();
var config = meta.config;
var id_tokens = tokenizer.tokenize(config.name);
var id_map = filter_junk(id_tokens);
var desc_tokens = tokenizer.tokenize(config.description);
var desc_map = filter_junk(desc_tokens);
var long_description_tokens = tokenizer.tokenize(config.long_description);
var l_desc_map = filter_junk(long_description_tokens);
var keywords = _.union(id_map, desc_map, l_desc_map);
var icon = config.icons["96"];
var by = meta.pushed_by;
var title = config.display_name || config.name;
title = title.substr(0, 1).toUpperCase() + title.substr(1);
_.each(keywords, function(token){
emit(token, {
_id : doc._id,
name : config.name,
display_name : title,
description: config.description,
keywords : keywords,
icon_96 : icon,
by : by
});
});
}
}