This repository has been archived by the owner on May 13, 2022. It is now read-only.
forked from LearningRegistry/LearningRegistry
/
map.js
executable file
·79 lines (63 loc) · 2.27 KB
/
map.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
function(doc) {
if (doc.doc_type != "resource_data" || !doc.node_timestamp) return;
//only emitting related as a single key so we don't kill this view
if(doc.resource_data && doc.resource_data.activity && doc.resource_data.activity.related) {
for each(var related in doc.resource_data.activity.related) {
if(related.id) {
emit({'related': related.id.toLowerCase() }, null);
}
}
}
var date_stamp = doc.node_timestamp;
date_stamp = date_stamp.substring(0,10);
var identities = new Array();
var arrayContains = function(testArray, testValue) {
for each(var val in testArray) {
if(val==testValue) return true;
}
return false;
}
//grab all the identities in identity or submitter/curator/owner/signer (depending on version)
if(doc.identity) {
if(doc.identity.submitter) identities.push(doc.identity.submitter.toLowerCase());
if(doc.identity.curator) identities.push(doc.identity.curator.toLowerCase());
if(doc.identity.owner) identities.push(doc.identity.owner.toLowerCase());
if(doc.identity.signer) identities.push(doc.identity.signer.toLowerCase());
}
if(doc.submitter) identities.push(doc.submitter.toLowerCase());
//build identities indices
for each(identity in identities) {
emit({'id':identity}, null);
}
//build date indices
emit({'date':date_stamp}, null);
for each(identity in identities) {
emit([{'date':date_stamp}, {'id':identity}], null);
}
//build
var emitaAllKeywordIndices = function(value) {
emit({'tag':value}, null);
for each(identity in identities) {
emit([{'id':identity}, {'tag':value}], null);
}
emit([{'date':date_stamp}, {'tag':value}], null);
for each(identity in identities) {
emit([{'date':date_stamp}, {'id':identity}, {'tag':value}], null);
}
}
var usedKeys = new Array();
for each(var key in doc.keys) {
var cleanKey = key.toLowerCase();
cleanKey = cleanKey.replace(/^\s+/, "");
cleanKey = cleanKey.replace(/\s+$/, "");
//var used = arrayContains(usedKeys, key);
if(!arrayContains(usedKeys, cleanKey)) {
emitaAllKeywordIndices(cleanKey);
usedKeys.push(cleanKey);
}
}
for each(var schema in doc.payload_schema) {
emitaAllKeywordIndices(schema.toLowerCase());
}
if(doc.resource_data_type) emitaAllKeywordIndices(doc.resource_data_type.toLowerCase());
}