SOLR-8370: Display configured Similarity in Schema-Browser

(cherry picked from commit 14b6d93)
This commit is contained in:
Jan Høydahl 2016-10-20 13:25:40 +02:00
parent e61ce95a8f
commit c35c723bf5
6 changed files with 98 additions and 36 deletions

View File

@ -102,6 +102,9 @@ New Features
* SOLR-9417: Allow daemons to terminate when they finish iterating a topic (Joel Bernstein)
* SOLR-8370: Display configured Similarity in Schema-Browser, both global/default and per-field/field-type
(janhoy, Alexandre Rafalovitch)
Bug Fixes
----------------------

View File

@ -474,6 +474,7 @@ public class LukeRequestHandler extends RequestHandlerBase
finfo.add("uniqueKeyField",
null == uniqueField ? null : uniqueField.getName());
finfo.add("defaultSearchField", schema.getDefaultSearchFieldName());
finfo.add("similarity", getSimilarityInfo(schema.getSimilarity()));
finfo.add("types", types);
return finfo;
}

View File

@ -131,20 +131,32 @@ public class SchemaSimilarityFactory extends SimilarityFactory implements SolrCo
"' but that <fieldType> does not define a <similarity>");
}
}
assert null != defaultSim;
similarity = new PerFieldSimilarityWrapper(defaultSim) {
@Override
public Similarity get(String name) {
FieldType fieldType = core.getLatestSchema().getFieldTypeNoEx(name);
if (fieldType == null) {
return defaultSim;
} else {
Similarity similarity = fieldType.getSimilarity();
return similarity == null ? defaultSim : similarity;
}
}
};
similarity = new SchemaSimilarity(defaultSim);
}
return similarity;
}
private class SchemaSimilarity extends PerFieldSimilarityWrapper {
private Similarity defaultSimilarity;
public SchemaSimilarity(Similarity defaultSimilarity) {
this.defaultSimilarity = defaultSimilarity;
}
@Override
public Similarity get(String name) {
FieldType fieldType = core.getLatestSchema().getFieldTypeNoEx(name);
if (fieldType == null) {
return defaultSimilarity;
} else {
Similarity similarity = fieldType.getSimilarity();
return similarity == null ? defaultSimilarity : similarity;
}
}
@Override
public String toString() {
return "SchemaSimilarity. Default: " + ((get("") == null) ? "null" : get("").toString());
}
}
}

View File

@ -701,4 +701,27 @@ limitations under the License.
#content #schema .copyfield .updatable a {
float:left;
width:80%;
}
#content #schema dd.similarity.ng-binding::after {
content: attr(data-tip) ;
font-size: 12px;
position: relative;
white-space: nowrap;
bottom: 9999px;
left: 0;
background: lightyellow;
color: black;
padding: 4px 7px;
line-height: 24px;
height: 24px;
border: 1px solid darkgray;
opacity: 0;
transition:opacity 0.4s ease-out;
}
#content #schema dd.similarity.ng-binding:hover::after {
opacity: 90;
bottom: -20px;
}

View File

@ -70,6 +70,10 @@ solrAdminApp.controller('SchemaController',
$scope.core = $routeParams.core;
$scope.defaultSearchField = data.default_search_field;
$scope.uniqueKeyField = data.unique_key_field;
$scope.similarity = data.similarity;
if ($scope.similarity && $scope.similarity.className) {
$scope.similarity.className = shortenPackages($scope.similarity.className);
}
$scope.isDefaultSearchField = ($scope.selectedType == "Field" && $scope.name == $scope.defaultSearchField);
$scope.isUniqueKeyField = ($scope.selectedType == "Field" && $scope.name == $scope.uniqueKeyField);
@ -334,6 +338,7 @@ var mergeIndexAndSchemaData = function(index, schema) {
var data = {
default_search_field: null,
unique_key_field: null,
similarity: null,
key: {},
fields: {},
dynamic_fields: {},
@ -354,6 +359,7 @@ var mergeIndexAndSchemaData = function(index, schema) {
data.default_search_field = schema.defaultSearchField;
data.unique_key_field = schema.uniqueKeyField;
data.similarity = schema.similarity;
data.dynamic_fields = schema.dynamicFields;
data.types = schema.types;
@ -422,11 +428,11 @@ var mergeIndexAndSchemaData = function(index, schema) {
return data;
};
var getFieldProperties = function(data, core, is, field) {
var getFieldProperties = function(data, core, is, name) {
var display = {};
display.partialState = is.field && !!data.fields[field].partial;
display.partialState = is.field && !!data.fields[name].partial;
display.columns = [];
display.rows = [];
@ -446,23 +452,33 @@ var getFieldProperties = function(data, core, is, field) {
}
// Identify the rows for our field property table
if (is.field && data.fields[field]) {
if (data.fields[field].flags) {
addRow('Properties', data.fields[field].flags);
if (is.field && data.fields[name]) {
if (data.fields[name].flags) {
addRow('Properties', data.fields[name].flags);
}
if (data.fields[field].schema) {
addRow('Schema', data.fields[field].schema);
if (data.fields[name].schema) {
addRow('Schema', data.fields[name].schema);
}
if (data.fields[field].index) {
addRow('Index', data.fields[field].index);
if (data.fields[name].index) {
addRow('Index', data.fields[name].index);
}
display.docs = data.fields[field].docs;
display.docsUrl = "#/" + core + "/query?q=" + field + ":[* TO *]";
display.distinct = data.fields[field].distinct;
display.positionIncrementGap = data.fields[field].positionIncrementGap;
display.similarity = data.fields[field].similarity;
} else if (is.dynamicField && data.dynamic_fields[field] && data.dynamic_fields[field].flags) {
addRow('Properties', data.dynamic_fields[field].flags);
display.docs = data.fields[name].docs;
display.docsUrl = "#/" + core + "/query?q=" + name + ":[* TO *]";
display.distinct = data.fields[name].distinct;
display.positionIncrementGap = data.fields[name].positionIncrementGap;
if (data.types[data.fields[name].type]) {
display.similarity = data.types[data.fields[name].type].similarity;
} else {
display.similarity = null;
}
} else if (is.dynamicField && data.dynamic_fields[name] && data.dynamic_fields[name].flags) {
addRow('Properties', data.dynamic_fields[name].flags);
display.similarity = data.types[data.dynamic_fields[name].type].similarity;
} else if (is.type && data.types[name]) {
display.similarity = data.types[name].similarity;
}
if (display.similarity && display.similarity.className) {
display.similarity.className = shortenPackages(display.similarity.className);
}
// identify columns in field property table:
@ -591,7 +607,11 @@ var sortedObjectArray = function(list) {
objarr.push({"name": list[i]});
}
return objarr;
}
};
var shortenPackages = function(className) {
return className.replace("org.apache.solr", "o.a.s").replace("org.apache.lucene", "o.a.l");
};
/*
var get_width = function get_width()

View File

@ -212,7 +212,7 @@ limitations under the License.
</h2>
</div>
<div class="partial" ng-show="partialState">
<div class="partial" ng-show="display.partialState">
<p>Because your Index is empty, we do not have enough Information about this Field</p>
@ -220,11 +220,11 @@ limitations under the License.
<dl class="options clearfix">
<dt class="field-type">Field-Type:</dt>
<dd class="field-type">{{analysis.data.className}}</dd>
<dt class="field-type" ng-show="analysis.data.className">Field-Type:</dt>
<dd class="field-type" ng-show="analysis.data.className">{{analysis.data.className}}</dd>
<dt class="similarity" ng-show="display.similarity">Similarity:</dt>
<dd class="similarity" ng-show="display.similarity">{{ display.similarity.details }} ({{ similarity.className }}) </dd>
<dt class="similarity" ng-show="display.similarity.className">Similarity:</dt>
<dd class="similarity" ng-show="display.similarity.className" data-tip="{{ display.similarity.className }}">{{ display.similarity.details }}</dd>
<dt class="position-increment-gap" ng-show="display.positionIncrementGap"><abbr title="Position Increment Gap">PI Gap</abbr>:</dt>
<dd class="position-increment-gap" ng-show="display.positionIncrementGap">{{ display.positionIncrementGap }}</dd>
@ -287,7 +287,7 @@ limitations under the License.
</div>
<div class="terminfo-holder loaded clearfix" ng-class="{disabled: noTermData}" ng-show="is.field">
<div class="terminfo-holder loaded clearfix" ng-class="{disabled: noTermData}" ng-show="is.field && !display.partialState">
<div class="trigger">
@ -438,6 +438,9 @@ limitations under the License.
<dt class="default-search-field" ng-class="{active: isDefaultSearchField}" ng-show="defaultSearchField">Default Search Field</dt>
<dd class="default-search-field" ng-class="{active: isDefaultSearchField}"><a ng-href="#/{{core}}/schema?field={{defaultSearchField}}">{{defaultSearchField}}</a></dd>
<dt class="similarity" ng-class="{active: similarity.className}">Global Similarity:</dt>
<dd class="similarity" ng-class="{active: similarity.className}" data-tip="{{ similarity.className }}">{{ similarity.details }}</dd>
</dl>
</div>