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

View file

@ -89,6 +89,40 @@
</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 --%>
<%
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