Skip to content

Commit

Permalink
Upgrade 6.1.3
Browse files Browse the repository at this point in the history
support in memory history
  • Loading branch information
johtani committed Jan 17, 2018
1 parent de9c2bf commit f7e225f
Show file tree
Hide file tree
Showing 9 changed files with 496 additions and 335 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> UI for elasticsearch analyze API
This is for kibana 6.0.0_rc1.
This is for kibana 6.1.2.

Analyze text with Aalyzer
![Sample image](./sample_image.png)
Expand Down
7 changes: 0 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,29 @@ export default function (kibana) {
require: ['elasticsearch'],
name: 'analyze-api-ui-plugin',
uiExports: {

app: {
title: 'Analyze UI',
description: 'UI for elasticsearch analyze API',
main: 'plugins/analyze-api-ui-plugin/app'
},


translations: [
resolve(__dirname, './translations/es.json')
],


hacks: [
]

},

config(Joi) {
return Joi.object({
enabled: Joi.boolean().default(true),
}).default();
},


init(server, options) {
// Add server routes and initalize the plugin here
analyzeRoute(server);
}


});
};
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "analyze-api-ui-plugin",
"version": "6.0.0",
"version": "6.1.2",
"description": "UI for elasticsearch analyze API",
"main": "index.js",
"kibana": {
"version": "6.0.0-rc1",
"version": "6.1.2",
"templateVersion": "7.2.0"
},
"scripts": {
Expand All @@ -17,7 +17,9 @@
"gather-info": "node gather-info.js"
},
"dependencies": {
"boom": "2.8.0"
"boom": "2.8.0",
"joi": "6.10.1",
"lodash": "3.10.1"
},
"devDependencies": {
"@elastic/eslint-config-kibana": "^0.6.1",
Expand Down
314 changes: 314 additions & 0 deletions public/analyzeui_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,314 @@
import utils from "./utils";

export function analyzeApiUiPluginController($http, $scope, $timeout, chrome, Notifier) {
const notify = new Notifier();
$scope.services = ['analyzer', 'custom_analyzer', 'field', 'compare analyzers'];
$scope.currentTab = $scope.services[0];
$scope.title = 'Analyze Api Ui Plugin';
$scope.description = 'UI for elasticsearch analyze API';
$scope.showAllAttr = false;

// load formValues & currentTab from sessionStorage
utils.loadSavedState($scope);

let timer;
const saveDelay = 500;

function saveState() {
if (timer) {
timer = $timeout.cancel(timer);
}
timer = $timeout(utils.saveState, saveDelay, true, $scope);
}

$scope.$watch('formValues', saveState, true);
$scope.$watch('currentTab', saveState);

this.initializeError = () => {
$scope.detail = {};
$scope.show_result = false;
$scope.esrequest = {};
$scope.show_esrequest = false;
$scope.textError = null;
$scope.indexNameError = null;
$scope.analyzerError = null;
$scope.resultAnalyzers = [];
}

this.alwaysShowTokenProperties = [
"token",
"position"
];
this.hiddenTokenProperties = [
"bytes","pronunciation (en)", "reading (en)", "partOfSpeech (en)", "inflectionType (en)", "inflectionForm (en)"
];

// switch tab
this.changeTab = (tab) => {
$scope.currentTab = tab;
this.initializeError();
};

// add input of charfilter function
this.addCharfilter = ($index) => {
//TODO check not having '' in current charfilters
$scope.formValues.charfilters.push({'item': '', 'id': $scope.formValues.charfilters.length});
};
// remove input of charfilter function
this.removeCharfilter = ($index) => {
$scope.formValues.charfilters.splice($index, 1);
};

// add input of filter function
this.addFilter = ($index) => {
//TODO check not having '' in current filters
$scope.formValues.filters.push({'item': '', 'id': $scope.formValues.filters.length});
};
// remove input of charfilter function
this.removeFilter = ($index) => {
$scope.formValues.filters.splice($index, 1);
};

// add input of analyzer function
this.addAnalyzer = ($index) => {
//TODO check not having '' in current analyzers
$scope.formValues.analyzersForCompare.push({'item': '', 'id': $scope.formValues.charfilters.length});
};
// remove input of analyzer function
this.removeAnalyzer = ($index) => {
$scope.formValues.analyzersForCompare.splice($index, 1);
};

//
this.parseCustom = (target) => {
if (typeof target === 'string' && target.startsWith('{')) {
try {
var tmpJson = JSON.parse(target);
if (tmpJson !== null && typeof tmpJson === 'object') {
return tmpJson;
} else {
$scope.analyzerError = 'charfilter has wrong custom charfilter';
return -1;
}
} catch (e) {
$scope.analyzerError = e.message;
return -1;
}
} else {
return target;
}
};

// show short name
this.shortenName = (name) => {
if (name.indexOf('.') > 0) {
return name.substr(name.lastIndexOf('.')+1);
}
return name;
}

// count tokenstream length
this.countTokenSteamLength = (detail) => {
// FIXME tokens length is not fit if it has synonym token/compound token...
var tokenStreamLength = 0;

if (detail.tokenizer) {
tokenStreamLength = this.getLength(tokenStreamLength, detail.tokenizer.tokens);
} else if (detail.analyzer) {
tokenStreamLength = this.getLength(tokenStreamLength, detail.analyzer.tokens);
}
if (detail.tokenfilters) {
detail.tokenfilters.forEach( (filter) => {
tokenStreamLength = this.getLength(tokenStreamLength, filter.tokens);
});
}
$scope.tokenIndicesArray = [];
for (var i = 0; i < tokenStreamLength; i++) {
$scope.tokenIndicesArray.push(i);
}
};

// compare and swap tokenStreamLength
this.getLength = (current, tokenArray) => {
// FIXME check if there is synonyms or compound
var length = current;
if (tokenArray != null) {
// FIXME must consider the situation if positionIncrements != 1
if (tokenArray[tokenArray.length -1].position >= current) {
length = tokenArray[tokenArray.length -1].position + 1;
}
}
return length;
};

// for display
this.getTokenFromTokenstream = (index, target1, target2) => {
var target = target1;
if (target == null && target2 != null) {
target = target2;
}
$scope.currentLevelTokenList = [];
for (var token of target.tokens) {
if (token.position > index) {
break;
}
if (token.position == index) {
$scope.currentLevelTokenList.push(token);
}
}
return $scope.currentLevelTokenList.length > 0;
}

// filter token properties
this.filteredCurrentTokenInfo = (token) => {
if (token != null) {
var result = {};
Object.keys(token).forEach((key) => {
if (!this.hiddenTokenProperties.includes(key)) {
result[key] = token[key];
}
});
return result;
} else {
return null;
}
};

// switch show/hide properties
this.hideTokenProperty = (propertyName) => {
if (this.alwaysShowTokenProperties.includes(propertyName)) {
return true;
} else {
// TODO should we handle each attribute to show/hide?
return $scope.showAllAttr;
}
};

// Call analyze function
this.performAnalyze = () => {
// initialize
this.initializeError();

// FIXME validation logic, text is required
let param = {
text: $scope.formValues.text
};
if ($scope.formValues.text.trim().length == 0) {
$scope.textError = 'text should be not null!';
return;
}
if ($scope.formValues.indexName.length > 0)
param.indexName = $scope.formValues.indexName.trim();

if ($scope.currentTab == 'analyzer') {
if ($scope.formValues.analyzer.length > 0)
param.analyzer = $scope.formValues.analyzer.trim();
} else if ($scope.currentTab == 'field') {
if ($scope.formValues.field.trim().length == 0)
$scope.analyzerError = 'field is required. ';
if ($scope.formValues.indexName.trim().length == 0)
$scope.analyzerError += 'index name is required for "field". ';
if ($scope.analyzerError) {
return;
}
param.field = $scope.formValues.field.trim();
} else if ($scope.currentTab == 'custom_analyzer'){
if ($scope.formValues.tokenizer) {
var tmpObj = this.parseCustom($scope.formValues.tokenizer.trim());
if (tmpObj != -1) {
param.tokenizer = tmpObj;
tmpObj = null;
} else {
return;
}
}
// FIXME get tokenizer/char_filter/filter
if ($scope.formValues.charfilters.length > 0) {
$scope.formValues.charfilters.forEach( (charfilter) => {
if (charfilter && charfilter.item && charfilter.item.trim().length > 0 ) {
if(param.charfilters == null) param.charfilters = [];
var tmpCharfilter = this.parseCustom(charfilter.item.trim());
if (tmpCharfilter != -1) {
param.charfilters.push(tmpCharfilter);
} else {
return;
}
}
});
}
if ($scope.formValues.filters.length > 0) {
$scope.formValues.filters.forEach( (filter) => {
if (filter && filter.item && filter.item.trim().length > 0 ) {
if(param.filters == null) param.filters = [];
var tmpFilter = this.parseCustom(filter.item.trim());
if (tmpFilter != -1) {
param.filters.push(tmpFilter);
} else {
return;
}
}
});
}
} else if ($scope.currentTab == 'compare analyzers') {
$scope.formValues.analyzersForCompare.forEach( (analyzer) => {
if (!(analyzer && analyzer.item && analyzer.item.trim().length > 0)) {
console.log("some analyzer is null");
return;
}
});
}

if ($scope.currentTab !== 'compare analyzers'){
// call kibana server API
$http.post(chrome.addBasePath('/api/analyze-api-ui-plugin/analyze'), param)
.then(
(response) => {
$scope.detail = response.data.detail;
this.countTokenSteamLength(response.data.detail);
$scope.esrequest = response.data.request;
$scope.show_esrequest = true;
$scope.show_result = true;
$scope.showAllAttr = false;
})
.catch( error => {
if (error.data.statusCode == 404) {
$scope.indexNameError = error.data.message;
} else if (error.data.statusCode == 400) {
$scope.analyzerError = error.data.message;
} else {
notify.error(error.data);
}
});
} else {
console.log("comparing!!!");
// multiple analyzers
param.analyzers = $scope.formValues.analyzersForCompare;

$http.post(chrome.addBasePath('/api/analyze-api-ui-plugin/multi_analyze'), param)
.then(
(response) => {
$scope.resultAnalyzers = response.data.resultAnalyzers;
$scope.show_result = true;
var tokenStreamLength = 0;
$scope.resultAnalyzers.forEach( (result) => {

tokenStreamLength = this.getLength(tokenStreamLength, result.tokens);
$scope.tokenIndicesArray = [];
for (var i = 0; i < tokenStreamLength; i++) {
$scope.tokenIndicesArray.push(i);
}
});
})
.catch( error => {
if (error.data.statusCode == 404) {
$scope.indexNameError = error.data.message;
} else if (error.data.statusCode == 400) {
$scope.analyzerError = error.data.message;
} else {
notify.error(error.data);
}
});
}
};

}
Loading

0 comments on commit f7e225f

Please sign in to comment.