From 14b6d93db4b0a608809782d1ef01fa97840b80e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B8ydahl?= Date: Thu, 20 Oct 2016 13:25:40 +0200 Subject: [PATCH] SOLR-8370: Display configured Similarity in Schema-Browser --- solr/CHANGES.txt | 3 ++ .../handler/admin/LukeRequestHandler.java | 1 + .../similarities/SchemaSimilarityFactory.java | 39 +++++++++----- solr/webapp/web/css/angular/schema.css | 23 ++++++++ .../web/js/angular/controllers/schema.js | 54 +++++++++++++------ solr/webapp/web/partials/schema.html | 15 +++--- 6 files changed, 98 insertions(+), 37 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index aca76018237..b3a2a301ddb 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -142,6 +142,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 ---------------------- diff --git a/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java index a5fc36c3019..d0dd15252dd 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java @@ -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; } diff --git a/solr/core/src/java/org/apache/solr/search/similarities/SchemaSimilarityFactory.java b/solr/core/src/java/org/apache/solr/search/similarities/SchemaSimilarityFactory.java index e648481dd65..a71de189d5a 100644 --- a/solr/core/src/java/org/apache/solr/search/similarities/SchemaSimilarityFactory.java +++ b/solr/core/src/java/org/apache/solr/search/similarities/SchemaSimilarityFactory.java @@ -129,21 +129,32 @@ public class SchemaSimilarityFactory extends SimilarityFactory implements SolrCo "' but that does not define a "); } } - assert null != defaultSim; - final Similarity defaultSimilarity = defaultSim; - similarity = new PerFieldSimilarityWrapper() { - @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; - } - } - }; + 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()); + } + } } diff --git a/solr/webapp/web/css/angular/schema.css b/solr/webapp/web/css/angular/schema.css index 626cdc2bb75..98a857f219e 100644 --- a/solr/webapp/web/css/angular/schema.css +++ b/solr/webapp/web/css/angular/schema.css @@ -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; } \ No newline at end of file diff --git a/solr/webapp/web/js/angular/controllers/schema.js b/solr/webapp/web/js/angular/controllers/schema.js index ee23bd7931e..94dd93e8d4d 100644 --- a/solr/webapp/web/js/angular/controllers/schema.js +++ b/solr/webapp/web/js/angular/controllers/schema.js @@ -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() diff --git a/solr/webapp/web/partials/schema.html b/solr/webapp/web/partials/schema.html index ca626fd74c1..1c0347f73f4 100644 --- a/solr/webapp/web/partials/schema.html +++ b/solr/webapp/web/partials/schema.html @@ -212,7 +212,7 @@ limitations under the License. -
+

Because your Index is empty, we do not have enough Information about this Field

@@ -220,11 +220,11 @@ limitations under the License.
-
Field-Type:
-
{{analysis.data.className}}
+
Field-Type:
+
{{analysis.data.className}}
-
Similarity:
-
{{ display.similarity.details }} ({{ similarity.className }})
+
Similarity:
+
{{ display.similarity.details }}
PI Gap:
{{ display.positionIncrementGap }}
@@ -287,7 +287,7 @@ limitations under the License.
-
+
@@ -438,6 +438,9 @@ limitations under the License.
Default Search Field
{{defaultSearchField}}
+
Global Similarity:
+
{{ similarity.details }}
+