-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move JS code out of -defines and into .js files
greatly improves readability JS files are read during application startup, and storing in the application environment under properties named after their filenames
- Loading branch information
Showing
7 changed files
with
115 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// This function is used as the map phase implementation for | ||
// searching article text | ||
// Each element in the result should be a structure of | ||
// { | ||
// key: (string), // key of the Riak object for the article | ||
// ranges: [ (string) ], // list of matching phrases | ||
// } | ||
function(v, d) { | ||
// always want the key in the result | ||
var result = {key: v.key}; | ||
|
||
// if the object was found, and we have word position info | ||
if (v.values && v.values[0] && d.p) { | ||
// sort positions | ||
d.p.sort(); | ||
|
||
// create a list of start/end position pairs that attempt | ||
// to group "close" positions (within 5 words) together | ||
result.ranges=[{start: d.p[0], end: d.p[0]}]; | ||
for (var i = 1; i < d.p.length; i++) { | ||
if (result.ranges[result.ranges.length-1].end-d.p[i] < 5) | ||
result.ranges[result.ranges.length-1].end = d.p[i]; | ||
else | ||
result.ranges[result.ranges.length] = | ||
{start: d.p[i], end: d.p[i]}; | ||
} | ||
|
||
// extract the phrases from the text | ||
var text = JSON.parse(v.values[0].data).text; | ||
var words = text.match(/[a-z0-9\u80-\uff]*/g).filter( | ||
function(s) { return s != ""; }).length | ||
|
||
for (var i = 0; i < result.ranges.length; i++) { | ||
var s = result.ranges[i].start < 5 ? | ||
0 : result.ranges[i].start-5; | ||
var e = result.ranges[i].end+5 > words ? | ||
words : result.ranges[i].end+5; | ||
|
||
// regexp is basically "match START words, then grab everything | ||
// until WORDS-END words from the end" | ||
var match = (new RegExp( | ||
"(?:[a-z0-9\u80-\uff]+[^a-z0-9\u80-\uff]+){"+s+"}"+ | ||
"(.*)[^a-z0-9\u80-\uff]"+ | ||
"(?:[a-z0-9\u80-\uff]+[^a-z0-9\u80-\uff]+){"+(words-e)+"}")) | ||
.exec(text); | ||
result.ranges[i] = match[1]; | ||
} | ||
} | ||
|
||
return [result]; | ||
} |
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,24 @@ | ||
// This function is used as the map phase implementation for | ||
// extracting summary data from archives for history production | ||
// Each element in the result should be a structure of | ||
// { | ||
// version: (string), // the hash version of the revision | ||
// timestamp: (integer), // the time of the revision | ||
// message: (string), // the commit message | ||
// editor: (string), // the username of the editor | ||
// } | ||
function(v) { | ||
var json = JSON.parse(v.values[0].data); | ||
var summary = { | ||
version: json.version, | ||
timestamp: json.timestamp, | ||
message: json.message, | ||
}; | ||
var links = v.values[0].metadata.Links; | ||
for(var i in links) { | ||
if (links[i][2] == "editor") { | ||
summary.editor = links[i][1]; | ||
} | ||
} | ||
return [summary]; | ||
} |
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,7 @@ | ||
// This function is used as the reduce phase implementation for | ||
// ordering/paging archives in the history view (TODO) | ||
function(v) { | ||
return v.sort( | ||
function(a,b) { return b[2]-a[2]; } | ||
); | ||
} |
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
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