diff --git a/app/controllers/HomeController.java b/app/controllers/HomeController.java index 7ccc006..a9b7341 100644 --- a/app/controllers/HomeController.java +++ b/app/controllers/HomeController.java @@ -148,22 +148,34 @@ public Result index() { public Result api() { String format = "json"; ImmutableMap searchSamples = ImmutableMap.builder() - .put("Alles", controllers.routes.HomeController.search("*", "", "", 0, 10, format).toString()) + .put("Alles", controllers.routes.HomeController + .search("*", "", "", "", "", "", "", "", 0, 10, format).toString()) .put("Alle Felder", - controllers.routes.HomeController.search("london", "", "", 0, 10, format).toString()) + controllers.routes.HomeController + .search("london", "", "", "", "", "", "", "", 0, 10, format) + .toString()) .put("Feldsuche", - controllers.routes.HomeController.search("preferredName:Twain", "", "", 0, 10, format) + controllers.routes.HomeController.search("preferredName:Twain", "", "", "", + "", "", "", "", 0, 10, format) .toString()) .put("Filter", controllers.routes.HomeController - .search("preferredName:Twain", "type:Person", "", 0, 10, format).toString()) + .search("preferredName:Twain", "", "", "", "", "", "type:Person", + "", 0, 10, format) + .toString()) .put("Paginierung", - controllers.routes.HomeController.search("london", "", "", 50, 100, format).toString()) + controllers.routes.HomeController + .search("london", "", "", "", "", "", "", "", 50, 100, format) + .toString()) .put("Sortierung", controllers.routes.HomeController - .search("scholl", "", "preferredName.keyword:asc", 0, 10, format).toString()) + .search("scholl", "", "", "", "", "", "", + "preferredName.keyword:asc", 0, 10, format) + .toString()) .put("ASCII", controllers.routes.HomeController - .search("preferredName.ascii:Chor OR variantName.ascii:Chor", "", "", 0, 10, format).toString()) + .search("preferredName.ascii:Chor OR variantName.ascii:Chor", "", "", "", + "", "", "", "", 0, 10, format) + .toString()) .build(); ImmutableMap getSamples = ImmutableMap.of(// "London", controllers.routes.HomeController.authorityDotFormat("4074335-4", "json").toString(), // @@ -326,14 +338,16 @@ public Result advanced() { return ok(views.html.advanced.render(allHits())); } - public Result search(String q, String filter, String sort, int from, int size, String format) { + public Result search(String q, String name, String place, String subject, String publication, + String date, String filter, String sort, int from, int size, String format) { Format responseFormat = Accept.formatFor(format, request().acceptedTypes()); if (responseFormat == null || Stream.of(RdfFormat.values()).map(RdfFormat::getParam) .anyMatch(f -> f.equals(responseFormat.queryParamString))) { return unsupportedMediaType(views.html.error.render(q, String.format("Unsupported for search: format=%s, accept=%s", format, request().acceptedTypes()))); } - String queryString = (q == null || q.isEmpty()) ? "*" : q; + String queryString = buildQueryString(q, name, place, subject, publication, date); + queryString = (queryString == null || queryString.isEmpty()) ? "*" : queryString; try { SearchResponse response = index.query(queryString, filter, sort, from, size); response().setHeader("Access-Control-Allow-Origin", "*"); @@ -346,7 +360,8 @@ public Result search(String q, String filter, String sort, int from, int size, S } switch (responseFormat) { case HTML: { - return htmlSearch(q, filter, from, size, responseFormat.queryParamString, response); + return htmlSearch(q, name, place, subject, publication, date, filter, from, size, + responseFormat.queryParamString, response); } case JSON_LINES: { response().setHeader("Content-Disposition", @@ -364,14 +379,8 @@ public Result search(String q, String filter, String sort, int from, int size, S } } - public Result searchAdvanced(String name, String place, String subject, String publication, String date, - String filter, String sort, int from, int size, String format) { - String q = buildQueryString(name, place, subject, publication, date); - return search(q, filter, sort, from, size, format); - } - - private String buildQueryString(String name, String place, String subject, String publication, String date) { - String q = ""; + private String buildQueryString(String q, String name, String place, String subject, + String publication, String date) { q += add(name, "preferredName", "variantName"); q += add(place, "placeOfBirth.label", "placeOfActivity.label", "placeOfDeath.label"); q += add(subject, "professionOrOccupation.label", "gndSubjectCategory.label"); @@ -426,9 +435,12 @@ public ByteString next() { }; } - private Result htmlSearch(String q, String type, int from, int size, String format, SearchResponse response) { - return ok(views.html.search.render(q, type, from, size, returnAsJson(q, response), - response == null ? 0 : response.getHits().getTotalHits(), allHits())); + private Result htmlSearch(String q, String name, String place, String subject, + String publication, String date, String type, int from, int size, String format, + SearchResponse response) { + return ok(views.html.search.render(q, name, place, subject, publication, date, type, from, + size, returnAsJson(q, response), + response == null ? 0 : response.getHits().getTotalHits(), allHits())); } static Result withCallback(final String json) { diff --git a/app/models/AuthorityResource.java b/app/models/AuthorityResource.java index 0e3b6b9..80cfee1 100644 --- a/app/models/AuthorityResource.java +++ b/app/models/AuthorityResource.java @@ -369,7 +369,9 @@ private String addLiterals(String field, String result) { String literalField = field + "AsLiteral"; for (Object literal : get(literalField)) { String search = controllers.routes.HomeController - .search("", literalField + ":\"" + literal + "\"", "", 0, 10, "html").toString(); + .search("", "", "", "", "", "", literalField + ":\"" + literal + "\"", "", 0, + 10, "html") + .toString(); result = result + " " + "|" + " " + literal + " " + String.format( "" @@ -385,7 +387,9 @@ private List typeLinks() { .collect(Collectors.toList()); List typeLinks = (subTypes.isEmpty() ? getType() : subTypes).stream() .map(t -> String.format("%s", - controllers.routes.HomeController.search("", "+(type:" + t + ")", "", 0, 10, "").toString(), + controllers.routes.HomeController + .search("", "", "", "", "", "", "+(type:" + t + ")", "", 0, 10, "") + .toString(), models.GndOntology.label(t))) .collect(Collectors.toList()); return typeLinks; @@ -454,7 +458,7 @@ private String process(String field, String value, String label, int i, int size boolean labelBasedFacet = facets.contains(field + ".label"); boolean qBasedSearch = facets.stream().noneMatch(s -> s.startsWith(field)); String search = controllers.routes.HomeController - .search(qBasedSearch ? field + ".id:\"" + value + "\"" : "", + .search(qBasedSearch ? field + ".id:\"" + value + "\"" : "", "", "", "", "", "", labelBasedFacet ? field + ".label:\"" + label + "\"" : field + ".id:\"" + value + "\"", "", 0, 10, "html") .toString(); @@ -470,7 +474,8 @@ private String process(String field, String value, String label, int i, int size result = searchLink + " " + (linkableEntity ? entityLink : ""); } else if (field.endsWith("AsLiteral")) { String search = controllers.routes.HomeController - .search("", field + ":\"" + value + "\"", "", 0, 10, "html").toString(); + .search("", "", "", "", "", "", field + ":\"" + value + "\"", "", 0, 10, "html") + .toString(); result = result + " " + String.format( "" diff --git a/app/views/search.scala.html b/app/views/search.scala.html index c2cceab..8b8baea 100644 --- a/app/views/search.scala.html +++ b/app/views/search.scala.html @@ -1,6 +1,6 @@ @* Copyright 2015-2018 Fabian Steeg, hbz. Licensed under the EPL 2.0 *@ -@(q: String, f: String, from: Int, size: Int, result: String, searchHits: Long, allHits: Long) +@(q: String, name: String = "", place: String = "", subject: String = "", publication: String = "", date: String = "", f: String, from: Int, size: Int, result: String, searchHits: Long, allHits: Long) @import play.api.libs.json._ @import controllers.HomeController.CONFIG @@ -10,17 +10,17 @@ @@ -28,7 +28,7 @@ @pageLink(num: Int)={
  • - @num + @num
  • } @@ -171,6 +171,9 @@
    @models.GndOntology.label("type")
    @main(q, "RPPD - Ergebnisliste", allHits) { + @if(Seq(name, place, subject, publication, date).exists(!_.isEmpty)){ + @search_advanced("Suche aktualisieren", q=q, name=name, place=place, subject=subject, publication=publication, date=date) + } @defining((Json.parse(result) \ "member").asOpt[Seq[JsValue]].getOrElse(Seq()).zipWithIndex) { hits =>
    diff --git a/app/views/search_advanced.scala.html b/app/views/search_advanced.scala.html index 0559694..9bb556e 100644 --- a/app/views/search_advanced.scala.html +++ b/app/views/search_advanced.scala.html @@ -46,7 +46,7 @@ } -@helper.form(action = controllers.routes.HomeController.searchAdvanced(), +@helper.form(action = controllers.routes.HomeController.search(), 'id -> "nwbib-form", 'role -> "form", 'class -> "form-inline", 'autocomplete -> "off") { @defining(TreeMap("name"->name,"place"->place,"publication"->publication,"subject"->subject,"date"->date).filter({case (k,v) => !v.isEmpty})) { fields => @for(((k,v),i)<- (if(fields.isEmpty) TreeMap("q" -> "") else fields).zipWithIndex){ diff --git a/conf/routes b/conf/routes index 25cc28c..0bb78bd 100644 --- a/conf/routes +++ b/conf/routes @@ -23,9 +23,8 @@ GET /context.jsonld controllers.HomeController.context() GET /dataset.jsonld controllers.HomeController.dataset(format="json") GET /dataset controllers.HomeController.dataset(format?="") -GET /search controllers.HomeController.search(q ?= "", filter ?= "", sort ?= "", from: Int ?= 0, size: Int ?= 10, format ?= null) +GET /search controllers.HomeController.search(q ?= "", name ?= "", place ?= "", subject ?= "", publication ?= "", date ?= "", filter ?= "", sort ?= "", from: Int ?= 0, size: Int ?= 10, format ?= null) GET /advanced controllers.HomeController.advanced() -GET /searchAdvanced controllers.HomeController.searchAdvanced(name ?= "", place ?= "", subject ?= "", publication ?= "", date ?= "", filter ?= "", sort ?= "", from: Int ?= 0, size: Int ?= 10, format ?= null) GET /cgi-bin/wwwalleg/:name.pl controllers.HomeController.authorityPl(name, db ?= "rnam", index: Int ?= 1, zeilen: Int ?= 1, s1) diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css index 1002785..582cac2 100644 --- a/public/stylesheets/main.css +++ b/public/stylesheets/main.css @@ -21,8 +21,8 @@ input#owner { .search-field { padding: 2px; - padding-right: 10px !important; - padding-left: 10px !important; + padding-right: 12px !important; + padding-left: 12px !important; } .pagination-and-facets {