NIHVIVO-2449 Display mostSpecificTypes in search results in place of moniker. Create new template model class for individual in search results, since the display increasingly diverges from the individualList display.

This commit is contained in:
ryounes 2011-07-05 22:00:10 +00:00
parent 1d1edb17b8
commit 1c52d91b08
9 changed files with 95 additions and 41 deletions

View file

@ -414,9 +414,10 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
DatasetWrapper w = dwf.getDatasetWrapper(); DatasetWrapper w = dwf.getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
QueryExecution qexec = null;
try { try {
QueryExecution qexec = QueryExecutionFactory.create(query, dataset); qexec = QueryExecutionFactory.create(query, dataset);
ResultSet results = qexec.execSelect(); ResultSet results = qexec.execSelect();
while (results.hasNext()) { while (results.hasNext()) {
QuerySolution soln = results.nextSolution(); QuerySolution soln = results.nextSolution();
@ -431,6 +432,9 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
} finally { } finally {
dataset.getLock().leaveCriticalSection(); dataset.getLock().leaveCriticalSection();
if (qexec != null) {
qexec.close();
}
w.close(); w.close();
} }

View file

@ -358,7 +358,7 @@ public class PagedSearchController extends FreemarkerHttpServlet implements Sear
// Convert search result individuals to template model objects // Convert search result individuals to template model objects
body.put("individuals", ListedIndividualTemplateModel body.put("individuals", ListedIndividualTemplateModel
.getIndividualTemplateModelList(beans, vreq)); .getIndividualTemplateModels(beans, vreq));
body.put("querytext", qtxt); body.put("querytext", qtxt);
body.put("title", qtxt + " - " + appBean.getApplicationName() body.put("title", qtxt + " - " + appBean.getApplicationName()

View file

@ -52,6 +52,7 @@ import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQuery;
import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQueryFactory; import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQueryFactory;
import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.LinkTemplateModel; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.LinkTemplateModel;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualSearchResult;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ListedIndividualTemplateModel; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ListedIndividualTemplateModel;
import freemarker.template.Configuration; import freemarker.template.Configuration;
@ -301,11 +302,8 @@ public class SolrPagedSearchController extends FreemarkerHttpServlet {
} }
} }
// Convert search result individuals to template model objects body.put("individuals", IndividualSearchResult
// RY If this diverges significantly from what's used on the index page, .getIndividualTemplateModels(individuals, vreq));
// create a different template model.
body.put("individuals", ListedIndividualTemplateModel
.getIndividualTemplateModelList(individuals, vreq));
body.put("querytext", qtxt); body.put("querytext", qtxt);
body.put("title", qtxt + " - " + appBean.getApplicationName() body.put("title", qtxt + " - " + appBean.getApplicationName()

View file

@ -154,7 +154,6 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
return opsDao.getMostSpecificTypesForIndividual(getUri()); return opsDao.getMostSpecificTypesForIndividual(getUri());
} }
public String getUri() { public String getUri() {
return individual.getURI(); return individual.getURI();
} }

View file

@ -0,0 +1,64 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.web.ViewFinder;
import edu.cornell.mannlib.vitro.webapp.web.ViewFinder.ClassView;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
public class IndividualSearchResult extends BaseTemplateModel {
private static final Log log = LogFactory.getLog(IndividualSearchResult.class);
protected Individual individual;
protected VitroRequest vreq;
public IndividualSearchResult(Individual individual, VitroRequest vreq) {
this.individual = individual;
this.vreq = vreq;
}
private String getView(ClassView view) {
ViewFinder vf = new ViewFinder(view);
return vf.findClassView(individual, vreq);
}
public static List<IndividualSearchResult> getIndividualTemplateModels(List<Individual> individuals, VitroRequest vreq) {
List<IndividualSearchResult> models = new ArrayList<IndividualSearchResult>(individuals.size());
for (Individual individual : individuals) {
models.add(new IndividualSearchResult(individual, vreq));
}
return models;
}
/* Access methods for templates */
public String getProfileUrl() {
return UrlBuilder.getIndividualProfileUrl(individual, vreq.getWebappDaoFactory());
}
public String getName() {
return individual.getName();
}
public List<String> getMostSpecificTypes() {
ObjectPropertyStatementDao opsDao = vreq.getWebappDaoFactory().getObjectPropertyStatementDao();
return opsDao.getMostSpecificTypesForIndividual(individual.getURI());
}
public String getSearchView() {
return getView(ClassView.SEARCH);
}
}

View file

@ -21,22 +21,16 @@ import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
public class ListedIndividualTemplateModel extends BaseTemplateModel { public class ListedIndividualTemplateModel extends BaseTemplateModel {
private static final Log log = LogFactory.getLog(ListedIndividualTemplateModel.class); private static final Log log = LogFactory.getLog(ListedIndividualTemplateModel.class);
private static final String PATH = Route.INDIVIDUAL.path();
protected Individual individual; protected Individual individual;
protected VitroRequest vreq; protected VitroRequest vreq;
protected UrlBuilder urlBuilder;
public ListedIndividualTemplateModel(Individual individual, VitroRequest vreq) { public ListedIndividualTemplateModel(Individual individual, VitroRequest vreq) {
this.individual = individual; this.individual = individual;
this.vreq = vreq; this.vreq = vreq;
// Needed for getting portal-sensitive urls. Remove if multi-portal support is removed.
this.urlBuilder = new UrlBuilder(vreq.getAppBean());
} }
public static List<ListedIndividualTemplateModel> getIndividualTemplateModelList(List<Individual> individuals, VitroRequest vreq) { public static List<ListedIndividualTemplateModel> getIndividualTemplateModels(List<Individual> individuals, VitroRequest vreq) {
List<ListedIndividualTemplateModel> models = new ArrayList<ListedIndividualTemplateModel>(individuals.size()); List<ListedIndividualTemplateModel> models = new ArrayList<ListedIndividualTemplateModel>(individuals.size());
for (Individual individual : individuals) { for (Individual individual : individuals) {
models.add(new ListedIndividualTemplateModel(individual, vreq)); models.add(new ListedIndividualTemplateModel(individual, vreq));
@ -44,11 +38,6 @@ public class ListedIndividualTemplateModel extends BaseTemplateModel {
return models; return models;
} }
private String getView(ClassView view) {
ViewFinder vf = new ViewFinder(view);
return vf.findClassView(individual, vreq);
}
/* Access methods for templates */ /* Access methods for templates */
public String getProfileUrl() { public String getProfileUrl() {
@ -105,18 +94,8 @@ public class ListedIndividualTemplateModel extends BaseTemplateModel {
return individual.getName(); return individual.getName();
} }
@Deprecated
public String getMoniker() {
return "";
// return individual.getMoniker();
}
public String getUri() { public String getUri() {
return individual.getURI(); return individual.getURI();
} }
public String getSearchView() {
return getView(ClassView.SEARCH);
}
} }

View file

@ -49,4 +49,16 @@ a:visited span.SearchTerm {
/* Search tips */ /* Search tips */
div.searchTips li { div.searchTips li {
line-height: 2em; line-height: 2em;
} }
/* Search results */
.most-specific-type {
font-size: .825em;
color: #5e6363;
border-left: 1px solid #A6B1B0;
padding-left: .35em;
padding-right: .35em;
}
*/

View file

@ -2,9 +2,8 @@
<#-- Default individual search view --> <#-- Default individual search view -->
<a href="${individual.profileUrl}">${individual.name}</a> <#import "lib-properties.ftl" as p>
<#-- <#if individual.moniker?has_content> | ${individual.moniker}</#if> -->
<#if individual.description?has_content> <a href="${individual.profileUrl}">${individual.name}</a>
<div class="searchFragment">${individual.description}</div>
</#if> <@p.mostSpecificTypes individual />

View file

@ -249,8 +249,7 @@ name will be used as the label. -->
<#-- Most specific types --> <#-- Most specific types -->
<#macro mostSpecificTypes individual> <#macro mostSpecificTypes individual>
<#local types = individual.mostSpecificTypes /> <#list individual.mostSpecificTypes as type>
<#list types as type>
<span class="most-specific-type">${type}</span> <span class="most-specific-type">${type}</span>
</#list> </#list>
</#macro> </#macro>