Addding paged resutls to index pages. NIHVIVO-1145
This commit is contained in:
parent
23bc237950
commit
c08c2fba9b
6 changed files with 215 additions and 47 deletions
|
@ -26,7 +26,7 @@ public class Controllers {
|
||||||
|
|
||||||
public static final String ENTITY = "/entity";
|
public static final String ENTITY = "/entity";
|
||||||
public static final String ENTITY_PROP_LIST = "/entityPropList";
|
public static final String ENTITY_PROP_LIST = "/entityPropList";
|
||||||
public static final String ENTITY_LIST = "/EntityList";
|
public static final String ENTITY_LIST = "/entitylist";
|
||||||
|
|
||||||
public static final String BROWSE_CONTROLLER = "browsecontroller";
|
public static final String BROWSE_CONTROLLER = "browsecontroller";
|
||||||
public static final String RETRY_URL = "editForm";
|
public static final String RETRY_URL = "editForm";
|
||||||
|
|
|
@ -2,24 +2,47 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller;
|
package edu.cornell.mannlib.vitro.webapp.controller;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import java.io.IOException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
import java.net.URLEncoder;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
import java.util.ArrayList;
|
||||||
import edu.cornell.mannlib.vitro.webapp.flags.FlagException;
|
import java.util.List;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.jsptags.InputElementFormattingTag;
|
|
||||||
|
|
||||||
import javax.servlet.RequestDispatcher;
|
import javax.servlet.RequestDispatcher;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
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.apache.lucene.document.Document;
|
||||||
|
import org.apache.lucene.index.Term;
|
||||||
|
import org.apache.lucene.search.BooleanClause;
|
||||||
|
import org.apache.lucene.search.BooleanQuery;
|
||||||
|
import org.apache.lucene.search.IndexSearcher;
|
||||||
|
import org.apache.lucene.search.PrefixQuery;
|
||||||
|
import org.apache.lucene.search.Query;
|
||||||
|
import org.apache.lucene.search.ScoreDoc;
|
||||||
|
import org.apache.lucene.search.Sort;
|
||||||
|
import org.apache.lucene.search.TermQuery;
|
||||||
|
import org.apache.lucene.search.TopDocs;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.TabEntitiesController.PageRecord;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.flags.FlagException;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.search.lucene.LuceneIndexFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils;
|
||||||
|
|
||||||
public class EntityListController extends VitroHttpServlet {
|
public class EntityListController extends VitroHttpServlet {
|
||||||
|
|
||||||
|
public static final int ENTITY_LIST_CONTROLLER_MAX_RESULTS = 30000;
|
||||||
|
public static final int INDIVIDUALS_PER_PAGE = 30;
|
||||||
|
|
||||||
long startTime = -1;
|
long startTime = -1;
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(EntityListController.class.getName());
|
private static final Log log = LogFactory.getLog(EntityListController.class.getName());
|
||||||
|
@ -47,7 +70,6 @@ public class EntityListController extends VitroHttpServlet {
|
||||||
String vitroClassIdStr=req.getParameter("vclassId");
|
String vitroClassIdStr=req.getParameter("vclassId");
|
||||||
if (vitroClassIdStr!=null && !vitroClassIdStr.equals("")) {
|
if (vitroClassIdStr!=null && !vitroClassIdStr.equals("")) {
|
||||||
try {
|
try {
|
||||||
//TODO have to change this so vclass's group and entity count are populated
|
|
||||||
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vitroClassIdStr);
|
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vitroClassIdStr);
|
||||||
if (vclass == null) {
|
if (vclass == null) {
|
||||||
log.error("Couldn't retrieve vclass "+vitroClassIdStr);
|
log.error("Couldn't retrieve vclass "+vitroClassIdStr);
|
||||||
|
@ -63,9 +85,12 @@ public class EntityListController extends VitroHttpServlet {
|
||||||
throw new HelpException("EntityListController: attribute 'vclass' must be of type "
|
throw new HelpException("EntityListController: attribute 'vclass' must be of type "
|
||||||
+ VClass.class.getName() );
|
+ VClass.class.getName() );
|
||||||
}
|
}
|
||||||
if (vclass!=null){
|
|
||||||
doVClass(req, res, vclass);
|
if (vclass!=null)
|
||||||
}
|
doVClass(vreq, res, vclass);
|
||||||
|
else
|
||||||
|
log.debug("no vclass found for " + obj);
|
||||||
|
|
||||||
} catch (HelpException help){
|
} catch (HelpException help){
|
||||||
doHelp(res);
|
doHelp(res);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -88,18 +113,79 @@ public class EntityListController extends VitroHttpServlet {
|
||||||
* @throws ServletException
|
* @throws ServletException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private void doVClass(HttpServletRequest request, HttpServletResponse res, VClass vclass)
|
private void doVClass(VitroRequest request, HttpServletResponse res, VClass vclass)
|
||||||
throws ServletException, IOException, FlagException {
|
throws ServletException, IOException, FlagException {
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
IndexSearcher index = LuceneIndexFactory.getIndexSearcher(getServletContext());
|
||||||
|
boolean isSinglePortal = request.getWebappDaoFactory().getPortalDao().isSinglePortal();
|
||||||
|
|
||||||
//get list of entities,
|
Portal portal = request.getPortal();
|
||||||
List<Individual> entities = vreq.getWebappDaoFactory().getIndividualDao().getIndividualsByVClass(vclass);
|
int portalId = 1;
|
||||||
request.setAttribute("entities",entities);
|
if( portal != null )
|
||||||
|
portalId = portal.getPortalId();
|
||||||
|
|
||||||
if (entities == null) {
|
|
||||||
log.error("entities list is null");
|
String alpha = request.getParameter("alpha");
|
||||||
|
int page = getPage(request);
|
||||||
|
IndividualDao indDao = request.getWebappDaoFactory().getIndividualDao();
|
||||||
|
|
||||||
|
//make lucene query for this rdf:type
|
||||||
|
Query query = getQuery(vclass.getURI(),alpha, isSinglePortal, portalId);
|
||||||
|
|
||||||
|
//execute lucene query for individuals of the specified type
|
||||||
|
TopDocs docs = index.search(query, null,
|
||||||
|
ENTITY_LIST_CONTROLLER_MAX_RESULTS,
|
||||||
|
new Sort(Entity2LuceneDoc.term.NAMEUNANALYZED));
|
||||||
|
|
||||||
|
if( docs == null ){
|
||||||
|
log.error("Search of lucene index returned null");
|
||||||
|
throw new ServletException("Search of lucene index returned null");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//get list of individuals for the search results
|
||||||
|
int size = docs.totalHits;
|
||||||
|
// don't get all the results, only get results for the requestedSize
|
||||||
|
List<Individual> individuals = new ArrayList<Individual>(INDIVIDUALS_PER_PAGE);
|
||||||
|
int individualsAdded = 0;
|
||||||
|
int ii = (page-1)*INDIVIDUALS_PER_PAGE;
|
||||||
|
while( individualsAdded < INDIVIDUALS_PER_PAGE && ii < size ){
|
||||||
|
ScoreDoc hit = docs.scoreDocs[ii];
|
||||||
|
if (hit != null) {
|
||||||
|
Document doc = index.doc(hit.doc);
|
||||||
|
if (doc != null) {
|
||||||
|
String uri = doc.getField(Entity2LuceneDoc.term.URI).stringValue();
|
||||||
|
Individual ind = indDao.getIndividualByURI( uri );
|
||||||
|
individuals.add( ind );
|
||||||
|
individualsAdded++;
|
||||||
|
} else {
|
||||||
|
log.warn("no document found for lucene doc id " + hit.doc);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.debug("hit was null");
|
||||||
|
}
|
||||||
|
ii++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
request.setAttribute("servlet",Controllers.ENTITY_LIST);
|
||||||
|
request.setAttribute("vclassId", vclass.getURI());
|
||||||
|
request.setAttribute("controllerParam","vclassId=" + URLEncoder.encode(vclass.getURI(),"UTF-8"));
|
||||||
|
request.setAttribute("count", size);
|
||||||
|
|
||||||
|
if( size > INDIVIDUALS_PER_PAGE ){
|
||||||
|
request.setAttribute("showPages", Boolean.TRUE);
|
||||||
|
List<PageRecord> pageRecords = TabEntitiesController.makePagesList(size, INDIVIDUALS_PER_PAGE, page);
|
||||||
|
request.setAttribute("pages", pageRecords);
|
||||||
|
}
|
||||||
|
request.setAttribute("showAlpha","1");
|
||||||
|
request.setAttribute("letters",Controllers.getLetters());
|
||||||
|
request.setAttribute("alpha",alpha);
|
||||||
|
|
||||||
|
request.setAttribute("totalCount", size);
|
||||||
|
request.setAttribute("entities",individuals);
|
||||||
|
if (individuals == null)
|
||||||
|
log.debug("entities list is null for vclass " + vclass.getURI());
|
||||||
|
|
||||||
|
|
||||||
VClassGroup classGroup=vclass.getGroup();
|
VClassGroup classGroup=vclass.getGroup();
|
||||||
if (classGroup==null) {
|
if (classGroup==null) {
|
||||||
request.setAttribute("title",vclass.getName()/* + " ("+vclass.getEntityCount()+")"*/);
|
request.setAttribute("title",vclass.getName()/* + " ("+vclass.getEntityCount()+")"*/);
|
||||||
|
@ -107,16 +193,9 @@ public class EntityListController extends VitroHttpServlet {
|
||||||
request.setAttribute("title",classGroup.getPublicName());
|
request.setAttribute("title",classGroup.getPublicName());
|
||||||
request.setAttribute("subTitle",vclass.getName()/* + " ("+vclass.getEntityCount()+")"*/);
|
request.setAttribute("subTitle",vclass.getName()/* + " ("+vclass.getEntityCount()+")"*/);
|
||||||
}
|
}
|
||||||
request.setAttribute("bodyJsp",Controllers.ENTITY_LIST_JSP);
|
|
||||||
|
|
||||||
//here you could have a search css
|
|
||||||
//String css = "<style type='text/css' media='screen'>@import '"+thePortal.getThemeDir()+"css/search.css';</style>";
|
|
||||||
//request.setAttribute("css",css);
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
|
||||||
//FINALLY: send off to the BASIC_JSP to get turned into html
|
//FINALLY: send off to the BASIC_JSP to get turned into html
|
||||||
//
|
request.setAttribute("bodyJsp",Controllers.ENTITY_LIST_JSP);
|
||||||
|
|
||||||
RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
|
RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
|
||||||
|
|
||||||
// use this for more direct debugging: RequestDispatcher rd = request.getRequestDispatcher(Controllers.ENTITY_LIST_JSP);
|
// use this for more direct debugging: RequestDispatcher rd = request.getRequestDispatcher(Controllers.ENTITY_LIST_JSP);
|
||||||
|
@ -125,6 +204,62 @@ public class EntityListController extends VitroHttpServlet {
|
||||||
rd.include(request,res);
|
rd.include(request,res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getPage(VitroRequest request) {
|
||||||
|
String pageStr = request.getParameter("page");
|
||||||
|
if( pageStr != null ){
|
||||||
|
try{
|
||||||
|
return Integer.parseInt(pageStr);
|
||||||
|
}catch(NumberFormatException nfe){
|
||||||
|
log.debug("could not parse page parameter");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private BooleanQuery getQuery(String vclassUri, String alpha , boolean isSinglePortal, int portalId){
|
||||||
|
BooleanQuery query = new BooleanQuery();
|
||||||
|
try{
|
||||||
|
//query term for rdf:type
|
||||||
|
query.add(
|
||||||
|
new TermQuery( new Term(Entity2LuceneDoc.term.RDFTYPE, vclassUri)),
|
||||||
|
BooleanClause.Occur.MUST );
|
||||||
|
|
||||||
|
//check for portal filtering
|
||||||
|
if( ! isSinglePortal ){
|
||||||
|
if( portalId < 16 ){ //could be a normal portal
|
||||||
|
query.add(
|
||||||
|
new TermQuery( new Term(Entity2LuceneDoc.term.PORTAL, Integer.toString(1 << portalId ))),
|
||||||
|
BooleanClause.Occur.MUST);
|
||||||
|
}else{ //could be a combined portal
|
||||||
|
BooleanQuery tabQueries = new BooleanQuery();
|
||||||
|
Long[] ids= FlagMathUtils.numeric2numerics(portalId);
|
||||||
|
for( Long id : ids){
|
||||||
|
tabQueries.add(
|
||||||
|
new TermQuery( new Term(Entity2LuceneDoc.term.PORTAL,id.toString()) ),
|
||||||
|
BooleanClause.Occur.SHOULD);
|
||||||
|
}
|
||||||
|
query.add(tabQueries,BooleanClause.Occur.MUST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Add alpha filter if it is needed
|
||||||
|
Query alphaQuery = null;
|
||||||
|
if( alpha != null && !"".equals(alpha) && alpha.length() == 1){
|
||||||
|
alphaQuery =
|
||||||
|
new PrefixQuery(new Term(Entity2LuceneDoc.term.NAMEUNANALYZED, alpha.toLowerCase()));
|
||||||
|
query.add(alphaQuery,BooleanClause.Occur.MUST);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("Query: " + query);
|
||||||
|
return query;
|
||||||
|
}catch (Exception ex){
|
||||||
|
log.error(ex,ex);
|
||||||
|
return new BooleanQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void doHelp(HttpServletResponse res)
|
private void doHelp(HttpServletResponse res)
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller;
|
package edu.cornell.mannlib.vitro.webapp.controller;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
<% /* <p>${pageTime} milliseconds</p> */ %>
|
<% /* <p>${pageTime} milliseconds</p> */ %>
|
||||||
|
|
||||||
|
<jsp:include page="/templates/alpha/alphaIndex.jsp"/>
|
||||||
<ul>
|
<ul>
|
||||||
<c:forEach items='${entities}' var='ent'>
|
<c:forEach items='${entities}' var='ent'>
|
||||||
<li>
|
<li>
|
||||||
|
@ -101,5 +102,7 @@
|
||||||
${requestScope.suppText}
|
${requestScope.suppText}
|
||||||
</c:if>
|
</c:if>
|
||||||
|
|
||||||
|
<jsp:include page="/templates/entity/entityListPages.jsp"/>
|
||||||
|
|
||||||
</div> <!--end contents-->
|
</div> <!--end contents-->
|
||||||
</div><!-- end content -->
|
</div><!-- end content -->
|
|
@ -89,10 +89,6 @@
|
||||||
</c:choose>
|
</c:choose>
|
||||||
</li>
|
</li>
|
||||||
</c:forEach>
|
</c:forEach>
|
||||||
<<<<<<< HEAD:webapp/web/templates/entity/entityListForTabs.jsp
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
=======
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<%-- Show pages to select from --%>
|
<%-- Show pages to select from --%>
|
||||||
|
@ -124,5 +120,6 @@ if( request.getAttribute("alpha") != null && ! "all".equalsIgnoreCase((String)re
|
||||||
</c:forEach>
|
</c:forEach>
|
||||||
</div>
|
</div>
|
||||||
</c:if>
|
</c:if>
|
||||||
>>>>>>> c91e65e... Fixing page index on lucene based tabs. NIHVIVO-1143:webapp/web/templates/entity/entityListForTabs.jsp
|
|
||||||
|
<jsp:include page="/templates/entity/entityListPages.jsp"/>
|
||||||
|
|
||||||
|
|
32
webapp/web/templates/entity/entityListPages.jsp
Normal file
32
webapp/web/templates/entity/entityListPages.jsp
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%><%/* this odd thing points to something in web.xml */ %>
|
||||||
|
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
|
||||||
|
|
||||||
|
<%-- Show pages to select from --%>
|
||||||
|
<%
|
||||||
|
if( request.getAttribute("alpha") != null && ! "all".equalsIgnoreCase((String)request.getAttribute("alpha"))) {
|
||||||
|
request.setAttribute("pageAlpha",request.getAttribute("alpha"));
|
||||||
|
}else{
|
||||||
|
request.setAttribute("pageAlpha",request.getAttribute("all"));
|
||||||
|
}
|
||||||
|
%>
|
||||||
|
|
||||||
|
<c:if test="${ requestScope.showPages }">
|
||||||
|
<div class="searchpages minimumFontMain">
|
||||||
|
|
||||||
|
Pages:
|
||||||
|
<c:forEach items='${requestScope.pages }' var='page'>
|
||||||
|
<c:url var='pageUrl' value=".${requestScope.servlet}">
|
||||||
|
<c:param name="page">${page.index}</c:param>
|
||||||
|
<c:if test="${not empty requestScope.alpha}">
|
||||||
|
<c:param name="alpha">${requestScope.pageAlpha}</c:param>
|
||||||
|
</c:if>
|
||||||
|
</c:url>
|
||||||
|
<c:if test="${ page.selected }">
|
||||||
|
${page.text}
|
||||||
|
</c:if>
|
||||||
|
<c:if test="${ not page.selected }">
|
||||||
|
<a class="minimumFontMain" href="${pageUrl}&${requestScope.controllerParam}">${page.text} </a>
|
||||||
|
</c:if>
|
||||||
|
</c:forEach>
|
||||||
|
</div>
|
||||||
|
</c:if>
|
Loading…
Add table
Reference in a new issue