From cf10361f762bc064791e174bd0eacd39af0c1545 Mon Sep 17 00:00:00 2001 From: Matija Obreza Date: Tue, 3 May 2016 23:04:19 +0200 Subject: [PATCH] Full-text search: update display of articles, posts, countries and institutes --- .../impl/FullTextSearchServiceImpl.java | 17 +++++++----- .../servlet/controller/SearchController.java | 17 +++++++++--- src/main/sourceapp/0/styles/genesys.scss | 17 ++++++++++++ src/main/sourceapp/1/styles/genesys.scss | 24 ++++++++++++++++- src/main/webapp/WEB-INF/jsp/search2/index.jsp | 12 +++++---- .../webapp/WEB-INF/tags/mini/activitypost.tag | 26 +++++++++++++++++++ src/main/webapp/WEB-INF/tags/mini/article.tag | 24 +++++++++++++++++ src/main/webapp/WEB-INF/tags/mini/country.tag | 2 +- .../webapp/WEB-INF/tags/mini/institute.tag | 16 +++++++----- 9 files changed, 131 insertions(+), 24 deletions(-) create mode 100644 src/main/webapp/WEB-INF/tags/mini/activitypost.tag create mode 100644 src/main/webapp/WEB-INF/tags/mini/article.tag diff --git a/src/main/java/org/genesys2/server/service/impl/FullTextSearchServiceImpl.java b/src/main/java/org/genesys2/server/service/impl/FullTextSearchServiceImpl.java index 494c2a107..8d3dde6d4 100644 --- a/src/main/java/org/genesys2/server/service/impl/FullTextSearchServiceImpl.java +++ b/src/main/java/org/genesys2/server/service/impl/FullTextSearchServiceImpl.java @@ -193,6 +193,10 @@ public class FullTextSearchServiceImpl implements FullTextSearchService, Initial return instituteRepository.findOne(id); } else if (Country.class.getName().equals(className)) { return countryRepository.findOne(id); + } else if (ActivityPost.class.getName().equals(className)) { + return postRepository.findOne(id); + } else if (Article.class.getName().equals(className)) { + return articleRepository.findOne(id); } else { throw new UnsupportedOperationException("Missing toEntity implementation for class=" + className); } @@ -460,7 +464,6 @@ public class FullTextSearchServiceImpl implements FullTextSearchService, Initial // FIXME Should not include articles that belong to institutes or // countries final Article article = (Article) model; - document.setClassPK(article.getClassPk()); document.setBody(article.getBody()); document.setSummary(article.getSummary()); document.setLanguage(article.getLang()); @@ -469,19 +472,19 @@ public class FullTextSearchServiceImpl implements FullTextSearchService, Initial document.setUrlToContent("/content/" + article.getSlug()); } else if (model instanceof ActivityPost) { - updateDocumentForCountry((ActivityPost) model, document); + updateDocument((ActivityPost) model, document); } else if (model instanceof Country) { - updateDocumentForCountry((Country) model, document); + updateDocument((Country) model, document); } else if (model instanceof FaoInstitute) { - updateDocumentForFaoInstitute((FaoInstitute) model, document); + updateDocument((FaoInstitute) model, document); } return document; } - private void updateDocumentForCountry(ActivityPost activityPost, FullTextDocument document) { + private void updateDocument(ActivityPost activityPost, FullTextDocument document) { document.setBody(activityPost.getBody()); document.setSummary(activityPost.getTitle()); document.setCreatedDate(activityPost.getCreatedDate()); @@ -489,7 +492,7 @@ public class FullTextSearchServiceImpl implements FullTextSearchService, Initial document.setUrlToContent("/content/news/" + activityPost.getId() + "/" + this.jspHelper.suggestUrlForText(activityPost.getTitle())); } - private void updateDocumentForCountry(Country country, FullTextDocument document) { + private void updateDocument(Country country, FullTextDocument document) { document.setUrlToContent("/geo/" + country.getCode3()); document.setLanguage(contentService.getDefaultLocale().getLanguage()); document.setSummary(country.getCode3() + " " + country.getNameL()); @@ -500,7 +503,7 @@ public class FullTextSearchServiceImpl implements FullTextSearchService, Initial } } - private void updateDocumentForFaoInstitute(FaoInstitute institute, FullTextDocument document) { + private void updateDocument(FaoInstitute institute, FullTextDocument document) { document.setUrlToContent("/wiews/" + institute.getCode()); document.setLanguage(contentService.getDefaultLocale().getLanguage()); document.setSummary(institute.getCode() + " " + institute.getAcronym() + " " + institute.getFullName()); diff --git a/src/main/java/org/genesys2/server/servlet/controller/SearchController.java b/src/main/java/org/genesys2/server/servlet/controller/SearchController.java index 2445941d7..2cc3a229c 100644 --- a/src/main/java/org/genesys2/server/servlet/controller/SearchController.java +++ b/src/main/java/org/genesys2/server/servlet/controller/SearchController.java @@ -24,6 +24,8 @@ import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.genesys2.server.model.impl.ActivityPost; +import org.genesys2.server.model.impl.Article; import org.genesys2.server.model.impl.ClassPK; import org.genesys2.server.model.impl.Country; import org.genesys2.server.model.impl.FaoInstitute; @@ -142,10 +144,14 @@ public class SearchController { @RequestMapping("/acn/search2") public String findFullTextDocument(ModelMap model, @RequestParam(required = false, value = "q") String searchQuery, @RequestParam(value = "page", required = true, defaultValue = "1") int page, - @RequestParam(value = "section", required = true, defaultValue = "accession") String section) throws SearchException { + @RequestParam(value = "section", required = false, defaultValue = "accession") String section) throws SearchException { + + if (StringUtils.isBlank(section)) { + section = "accession"; + } ClassPK classPK = contentService.getClassPk(section); - if (classPK == null) { + if (classPK == null && ! "accession".equals(section)) { LOG.warn("No search section " + section); throw new SearchException("No such search section"); } @@ -160,8 +166,13 @@ public class SearchController { model.addAttribute("pagedData", fullTextSearchService.search(searchQuery, new PageRequest(page - 1, 50), FaoInstitute.class)); } else if ("country".equals(section)) { model.addAttribute("pagedData", fullTextSearchService.search(searchQuery, new PageRequest(page - 1, 50), Country.class)); + } else if ("article".equals(section)) { + model.addAttribute("pagedData", fullTextSearchService.search(searchQuery, new PageRequest(page - 1, 50), Article.class)); + } else if ("activitypost".equals(section)) { + model.addAttribute("pagedData", fullTextSearchService.search(searchQuery, new PageRequest(page - 1, 50), ActivityPost.class)); } else { - model.addAttribute("pagedData", fullTextSearchService.search(searchQuery, new PageRequest(page - 1, 50), section)); + LOG.error("Unsupported full-text searchfor section: " + section); + throw new UnsupportedOperationException("No such search section"); } } catch (SearchException e) { LOG.info("Searching for: " + searchQuery + " failed with error " + e.getMessage()); diff --git a/src/main/sourceapp/0/styles/genesys.scss b/src/main/sourceapp/0/styles/genesys.scss index 62121276b..008096639 100644 --- a/src/main/sourceapp/0/styles/genesys.scss +++ b/src/main/sourceapp/0/styles/genesys.scss @@ -2487,3 +2487,20 @@ div[x-href] { .dropdown-menu.view-columns li { padding: 0 10px; } + +.genesys-mini { + .title { + margin: 0.5em 0; + font-size: 130%; + } + + .summary { + margin: 0.5em 0; + margin-left: 3em; + } + + .url { + margin: 0.5em 0; + color: Gray; + } +} diff --git a/src/main/sourceapp/1/styles/genesys.scss b/src/main/sourceapp/1/styles/genesys.scss index 2f38d8b5d..8b2a86307 100644 --- a/src/main/sourceapp/1/styles/genesys.scss +++ b/src/main/sourceapp/1/styles/genesys.scss @@ -653,4 +653,26 @@ span.idx-col { img { width: 100%; } -} \ No newline at end of file +} + +.genesys-mini { + .title { + margin: 0.5em 0; + font-size: 130%; + } + + .summary { + margin: 0.5em 0; + margin-left: 3em; + } + + .url { + margin: 0.5em 0; + color: Gray; + } + + .not-current { + font-style: italic; + opacity: 0.5; + } +} diff --git a/src/main/webapp/WEB-INF/jsp/search2/index.jsp b/src/main/webapp/WEB-INF/jsp/search2/index.jsp index db345c359..ea443eb2a 100644 --- a/src/main/webapp/WEB-INF/jsp/search2/index.jsp +++ b/src/main/webapp/WEB-INF/jsp/search2/index.jsp @@ -71,12 +71,8 @@ - Body - Summary - Body - Title @@ -104,9 +100,15 @@ + + + + + + - " ${section} " + "> diff --git a/src/main/webapp/WEB-INF/tags/mini/activitypost.tag b/src/main/webapp/WEB-INF/tags/mini/activitypost.tag new file mode 100644 index 000000000..e7ad78466 --- /dev/null +++ b/src/main/webapp/WEB-INF/tags/mini/activitypost.tag @@ -0,0 +1,26 @@ +<%@ tag description="Display article" pageEncoding="UTF-8"%> +<%@ tag body-content="empty"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> +<%@ taglib prefix="security" + uri="http://www.springframework.org/security/tags"%> +<%@ taglib prefix="local" tagdir="/WEB-INF/tags"%> +<%@ taglib prefix="cms" tagdir="/WEB-INF/tags/cms"%> +<%@ attribute name="activityPost" required="true" + type="org.genesys2.server.model.impl.ActivityPost"%> + +
+
+ +
+
+
+ +
+
diff --git a/src/main/webapp/WEB-INF/tags/mini/article.tag b/src/main/webapp/WEB-INF/tags/mini/article.tag new file mode 100644 index 000000000..6e78c12e6 --- /dev/null +++ b/src/main/webapp/WEB-INF/tags/mini/article.tag @@ -0,0 +1,24 @@ +<%@ tag description="Display article" pageEncoding="UTF-8"%> +<%@ tag body-content="empty"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> +<%@ taglib prefix="security" + uri="http://www.springframework.org/security/tags"%> +<%@ taglib prefix="local" tagdir="/WEB-INF/tags"%> +<%@ taglib prefix="cms" tagdir="/WEB-INF/tags/cms"%> +<%@ attribute name="article" required="true" + type="org.genesys2.server.model.impl.Article"%> + +
+
+ "> + + +
+
+ +
+
+ +
+
diff --git a/src/main/webapp/WEB-INF/tags/mini/country.tag b/src/main/webapp/WEB-INF/tags/mini/country.tag index 7934d1141..9401b211a 100644 --- a/src/main/webapp/WEB-INF/tags/mini/country.tag +++ b/src/main/webapp/WEB-INF/tags/mini/country.tag @@ -14,7 +14,7 @@ "> -
+
diff --git a/src/main/webapp/WEB-INF/tags/mini/institute.tag b/src/main/webapp/WEB-INF/tags/mini/institute.tag index b70ac5b56..4a98e3c97 100644 --- a/src/main/webapp/WEB-INF/tags/mini/institute.tag +++ b/src/main/webapp/WEB-INF/tags/mini/institute.tag @@ -9,15 +9,11 @@ type="org.genesys2.server.model.impl.FaoInstitute"%>
-
+
"> -
-
-
-
- +
@@ -25,8 +21,14 @@ "> + + + "> + + + - +
-- GitLab