Fixing page index on lucene based tabs. NIHVIVO-1143

Conflicts:

	webapp/src/edu/cornell/mannlib/vitro/webapp/controller/TabEntitiesController.java
	webapp/web/templates/entity/entityListForTabs.jsp
This commit is contained in:
bdc34 2010-10-06 20:54:29 +00:00
parent a83ea26a7b
commit c3cb7b05a2
3 changed files with 144 additions and 107 deletions

View file

@ -1,9 +1,9 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller;
package edu.cornell.mannlib.vitro.webapp.controller;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -39,86 +39,86 @@ import edu.cornell.mannlib.vitro.webapp.search.lucene.LuceneIndexFactory;
import edu.cornell.mannlib.vitro.webapp.search.lucene.LuceneIndexer;
import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils;
import edu.cornell.mannlib.vitro.webapp.web.TabWebUtil;
/**
* Produces the entity lists for tabs.
*
* @author bdc34
*
*/
public class TabEntitiesController extends VitroHttpServlet {
private static final long serialVersionUID = -5340982482787800013L;
private static final Log log = LogFactory.getLog(TabEntitiesController.class.getName());
public static int TAB_DEPTH_CUTOFF = 3;
/**
* Produces the entity lists for tabs.
*
* @author bdc34
*
*/
public class TabEntitiesController extends VitroHttpServlet {
private static final long serialVersionUID = -5340982482787800013L;
private static final Log log = LogFactory.getLog(TabEntitiesController.class.getName());
public static int TAB_DEPTH_CUTOFF = 3;
public static int MAX_PAGES = 40; //must be even
public static int DEFAULT_NUMBER_INDIVIDUALS_ON_TAB = 8;
private static int MAX_RESULTS=40000;
private static int NON_PAGED_LIMIT=1000;
private static Random random = new Random();
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
/***********************************************
Display a set of entities for a tab, these entities
may be manually linked, auto-linked, a mix of these two,
or a gallery.
request.attributes
a Tab object for the tabId must be in the attributes.
It should have the key
request.parameters
"tabId" id of the tab to do entities for
"tabDepth" String that is the depth of the tab in the display for
which we are doing entities.
leadingTab = 1, child of leadingTab = 2, etc.
"alpha" if set to a letter entities will be filtered
to have only that initial.
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
/***********************************************
Display a set of entities for a tab, these entities
may be manually linked, auto-linked, a mix of these two,
or a gallery.
request.attributes
a Tab object for the tabId must be in the attributes.
It should have the key
request.parameters
"tabId" id of the tab to do entities for
"tabDepth" String that is the depth of the tab in the display for
which we are doing entities.
leadingTab = 1, child of leadingTab = 2, etc.
"alpha" if set to a letter entities will be filtered
to have only that initial.
bdc34 2006-01-12 created
bdc34 2010-09-17 modified to use lucene for some tasks.
*/
public void doGet( HttpServletRequest req, HttpServletResponse response )
throws IOException, ServletException {
bdc34 2010-09-17 modified to use lucene for some tasks.
*/
public void doGet( HttpServletRequest req, HttpServletResponse response )
throws IOException, ServletException {
super.doGet(req,response);
try{
VitroRequest request = new VitroRequest(req);
try{
VitroRequest request = new VitroRequest(req);
TabDao tabDao = request.getWebappDaoFactory().getTabDao();
int depth = getTabDepth(request);
if( depth >= TAB_DEPTH_CUTOFF){
String tabId = request.getParameter("tabId");
log.debug("\ttab "+tabId+" is at, "+ depth+" below "+ TAB_DEPTH_CUTOFF);
return;
}
String tabId = request.getParameter("tabId");
if( tabId == null ){
String e="TabEntitiesController expects that request parameter 'tabId' be set";
throw new ServletException(e);
}
Tab tab = TabWebUtil.findStashedTab(tabId,request);
if( tab == null ){
String e="TabEntitiesController expects that tab"+tabId+" will be in the request attribute. "
+"It should have been placed there by a call to TabWebUtil.stashTabsInRequest in tabPrimary.jsp";
throw new ServletException(e);
int depth = getTabDepth(request);
if( depth >= TAB_DEPTH_CUTOFF){
String tabId = request.getParameter("tabId");
log.debug("\ttab "+tabId+" is at, "+ depth+" below "+ TAB_DEPTH_CUTOFF);
return;
}
String tabId = request.getParameter("tabId");
if( tabId == null ){
String e="TabEntitiesController expects that request parameter 'tabId' be set";
throw new ServletException(e);
}
Tab tab = TabWebUtil.findStashedTab(tabId,request);
if( tab == null ){
String e="TabEntitiesController expects that tab"+tabId+" will be in the request attribute. "
+"It should have been placed there by a call to TabWebUtil.stashTabsInRequest in tabPrimary.jsp";
throw new ServletException(e);
}
req.setAttribute("tabId", tab.getTabId());
request.setAttribute("controllerParam","primary=" + tab.getTabId());
String alpha = request.getParameter("alpha");
boolean doAlphaFilter = false;
if(( alpha != null && alpha.length() == 1) ){
String alpha = request.getParameter("alpha");
boolean doAlphaFilter = false;
if(( alpha != null && alpha.length() == 1) ){
doAlphaFilter = true;
request.setAttribute("alpha", alpha.toUpperCase());
request.setAttribute("alpha", alpha.toUpperCase());
}
boolean doPagedFilter = request.getParameter("page") != null;
@ -180,13 +180,14 @@ public void doGet( HttpServletRequest req, HttpServletResponse response )
log.debug("TabEntitiesController: doing none for tabtypeid: "
+ tab.getTabtypeId() +" and link mode: " + tab.getEntityLinkMethod());
}
} catch (Throwable e) {
req.setAttribute("javax.servlet.jsp.jspException",e);
RequestDispatcher rd = req.getRequestDispatcher("/error.jsp");
rd.include(req, response);
}
}
} catch (Throwable e) {
req.setAttribute("javax.servlet.jsp.jspException",e);
RequestDispatcher rd = req.getRequestDispatcher("/error.jsp");
rd.include(req, response);
}
}
/**
* This build a lucene query for the tab, runs the query, gets individuals for that query,
@ -337,22 +338,22 @@ public void doGet( HttpServletRequest req, HttpServletResponse response )
return query;
}
private void doAlphaFiltered(String alpha, Tab tab,
VitroRequest request, HttpServletResponse response, TabDao tabDao, int size)
private void doAlphaFiltered(String alpha, Tab tab,
VitroRequest request, HttpServletResponse response, TabDao tabDao, int size)
throws ServletException, IOException {
log.debug("in doAlphaFitlered");
request.setAttribute("entities", tab.getRelatedEntities());
request.setAttribute("alpha", alpha);
request.setAttribute("count", Integer.toString(size) );
request.setAttribute("entities", tab.getRelatedEntities());
request.setAttribute("alpha", alpha);
request.setAttribute("count", Integer.toString(size) );
request.setAttribute("tabParam",tab.getTabDepthName()+"="+tab.getTabId());
request.setAttribute("letters",Controllers.getLetters());
//request.setAttribute("letters",tab.grabEntityFactory().getLettersOfEnts());
request.setAttribute("servlet",Controllers.TAB);
String jsp = Controllers.ENTITY_LIST_FOR_TABS_JSP;
RequestDispatcher rd =
request.getRequestDispatcher(jsp);
rd.include(request, response);
request.setAttribute("letters",Controllers.getLetters());
//request.setAttribute("letters",tab.grabEntityFactory().getLettersOfEnts());
request.setAttribute("servlet",Controllers.TAB);
String jsp = Controllers.ENTITY_LIST_FOR_TABS_JSP;
RequestDispatcher rd =
request.getRequestDispatcher(jsp);
rd.include(request, response);
}
private void doAutoLinked(Tab tab, VitroRequest request, HttpServletResponse response, TabDao tabDao, int size)
@ -369,8 +370,7 @@ public void doGet( HttpServletRequest req, HttpServletResponse response )
request.getRequestDispatcher(jsp);
rd.include(request, response);
}
private int getPage(VitroRequest request) {
String p = request.getParameter("page") ;
if( p == null )
@ -380,7 +380,7 @@ public void doGet( HttpServletRequest req, HttpServletResponse response )
}catch(Exception e){
return 1;
}
}
}
/**
* Mixed and auto linked tabs get their individuals via
@ -494,20 +494,20 @@ public void doGet( HttpServletRequest req, HttpServletResponse response )
}
}
private int getSizeForGalleryTab(Tab tab){
private int getSizeForGalleryTab(Tab tab){
int rows = tab.getGalleryRows() != 0 ? tab.getGalleryRows() : 8;
int col = tab.getGalleryCols() != 0 ? tab.getGalleryCols() : 8;
return rows * col;
}
private int getSizeForNonGalleryTab(Tab tab, boolean showPaged ){
if( showPaged )
if( tab.getGalleryCols() == 0 || tab.getGalleryRows() == 0 )
return 8;
else
return getSizeForGalleryTab(tab);
else
return NON_PAGED_LIMIT;
}
private int getSizeForNonGalleryTab(Tab tab, boolean showPaged ){
if( showPaged )
if( tab.getGalleryCols() == 0 || tab.getGalleryRows() == 0 )
return 8;
else
return getSizeForGalleryTab(tab);
else
return NON_PAGED_LIMIT;
}
private int getTabDepth(VitroRequest request){
@ -587,5 +587,5 @@ public void doGet( HttpServletRequest req, HttpServletResponse response )
public boolean getSelected(){
return selected;
}
}
}
}
}

View file

@ -55,9 +55,12 @@ public class LuceneIndexFactory {
/**
* This method can be used to force the LuceneIndexFactory to return a new IndexSearcher.
* This will force a re-opening of the search index.
*
* This could be useful if the index was rebult in a different directory on the file system.
*/
public synchronized void forceNewIndexSearcher(){
log.debug("forcing the re-opening of the search index");
searcher = null;
}

View file

@ -89,6 +89,40 @@
</c:choose>
</li>
</c:forEach>
<<<<<<< HEAD:webapp/web/templates/entity/entityListForTabs.jsp
</ul>
=======
</ul>
<%-- 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 ="primary">${requestScope.tabId}</c:param>
<c:param name="page">${page.index}</c:param>
<c:if test="${not empty requestScope.pageAlpha}">
<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}">${page.text} </a>
</c:if>
</c:forEach>
</div>
</c:if>
>>>>>>> c91e65e... Fixing page index on lucene based tabs. NIHVIVO-1143:webapp/web/templates/entity/entityListForTabs.jsp