SOLR-7579: Fix Angular admin UI analysis screen drop-down issue

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1681131 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2015-05-22 14:45:45 +00:00
parent f9f2b12a57
commit 471784c67d
2 changed files with 65 additions and 66 deletions

View File

@ -19,19 +19,6 @@ solrAdminApp.controller('AnalysisController',
function($scope, $location, $routeParams, Luke, Analysis) {
$scope.resetMenu("analysis");
// Read initial values from URL:
$scope.init = function() {
var params = $location.search();
$scope.indexText = params["analysis.fieldvalue"];
$scope.queryText = params["analysis.query"];
if (params["analysis.fieldname"]) {
$scope.fieldOrType = "fieldname=" + params["analysis.fieldname"];
} else {
$scope.fieldOrType = "fieldtype=" + params["analysis.fieldtype"];
}
$scope.verbose = params["verboxe_output"]=="1";
};
$scope.refresh = function() {
Luke.schema({core: $routeParams.core}, function(data) {
$scope.fieldsAndTypes = [];
@ -49,20 +36,9 @@ solrAdminApp.controller('AnalysisController',
}
});
$scope.parseQueryString();
// @todo - if URL param, set $scope.verbose;
// @todo - set defaultSearchField either to context["analysis.fieldname"] or context["analysis.fieldtype"]
/** @todo: not sure:
var fields = 0;
for( var key in context.params )
{
if( 'string' === typeof context.params[key] && 0 !== context.params[key].length )
{
fields++;
$( '[name="' + key + '"]', analysis_form )
.val( context.params[key] );
}
}
*/
};
$scope.verbose = true;
@ -111,62 +87,85 @@ solrAdminApp.controller('AnalysisController',
return tokens;
};
var mangle = function(data) {
response = [];
for (var i=0; i < data.length; i+=2) {
var extractComponents = function(data, result, name) {
if (data) {
result[name] = [];
for (var i = 0; i < data.length; i += 2) {
var component = {
name: data[i],
short: getShortComponentName(data[i]),
captions: getCaptionsForComponent(data[i+1]),
tokens: getTokensForComponent(data[i+1])
captions: getCaptionsForComponent(data[i + 1]),
tokens: getTokensForComponent(data[i + 1])
};
response.push(component);
result[name].push(component);
}
}
return response;
};
var processAnalysisData = function(analysis, fieldOrType) {
var fieldname;
console.log(fieldOrType);
console.dir(analysis[fieldOrType]);
for (fieldname in analysis[fieldOrType]) {console.log(fieldname);break;}
var index = mangle(analysis[fieldOrType][fieldname].index);
var query = mangle(analysis[fieldOrType][fieldname].query);
response = {index: index, query: query};
var response = {};
extractComponents(analysis[fieldOrType][fieldname].index, response, "index");
extractComponents(analysis[fieldOrType][fieldname].query, response, "query");
return response;
};
$scope.analyse = function() {
$scope.updateQueryString = function() {
var parts = $scope.fieldOrType.split("=");
var fieldOrType = parts[0];
var name = parts[1];
if ($scope.indexText) {
$location.search("analysis.fieldvalue", $scope.indexText);
}
if ($scope.queryText) {
$location.search("analysis.query", $scope.queryText);
}
if (fieldOrType == "fieldname") {
$location.search("analysis.fieldname", name);
$location.search("analysis.fieldtype", null);
} else {
$location.search("analysis.fieldtype", name);
$location.search("analysis.fieldname", null);
}
};
$scope.parseQueryString = function () {
var params = {};
var search = $location.search();
if (Object.keys(search).length == 0) {
return;
}
for (var key in search) {
params[key]=search[key];
}
$scope.indexText = search["analysis.fieldvalue"];
$scope.queryText = search["analysis.query"];
if (search["analysis.fieldname"]) {
$scope.fieldOrType = "fieldname=" + search["analysis.fieldname"];
} else {
$scope.fieldOrType = "fieldtype=" + search["analysis.fieldtype"];
}
$scope.verbose = search["verbose_output"] == "1";
if ($scope.fieldOrType || $scope.indexText || $scope.queryText) {
params.core = $routeParams.core;
var parts = $scope.fieldOrType.split("=");
var fieldOrType = parts[0] == "fieldname" ? "field_names" : "field_types";
params = {
"analysis.fieldvalue": $scope.indexText,
"analysis.query": $scope.queryText
};
if (fieldOrType == "field_names") {
params["analysis.fieldname"] = parts[1];
} else {
params["analysis.fieldtype"] = parts[1];
}
$location.search("analysis.fieldname", null);
$location.search("analysis.fieldtype", null);
for (var param in params) {
$location.search(param, params[param]);
}
params.core = $routeParams.core;
Analysis.field(params, function(data) {
$scope.analysis = data;
$scope.result = processAnalysisData(data.analysis, fieldOrType);
});
}
};
$scope.toggleVerbose = function() {$scope.verbose = !$scope.verbose};
$scope.init();
$scope.refresh();
}
);

View File

@ -41,13 +41,13 @@ limitations under the License.
<li class="settings-holder clearfix">
<div class="settings clearfix">
<label for="type_or_name">Analyse Fieldname / FieldType:</label>
<select chosen id="type_or_name" ng-model="fieldOrType" ng-options="f.value as f.label group by f.group for f in fieldsAndTypes"></select>
<select style="width:130px" chosen id="type_or_name" ng-model="fieldOrType" ng-options="f.value as f.label group by f.group for f in fieldsAndTypes"></select>
<a id="tor_schema" href="#"><span>Schema Browser</span>&nbsp;</a>
<div class="buttons clearfix">
<button type="submit" ng-click="analyse()"><span>Analyse Values</span></button>
<button type="submit" ng-click="updateQueryString()"><span>Analyse Values</span></button>
<div class="verbose_output" ng-class="{active:verbose}">
<a ng-click="toggleVerbose()">Verbose Output</a>