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
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());
......
......@@ -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());
......
......@@ -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;
}
}
......@@ -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;
}
}
......@@ -71,12 +71,8 @@
<td class="notimportant"><spring:message code="accession.holdingInstitute" /></td>
</c:if>
<c:if test="${section eq 'article'}">
<td>Body</td>
<td>Summary</td>
</c:if>
<c:if test="${section eq 'activitypost'}">
<td>Body</td>
<td>Title</td>
</c:if>
<c:if test="${section eq 'country'}">
</c:if>
......@@ -104,9 +100,15 @@
<c:when test="${section eq 'institute'}">
<td><mini:institute institute="${unit}" /></td>
</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>
<td>
" ${section} "
<b><c:out value="${section}" /></b>
<a href="<c:url value="${unit.urlToContent}" />">
<c:set var="body" value="${unit.body}" />
<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 @@
<a href="<c:url value="/geo/${country.code3}" />"><c:out
value="${country.code3}" /></a>
</div>
<div class="name">
<div class="title">
<c:out value="${country.getName(pageContext.response.locale)}" />
</div>
</div>
......@@ -9,15 +9,11 @@
type="org.genesys2.server.model.impl.FaoInstitute"%>
<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
value="${institute.code}" /></a>
</div>
<div class="fullName">
<c:out value="${institute.fullName}" />
</div>
<div class="acronym">
<c:out value="${institute.acronym}" />
<span class="acronym"><c:out value="${institute.acronym}" /></span>
</div>
<div class="accessionCount">
<c:choose>
......@@ -25,8 +21,14 @@
<spring:message code="faoInstitutes.stat.accessionCount" />
<a href="<c:url value="/wiews/${institute.code}/data" />"><fmt:formatNumber value="${institute.accessionCount}" /></a>
</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>
<spring:message code="faoInstitute.no-accessions-registered" />
</c:otherwise>
</c:choose>
</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