Overview
TODO
Format
TODO |
Legacy documentation:
- TODO
TODO
Description
Legacy documentation:
- TODO
TODO
Examples
TODOThis method provides source builders who need to add javascript to the enrichment process with a single global set of variables and functions that can be used in the individual "scriptlets" other elements provide. The scripts provided (and same for the inputs) are executed once per source per harvest cycle.
For general information about using javascript with IKANOWS, see Using Javascript.
Table of Contents |
---|
Format
Code Block | ||
---|---|---|
| ||
{
"display": string,
"globals": {
"imports": [ string ],// An optional list of URLs that get imported before the scripts below are run
"scripts": [ string ], // A list of (java)script code blocks that are evaluated in order (normally only need to specify one)
"scriptlang":string, // Currently only "javascript" is supported
}
} |
Description
Globals is used to set functions that the other elements that use javascript can access.
Field | Description | |
---|---|---|
imports | An optional list of URLs that get imported before the scripts below are run | |
scripts | A list of (java)script code blocks that are evaluated in order (normally only need to specify one) | |
scriptlang | Currently only "javascript" is supported |
Examples
In the example below globals
is used to declare some javascript functions. They are accessed by the docMetadata
elements below to set some metadata values for the documents.
Code Block |
---|
{
"globals": {
"scripts": [
"function getAddressVal( addressStr, number) { try { var addressArray = addressStr.split(/ *, */); if (addressArray != null && addressArray.length > 0) { if (addressArray[number].toLowerCase()=='ny') { return 'new york'; } else if (addressArray[number].toLowerCase()=='long island' || addressArray[number].toLowerCase()=='li') { return 'medford'; } else { return addressArray[number]; } } else { return ''; } } catch (err) { return ''; } } function getRegion( code ) { if (code.toLowerCase()=='ny') {return 'New York';} else if (code.toLowerCase()=='nj') {return 'New Jersey';} else if (code.toLowerCase()=='ct') {return 'Connecticut';} else if (code.toLowerCase()=='md') {return 'Maryland';} else if (code.toLowerCase()=='va') {return 'Virginia';} else if (code.toLowerCase()=='pa') {return 'Pennsylvania';} else if (code.toLowerCase()=='nj') {return 'New Jersey';} else {return 'New York';} }"
]
}
},
{
"docMetadata": {
"title": "$metadata.json.body",
"description": "$metadata.json.body",
"fullText": "$metadata.json.body",
"publishedDate": "$SCRIPT(return _doc.metadata.json[0].postedTime.replace(/.[0-9]{3}Z/,'Z');)",
"geotag": {
"lat": "$SCRIPT( try {return _doc.metadata.json[0].geo.coordinates[0];} catch (err) {return '';})",
"lon": "$SCRIPT( try {return _doc.metadata.json[0].geo.coordinates[1];} catch (err) {return '';})"
}
} |
Panel |
---|
Footnotes: Legacy documentation, replaces the following:
Legacy documentation:
|