Skip to content

Commit 52dc57d

Browse files
committed
Support skos:altLabel and skos:example in list filter (#657)
1 parent c099d7e commit 52dc57d

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

app/controllers/nwbib/Classification.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ private SearchResponse classificationData() {
174174

175175
private enum Property {
176176
LABEL("http://www.w3.org/2004/02/skos/core#prefLabel"), //
177+
ALT_LABEL("http://www.w3.org/2004/02/skos/core#altLabel"), //
178+
EXAMPLE("http://www.w3.org/2004/02/skos/core#example"), //
177179
BROADER("http://www.w3.org/2004/02/skos/core#broader"), //
178180
NOTATION("http://www.w3.org/2004/02/skos/core#notation"), //
179181
NARROW_MATCH("http://www.w3.org/2004/02/skos/core#narrowMatch"), //
@@ -457,6 +459,8 @@ private static void collectLabelAndValue(SearchHit hit, JsonNode json,
457459
(style == Label.PLAIN || notation.isEmpty() ? ""
458460
: "<span class='notation'>" + notation + "</span>" + " ")
459461
+ label.findValue("@value").asText()) //
462+
.put("altLabel", findValues(json, Property.ALT_LABEL)) //
463+
.put("example", findValues(json, Property.EXAMPLE)) //
460464
.put("hits", Lobid.getTotalHitsNwbibClassification(id)) //
461465
.put("notation", notation) //
462466
.put("focus", focus(json)) //
@@ -465,6 +469,11 @@ private static void collectLabelAndValue(SearchHit hit, JsonNode json,
465469
}
466470
}
467471

472+
private static List<String> findValues(JsonNode json, Property p) {
473+
return json.has(p.value) ? json.get(p.value).findValuesAsText("@value")
474+
: Arrays.asList();
475+
}
476+
468477
private static List<String> matches(JsonNode json) {
469478
List<String> result = new ArrayList<>();
470479
addMatches(json, Property.NARROW_MATCH, result);

app/views/tags/browse_list.scala.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
</script>
6868
@for(json <- classes.getOrElse(Seq());
6969
entryLabel = label(json);
70+
altLabel = (json\"altLabel").asOpt[Seq[String]].getOrElse(Seq()).mkString("; ");
71+
example = (json\"example").asOpt[Seq[String]].getOrElse(Seq()).mkString("; ");
7072
normalized = entryLabel.replaceAll("ß", "ss") + entryLabel.replaceAll("ss", "ß");
7173
value = (json\"value").as[String];
7274
hits = (json\"hits").asOpt[scala.Long].getOrElse(0L);
@@ -107,7 +109,7 @@ <h4 class="modal-title" id="[email protected]">Links für @Html(entryLabel
107109
</div>
108110
}
109111
@if(t!="Zeitschriften"){<span @if(t!="Wikidata"){class='copy-link'}><a data-toggle="tooltip" data-placement="right" title="Identifikator und Bezeichnung in die Zwischenablage kopieren" href="#" onclick="copyToClipboard('@textToCopy', $(this));return false;"><span class="octicon octicon-clippy"></span></a></span>}
110-
<div style="display: none">@normalized</div>
112+
<div style="display: none">@normalized @altLabel @example</div>
111113
}
112114
@if(t=="Wikidata"){
113115
@if(anchor.startsWith("Q")) {

test/tests/InternalIntegrationTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,26 @@ public void testLeadingBlanksInSearchWord() {
101101
searchLeadingBlankWith("word=");
102102
}
103103

104+
@Test // See https://github.com/hbz/nwbib/issues/657
105+
public void testSearchInAltLabel() {
106+
running(testServer(3333), () -> {
107+
assertIndexDataForIdContains("N566042", "Ortsteil"); // from altLabel
108+
});
109+
}
110+
111+
@Test // See https://github.com/hbz/nwbib/issues/657
112+
public void testSearchInExample() {
113+
running(testServer(3333), () -> {
114+
assertIndexDataForIdContains("N543620", "Betriebsrat"); // from example
115+
});
116+
}
117+
118+
private static void assertIndexDataForIdContains(String id, String string) {
119+
assertThat(
120+
Classification.ids("https://nwbib.de/subjects#" + id, "").toString())
121+
.as("index data for " + id).contains(string);
122+
}
123+
104124
private static void searchLeadingBlankWith(String param) {
105125
running(testServer(3333), () -> {
106126
try {

0 commit comments

Comments
 (0)