Commit cf10361f authored by Matija Obreza's avatar Matija Obreza

Full-text search: update display of articles, posts, countries and institutes

parent c38258c5
...@@ -193,6 +193,10 @@ public class FullTextSearchServiceImpl implements FullTextSearchService, Initial ...@@ -193,6 +193,10 @@ public class FullTextSearchServiceImpl implements FullTextSearchService, Initial
return instituteRepository.findOne(id); return instituteRepository.findOne(id);
} else if (Country.class.getName().equals(className)) { } else if (Country.class.getName().equals(className)) {
return countryRepository.findOne(id); 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 { } else {
throw new UnsupportedOperationException("Missing toEntity implementation for class=" + className); throw new UnsupportedOperationException("Missing toEntity implementation for class=" + className);
} }
...@@ -460,7 +464,6 @@ public class FullTextSearchServiceImpl implements FullTextSearchService, Initial ...@@ -460,7 +464,6 @@ public class FullTextSearchServiceImpl implements FullTextSearchService, Initial
// FIXME Should not include articles that belong to institutes or // FIXME Should not include articles that belong to institutes or
// countries // countries
final Article article = (Article) model; final Article article = (Article) model;
document.setClassPK(article.getClassPk());
document.setBody(article.getBody()); document.setBody(article.getBody());
document.setSummary(article.getSummary()); document.setSummary(article.getSummary());
document.setLanguage(article.getLang()); document.setLanguage(article.getLang());
...@@ -469,19 +472,19 @@ public class FullTextSearchServiceImpl implements FullTextSearchService, Initial ...@@ -469,19 +472,19 @@ public class FullTextSearchServiceImpl implements FullTextSearchService, Initial
document.setUrlToContent("/content/" + article.getSlug()); document.setUrlToContent("/content/" + article.getSlug());
} else if (model instanceof ActivityPost) { } else if (model instanceof ActivityPost) {
updateDocumentForCountry((ActivityPost) model, document); updateDocument((ActivityPost) model, document);
} else if (model instanceof Country) { } else if (model instanceof Country) {
updateDocumentForCountry((Country) model, document); updateDocument((Country) model, document);
} else if (model instanceof FaoInstitute) { } else if (model instanceof FaoInstitute) {
updateDocumentForFaoInstitute((FaoInstitute) model, document); updateDocument((FaoInstitute) model, document);
} }
return document; return document;
} }
private void updateDocumentForCountry(ActivityPost activityPost, FullTextDocument document) { private void updateDocument(ActivityPost activityPost, FullTextDocument document) {
document.setBody(activityPost.getBody()); document.setBody(activityPost.getBody());
document.setSummary(activityPost.getTitle()); document.setSummary(activityPost.getTitle());
document.setCreatedDate(activityPost.getCreatedDate()); document.setCreatedDate(activityPost.getCreatedDate());
...@@ -489,7 +492,7 @@ public class FullTextSearchServiceImpl implements FullTextSearchService, Initial ...@@ -489,7 +492,7 @@ public class FullTextSearchServiceImpl implements FullTextSearchService, Initial
document.setUrlToContent("/content/news/" + activityPost.getId() + "/" + this.jspHelper.suggestUrlForText(activityPost.getTitle())); 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.setUrlToContent("/geo/" + country.getCode3());
document.setLanguage(contentService.getDefaultLocale().getLanguage()); document.setLanguage(contentService.getDefaultLocale().getLanguage());
document.setSummary(country.getCode3() + " " + country.getNameL()); document.setSummary(country.getCode3() + " " + country.getNameL());
...@@ -500,7 +503,7 @@ public class FullTextSearchServiceImpl implements FullTextSearchService, Initial ...@@ -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.setUrlToContent("/wiews/" + institute.getCode());
document.setLanguage(contentService.getDefaultLocale().getLanguage()); document.setLanguage(contentService.getDefaultLocale().getLanguage());
document.setSummary(institute.getCode() + " " + institute.getAcronym() + " " + institute.getFullName()); document.setSummary(institute.getCode() + " " + institute.getAcronym() + " " + institute.getFullName());
......
...@@ -24,6 +24,8 @@ import org.apache.commons.lang.ArrayUtils; ...@@ -24,6 +24,8 @@ import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.ClassPK;
import org.genesys2.server.model.impl.Country; import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute; import org.genesys2.server.model.impl.FaoInstitute;
...@@ -142,10 +144,14 @@ public class SearchController { ...@@ -142,10 +144,14 @@ public class SearchController {
@RequestMapping("/acn/search2") @RequestMapping("/acn/search2")
public String findFullTextDocument(ModelMap model, @RequestParam(required = false, value = "q") String searchQuery, public String findFullTextDocument(ModelMap model, @RequestParam(required = false, value = "q") String searchQuery,
@RequestParam(value = "page", required = true, defaultValue = "1") int page, @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); ClassPK classPK = contentService.getClassPk(section);
if (classPK == null) { if (classPK == null && ! "accession".equals(section)) {
LOG.warn("No search section " + section); LOG.warn("No search section " + section);
throw new SearchException("No such search section"); throw new SearchException("No such search section");
} }
...@@ -160,8 +166,13 @@ public class SearchController { ...@@ -160,8 +166,13 @@ public class SearchController {
model.addAttribute("pagedData", fullTextSearchService.search(searchQuery, new PageRequest(page - 1, 50), FaoInstitute.class)); model.addAttribute("pagedData", fullTextSearchService.search(searchQuery, new PageRequest(page - 1, 50), FaoInstitute.class));
} else if ("country".equals(section)) { } else if ("country".equals(section)) {
model.addAttribute("pagedData", fullTextSearchService.search(searchQuery, new PageRequest(page - 1, 50), Country.class)); 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 { } 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) { } catch (SearchException e) {
LOG.info("Searching for: " + searchQuery + " failed with error " + e.getMessage()); LOG.info("Searching for: " + searchQuery + " failed with error " + e.getMessage());
......
...@@ -2487,3 +2487,20 @@ div[x-href] { ...@@ -2487,3 +2487,20 @@ div[x-href] {
.dropdown-menu.view-columns li { .dropdown-menu.view-columns li {
padding: 0 10px; 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;
}
}
...@@ -653,4 +653,26 @@ span.idx-col { ...@@ -653,4 +653,26 @@ span.idx-col {
img { img {
width: 100%; 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;
}
}
...@@ -71,12 +71,8 @@ ...@@ -71,12 +71,8 @@
<td class="notimportant"><spring:message code="accession.holdingInstitute" /></td> <td class="notimportant"><spring:message code="accession.holdingInstitute" /></td>
</c:if> </c:if>
<c:if test="${section eq 'article'}"> <c:if test="${section eq 'article'}">
<td>Body</td>
<td>Summary</td>
</c:if> </c:if>
<c:if test="${section eq 'activitypost'}"> <c:if test="${section eq 'activitypost'}">
<td>Body</td>
<td>Title</td>
</c:if> </c:if>
<c:if test="${section eq 'country'}"> <c:if test="${section eq 'country'}">
</c:if> </c:if>
...@@ -104,9 +100,15 @@ ...@@ -104,9 +100,15 @@
<c:when test="${section eq 'institute'}"> <c:when test="${section eq 'institute'}">
<td><mini:institute institute="${unit}" /></td> <td><mini:institute institute="${unit}" /></td>
</c:when> </c:when>
<c:when test="${section eq 'article'}">
<td><mini:article article="${unit}" /></td>
</c:when>
<c:when test="${section eq 'activitypost'}">
<td><mini:activitypost activityPost="${unit}" /></td>
</c:when>
<c:otherwise> <c:otherwise>
<td> <td>
" ${section} " <b><c:out value="${section}" /></b>
<a href="<c:url value="${unit.urlToContent}" />"> <a href="<c:url value="${unit.urlToContent}" />">
<c:set var="body" value="${unit.body}" /> <c:set var="body" value="${unit.body}" />
<c:if test="${fn:length(body) > 100}"> <c:if test="${fn:length(body) > 100}">
......
<%@ 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"%>
<div class="genesys-mini genesy-post">
<div class="title">
<c:out escapeXml="false" value="${activityPost.title}" />
</div>
<div class="url">
<a
href="<c:url value="/content/news/${activityPost.id}/${jspHelper.suggestUrlForText(activityPost.title)}" />">
<c:url
value="/content/news/${activityPost.id}/${jspHelper.suggestUrlForText(activityPost.title)}" />
</a>
</div>
<div class="summary free-text">
<c:out escapeXml="false" value="${activityPost.body}" />
</div>
</div>
<%@ 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"%>
<div class="genesys-mini genesy-article">
<div class="title">
<a href="<c:url value="/${article.lang}/content/${article.slug}" />">
<c:out value="${article.title}" />
</a>
</div>
<div class="summary free-text">
<c:out escapeXml="false" value="${article.summary}" />
</div>
<div class="language">
<em><c:out value="${article.lang}" /></em>
</div>
</div>
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<a href="<c:url value="/geo/${country.code3}" />"><c:out <a href="<c:url value="/geo/${country.code3}" />"><c:out
value="${country.code3}" /></a> value="${country.code3}" /></a>
</div> </div>
<div class="name"> <div class="title">
<c:out value="${country.getName(pageContext.response.locale)}" /> <c:out value="${country.getName(pageContext.response.locale)}" />
</div> </div>
</div> </div>
...@@ -9,15 +9,11 @@ ...@@ -9,15 +9,11 @@
type="org.genesys2.server.model.impl.FaoInstitute"%> type="org.genesys2.server.model.impl.FaoInstitute"%>
<div class="genesys-mini genesys-institute"> <div class="genesys-mini genesys-institute">
<div class="code"> <div class="title ${institute.current ? '' : 'not-current'}">
<a href="<c:url value="/wiews/${institute.code}" />"><c:out <a href="<c:url value="/wiews/${institute.code}" />"><c:out
value="${institute.code}" /></a> value="${institute.code}" /></a>
</div>
<div class="fullName">
<c:out value="${institute.fullName}" /> <c:out value="${institute.fullName}" />
</div> <span class="acronym"><c:out value="${institute.acronym}" /></span>
<div class="acronym">
<c:out value="${institute.acronym}" />
</div> </div>
<div class="accessionCount"> <div class="accessionCount">
<c:choose> <c:choose>
...@@ -25,8 +21,14 @@ ...@@ -25,8 +21,14 @@
<spring:message code="faoInstitutes.stat.accessionCount" /> <spring:message code="faoInstitutes.stat.accessionCount" />
<a href="<c:url value="/wiews/${institute.code}/data" />"><fmt:formatNumber value="${institute.accessionCount}" /></a> <a href="<c:url value="/wiews/${institute.code}/data" />"><fmt:formatNumber value="${institute.accessionCount}" /></a>
</c:when> </c:when>
<c:when test="${! institute.current}">
<!-- Link to active -->
<a href="<c:url value="/wiews/${faoInstitute.vCode}" />">
<spring:message code="faoInstitute.view-current-institute" arguments="${institute.vCode}" />
</a>
</c:when>
<c:otherwise> <c:otherwise>
<spring:message code="faoInstitute.no-accessions-registered" />
</c:otherwise> </c:otherwise>
</c:choose> </c:choose>
</div> </div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment