diff --git a/doc/list_view_configuration_guidelines.txt b/doc/list_view_configuration_guidelines.txt
index 20ac1ce99..97daab064 100644
--- a/doc/list_view_configuration_guidelines.txt
+++ b/doc/list_view_configuration_guidelines.txt
@@ -5,13 +5,16 @@ List view configuration guidelines
REGISTERING THE LIST VIEW
-------------------------
-A custom list view is associated with an object property in the file /vivo/productMods/WEB-INF/ontologies/app/listViewConfig.owl.
-Example:
+A custom list view is associated with an object property in the RDF files in the directory /vivo/productMods/WEB-INF/ontologies/app/loadedAtStartup
+To register a list view, create a new .rdf or .n3 file in that directory. The file must be well formed RDF/XML or N3.
+
+Example of registering a new association in a file named newListViews.n3:
-
- listViewConfig-authorInAuthorship.xml
-
+
+
+ "listViewConfig-authorInAuthorship.xml" .
+Place this file in /vivo/productMods/WEB-INF/ontologies/app/loadedAtStartup, redeploy and restart tomcat to put the new custom list view in effect.
-----------------
REQUIRED ELEMENTS
diff --git a/webapp/ontologies/app/loadedAtStartup/displayModelListViews.rdf b/webapp/ontologies/app/loadedAtStartup/displayModelListViews.rdf
new file mode 100644
index 000000000..4a17524f5
--- /dev/null
+++ b/webapp/ontologies/app/loadedAtStartup/displayModelListViews.rdf
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+]>
+
+
+
+
+
+ listViewConfig-hasElement.xml
+
+
+
\ No newline at end of file
diff --git a/webapp/ontologies/search/vitroSearchProhibited.n3 b/webapp/ontologies/search/vitroSearchProhibited.n3
index 4b79892ac..ba3ed6838 100644
--- a/webapp/ontologies/search/vitroSearchProhibited.n3
+++ b/webapp/ontologies/search/vitroSearchProhibited.n3
@@ -1,23 +1,27 @@
# $This file is distributed under the terms of the license in /doc/license.txt$
-@prefix owl: .
-@prefix vitroDisplay: .
-@prefix rdf: .
-@prefix core: .
-@prefix example: .
-
# All instances of a class can be excluded from the search index
# by adding a vitroDisplay:excludeClass property between
# vitroDisplay:SearchIndex and the URI of the class
# that you would like to exclude.
-# All .n3 files in this directory will be used to configure
-# the search exclusions. Only .n3 files will be loaded.
-#
+# All .n3 or .rdf files in this directory will be used to configure
+# the search exclusions. Each file must be a valid file in the format
+# specified by its extension. Each file will be loaded individually and
+# must be a complete stand alone example of its format. Each file must contain all
+# the necessary prefixes, namespaces and preambles required by the format
+# specified by its extension.
+
# If you would like to add classes to the
# exclusions, add a file to this directory ending in .n3 with
# N3 statements similar to this example.
+#
+# @prefix owl: .
+# @prefix vitroDisplay: .
+# @prefix rdf: .
+# @prefix example: .
+#
# vitroDisplay:SearchIndex
# rdf:type owl:Thing ;
# vitroDisplay:excludeClass example:classToExclude ;
\ No newline at end of file
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/JsonServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/JsonServlet.java
index e0ce72697..8a648f2d6 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/JsonServlet.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/JsonServlet.java
@@ -54,6 +54,7 @@ public class JsonServlet extends VitroHttpServlet {
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(JsonServlet.class);
private static final int REPLY_SIZE = 256;
+ private static final int INDIVIDUALS_PER_PAGE = 30;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
@@ -267,7 +268,7 @@ public class JsonServlet extends VitroHttpServlet {
try {
map = IndividualListController.getResultsForVClassIntersections(
vclassURIs,
- page,
+ page, INDIVIDUALS_PER_PAGE,
alpha,
vreq.getWebappDaoFactory().getIndividualDao(),
context);
@@ -292,17 +293,11 @@ public class JsonServlet extends VitroHttpServlet {
}
public static String getDataPropertyValue(Individual ind, DataProperty dp, WebappDaoFactory wdf){
- List values = wdf.getDataPropertyStatementDao()
- .getDataPropertyValuesForIndividualByProperty(ind, dp);
- if( values == null || values.isEmpty() )
+ String value = ind.getDataValue(dp.getURI());
+ if( value == null || value.isEmpty() )
return "";
- else{
- if( values.get(0) != null )
- return values.get(0).getLexicalForm();
- else
- return "";
- }
-
+ else
+ return value;
}
/**
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java
index 9f11d4b87..12bcaafbf 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java
@@ -6,6 +6,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -40,8 +41,7 @@ public class IndividualListController extends FreemarkerHttpServlet {
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(IndividualListController.class.getName());
-
- private static final int INDIVIDUAL_LIST_CONTROLLER_MAX_RESULTS = 30000;
+
private static final int INDIVIDUALS_PER_PAGE = 30;
private static final int MAX_PAGES = 40; // must be even
@@ -165,22 +165,23 @@ public class IndividualListController extends FreemarkerHttpServlet {
}
}
- //Pulling out common code that is used for both single (regular) vclass query and multiple (intersection) query
- public static Map getResultsForVClasses(List vclassURIs, int page, String alpha, IndividualDao indDao, ServletContext context)
- throws IOException, ServletException{
- Map rvMap = new HashMap();
- try{
- SolrQuery query = getQuery(vclassURIs, alpha);
- rvMap = getResultsForVClassQuery(query, page, alpha, indDao, context);
- List individuals = (List) rvMap.get("entities");
- if (individuals == null)
- log.debug("entities list is null for vclasses " + vclassURIs.toString() );
- } catch(Throwable th) {
- log.error("An error occurred retrieving results for vclass query", th);
- }
- return rvMap;
- }
+// //Pulling out common code that is used for both single (regular) vclass query and multiple (intersection) query
+// public static Map getResultsForVClasses(List vclassURIs, int page, String alpha, IndividualDao indDao, ServletContext context)
+// throws IOException, ServletException{
+// Map rvMap = new HashMap();
+// try{
+// SolrQuery query = getQuery(vclassURIs, alpha, page, INDIVIDUALS_PER_PAGE);
+// rvMap = getResultsForVClassQuery(query, page, alpha, indDao, context);
+// List individuals = (List) rvMap.get("entities");
+// if (individuals == null)
+// log.debug("entities list is null for vclasses " + vclassURIs.toString() );
+// } catch(Throwable th) {
+// log.error("An error occurred retrieving results for vclass query", th);
+// }
+// return rvMap;
+// }
+ @SuppressWarnings("unchecked")
public static Map getResultsForVClass(String vclassURI, int page, String alpha, IndividualDao indDao, ServletContext context)
throws IOException, SearchException{
Map rvMap = new HashMap();
@@ -188,8 +189,8 @@ public class IndividualListController extends FreemarkerHttpServlet {
//make query for this rdf:type
List classUris = new ArrayList();
classUris.add(vclassURI);
- SolrQuery query = getQuery(classUris, alpha);
- rvMap = getResultsForVClassQuery(query, page, alpha, indDao, context);
+ SolrQuery query = getQuery(classUris, alpha, page, INDIVIDUALS_PER_PAGE);
+ rvMap = getResultsForVClassQuery(query, page, INDIVIDUALS_PER_PAGE, alpha, indDao, context);
List individuals = (List) rvMap.get("entities");
if (individuals == null)
log.debug("entities list is null for vclass " + vclassURI );
@@ -204,14 +205,15 @@ public class IndividualListController extends FreemarkerHttpServlet {
return rvMap;
}
- public static Map getResultsForVClassIntersections(List vclassURIs, int page, String alpha, IndividualDao indDao, ServletContext context)
+ @SuppressWarnings("unchecked")
+ public static Map getResultsForVClassIntersections(List vclassURIs, int page, int pageSize, String alpha, IndividualDao indDao, ServletContext context)
throws IOException, ServletException{
Map rvMap = new HashMap();
try{
// make query for multiple rdf types
- SolrQuery query = getQuery(vclassURIs, alpha);
+ SolrQuery query = getQuery(vclassURIs, alpha, page, pageSize);
log.debug("Executed solr query for " + vclassURIs.toString());
- rvMap = getResultsForVClassQuery(query, page, alpha, indDao, context);
+ rvMap = getResultsForVClassQuery(query, page, pageSize, alpha, indDao, context);
List individuals = (List) rvMap.get("entities");
if (individuals == null)
log.debug("entities list is null for vclass " + vclassURIs.toString() );
@@ -225,7 +227,7 @@ public class IndividualListController extends FreemarkerHttpServlet {
* This method is now called in a couple of places. It should be refactored
* into a DAO or similar object.
*/
- public static Map getResultsForVClassQuery(SolrQuery query, int page, String alpha, IndividualDao indDao, ServletContext context)
+ protected static Map getResultsForVClassQuery(SolrQuery query, int page, int pageSize, String alpha, IndividualDao indDao, ServletContext context)
throws IOException, ServletException {
Map rvMap = new HashMap();
SolrServer solr = SolrSetup.getSolrServer(context);
@@ -252,31 +254,26 @@ public class IndividualListController extends FreemarkerHttpServlet {
long hitCount = docs.getNumFound();
log.debug("Number of search results: " + hitCount);
- List individuals = new ArrayList(INDIVIDUALS_PER_PAGE);
- int individualsAdded = 0;
- int index = (page-1) * INDIVIDUALS_PER_PAGE;
- if(docs.size() > 0) {
- while (individualsAdded < INDIVIDUALS_PER_PAGE && index < hitCount) {
- SolrDocument doc = docs.get(index);
+ Iterator docIter = docs.iterator();
+ List individuals = new ArrayList(docs.size());
+
+ while ( docIter.hasNext() ){
+ SolrDocument doc = docIter.next();
if (doc != null) {
String uri = doc.get(VitroSearchTermNames.URI).toString();
Individual individual = indDao.getIndividualByURI( uri );
- if (individual != null) {
- individualsAdded++;
- individuals.add(individual);
+ if (individual != null) {
+ individuals.add( individual );
log.debug("Adding individual " + uri + " to individual list display");
} else {
log.debug("No existing individual for search document with uri = " + uri);
}
- }
- index++;
- }
- } else {
- log.debug("Docs size is 0");
- }
- if ( hitCount > INDIVIDUALS_PER_PAGE ){
+ }
+ }
+
+ if ( hitCount > pageSize ){
rvMap.put("showPages", Boolean.TRUE);
- List pageRecords = makePagesList(hitCount, INDIVIDUALS_PER_PAGE, page);
+ List pageRecords = makePagesList(hitCount, pageSize, page);
rvMap.put("pages", pageRecords);
}else{
rvMap.put("showPages", Boolean.FALSE);
@@ -292,63 +289,71 @@ public class IndividualListController extends FreemarkerHttpServlet {
}
//Get count of individuals without actually getting the results
- public static long getIndividualCount(List vclassUris, IndividualDao indDao, ServletContext context) {
- SolrQuery query = getQuery(vclassUris, null, 0);
- try {
- Map rvMap = getResultsForVClassQuery(query, 1, null, indDao, context);
- Long count = (Long) rvMap.get("totalCount");
- return count.longValue();
+ public static long getIndividualCount(List vclassUris, IndividualDao indDao, ServletContext context) {
+ SolrQuery query = new SolrQuery(makeMultiClassQuery(vclassUris));
+ query.setRows(0);
+ try {
+ SolrServer solr = SolrSetup.getSolrServer(context);
+ QueryResponse response = null;
+ response = solr.query(query);
+ return response.getResults().getNumFound();
} catch(Exception ex) {
log.error("An error occured in retrieving individual count", ex);
}
return 0;
}
- private static SolrQuery getQuery(List vclassUris, String alpha) {
- return getQuery(vclassUris, alpha, INDIVIDUAL_LIST_CONTROLLER_MAX_RESULTS);
- }
-
- private static SolrQuery getQuery(List vclassUris, String alpha, int numberRows){
-
+ /**
+ * builds a query with a type clause for each type in vclassUris, NAME_LOWERCASE filetred by
+ * alpha, and just the hits for the page for pageSize.
+ */
+ private static SolrQuery getQuery(List vclassUris, String alpha, int page, int pageSize){
String queryText = "";
-
- List queryTypes = new ArrayList();
- try {
+
+ try {
+ queryText = makeMultiClassQuery(vclassUris);
- // query term for rdf:type - multiple types possible
- for(String vclassUri: vclassUris) {
- queryTypes.add(VitroSearchTermNames.RDFTYPE + ":\"" + vclassUri + "\" ");
- }
-
- if (queryTypes.size() > 0) {
- queryText = StringUtils.join(queryTypes, " AND ");
- }
-
// Add alpha filter if applicable
if ( alpha != null && !"".equals(alpha) && alpha.length() == 1) {
queryText += VitroSearchTermNames.NAME_LOWERCASE + ":" + alpha.toLowerCase() + "*";
}
SolrQuery query = new SolrQuery(queryText);
- log.debug("Query text is " + queryText);
-
- // Get all available results from index rather than just those for the current page.
- // Otherwise, if there are a large number of non-existent individuals in the search
- // index, the current page of results might not retrieve any existing individuals,
- // and nothing gets returned.
- query.setStart(0)
- .setRows(numberRows)
- // Need a single-valued field for sorting
- .setSortField(VitroSearchTermNames.NAME_LOWERCASE_SINGLE_VALUED, SolrQuery.ORDER.asc);
+ query.setStart( page > 0 ? pageSize * page + 1 : 0 )
+ .setRows( pageSize );
+
+ // Need a single-valued field for sorting
+ query.setSortField(VitroSearchTermNames.NAME_LOWERCASE_SINGLE_VALUED, SolrQuery.ORDER.asc);
+
+ log.debug("Query text is " + queryText);
return query;
} catch (Exception ex){
- log.error(ex,ex);
+ log.error("Could not make Solr query",ex);
return new SolrQuery();
}
}
+ private static String makeMultiClassQuery( List vclassUris){
+ String queryText = "";
+ List queryTypes = new ArrayList();
+ try {
+ // query term for rdf:type - multiple types possible
+ for(String vclassUri: vclassUris) {
+ queryTypes.add(VitroSearchTermNames.RDFTYPE + ":\"" + vclassUri + "\" ");
+ }
+ if (queryTypes.size() > 0) {
+ queryText = StringUtils.join(queryTypes, " AND ");
+ }
+ return queryText;
+ } catch (Exception ex){
+ log.error("Could not make Solr query",ex);
+ return "";
+ }
+ }
+
+
public static List makePagesList( long size, int pageSize, int selectedPage ) {
List records = new ArrayList( MAX_PAGES + 1 );
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/FileBasedProhibitedFromSearch.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/FileBasedProhibitedFromSearch.java
index b72838bc8..45549f9f7 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/FileBasedProhibitedFromSearch.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/FileBasedProhibitedFromSearch.java
@@ -8,6 +8,8 @@ import java.io.FileInputStream;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.ModelFactory;
+import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
+
public class FileBasedProhibitedFromSearch extends ProhibitedFromSearch {
/**
@@ -17,42 +19,12 @@ public class FileBasedProhibitedFromSearch extends ProhibitedFromSearch {
* @param dir to find N3 files in.
*/
public FileBasedProhibitedFromSearch(String uri, File dir){
- super( uri, getModelFromDir(dir));
+ super( uri, JenaDataSourceSetupBase.getModelFromDir(dir));
}
public FileBasedProhibitedFromSearch(String URI, OntModel model) {
super(URI, model);
}
- protected static OntModel getModelFromDir( File dir){
- if( dir == null )
- throw new IllegalStateException("Must pass a File to FileBasedProhibitedFromSearch");
- if( !dir.isDirectory() )
- throw new IllegalStateException("Parameter dir to FileBasedProhibitedFromSearch " +
- "must be a File object for a directory");
- if( !dir.canRead() )
- throw new IllegalStateException("Parameter dir to FileBasedProhibitedFromSearch must " +
- "be a directory that is readable, check premissions on " + dir.getAbsolutePath());
-
- OntModel modelOnlyForPFS = ModelFactory.createOntologyModel();
- for( File file : dir.listFiles()){
- if( file.isFile()
- && file.canRead()
- && file.getName() != null
- && file.getName().endsWith(".n3")){
- try{
- modelOnlyForPFS.read( new FileInputStream(file), null, "N3");
- }catch( Throwable th){
- log.warn("could not load file " +
- file.getAbsolutePath() + file.separator + file.getName(), th);
- }
- }
- }
-
- if( modelOnlyForPFS.size() == 0 ){
- log.warn("No class exclusion statements found.");
- }
-
- return modelOnlyForPFS;
- }
+
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java
index 46826d1ff..f8bb688b1 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java
@@ -11,7 +11,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -24,13 +23,14 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.response.FacetField;
import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.client.solrj.response.FacetField.Count;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
-import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
@@ -51,7 +51,6 @@ 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.solr.SolrSetup;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.LinkTemplateModel;
-import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.BaseListedIndividual;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.searchresult.IndividualSearchResult;
import freemarker.template.Configuration;
@@ -67,8 +66,8 @@ public class PagedSearchController extends FreemarkerHttpServlet {
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(PagedSearchController.class);
- private static final int DEFAULT_HITS_PER_PAGE = 25;
- private static final int DEFAULT_MAX_HIT_COUNT = 1000;
+ protected static final int DEFAULT_HITS_PER_PAGE = 25;
+ protected static final int DEFAULT_MAX_HIT_COUNT = 1000;
private static final String PARAM_XML_REQUEST = "xml";
private static final String PARAM_START_INDEX = "startIndex";
@@ -146,26 +145,8 @@ public class PagedSearchController extends FreemarkerHttpServlet {
log.debug("IndividualDao is " + iDao.toString() + " Public classes in the classgroup are " + grpDao.getPublicGroupsWithVClasses().toString());
log.debug("VClassDao is "+ vclassDao.toString() );
- int startIndex = 0;
- try{
- startIndex = Integer.parseInt(vreq.getParameter(PARAM_START_INDEX));
- }catch (Throwable e) {
- startIndex = 0;
- }
- log.debug("startIndex is " + startIndex);
-
- int hitsPerPage = DEFAULT_HITS_PER_PAGE;
- try{
- hitsPerPage = Integer.parseInt(vreq.getParameter(PARAM_HITS_PER_PAGE));
- } catch (Throwable e) {
- hitsPerPage = DEFAULT_HITS_PER_PAGE;
- }
- log.debug("hitsPerPage is " + hitsPerPage);
-
- int maxHitCount = DEFAULT_MAX_HIT_COUNT ;
- if( startIndex >= DEFAULT_MAX_HIT_COUNT - hitsPerPage )
- maxHitCount = startIndex + DEFAULT_MAX_HIT_COUNT ;
- log.debug("maxHitCount is " + maxHitCount);
+ int startIndex = getStartIndex(vreq);
+ int hitsPerPage = getHitsPerPage( vreq );
String qtxt = vreq.getParameter(VitroQuery.QUERY_PARAMETER_NAME);
log.debug("Query text is \""+ qtxt + "\"");
@@ -175,42 +156,27 @@ public class PagedSearchController extends FreemarkerHttpServlet {
return doFailedSearch(badQueryMsg, qtxt, format);
}
- SolrQuery query = getQuery(qtxt, maxHitCount, vreq);
+ SolrQuery query = getQuery(qtxt, hitsPerPage, startIndex, vreq);
SolrServer solr = SolrSetup.getSolrServer(getServletContext());
- QueryResponse response = null;
-
+ QueryResponse response = null;
try {
response = solr.query(query);
-
- } catch (Throwable t) {
- log.error("in first pass at search: " + t);
- // this is a hack to deal with odd cases where search and index threads interact
- try{
- wait(150);
- response = solr.query(query);
- } catch (Exception ex) {
- log.error(ex);
- String msg = makeBadSearchMessage(qtxt, ex.getMessage());
- if (msg == null) {
- msg = "The search request contained errors.";
- }
- return doFailedSearch(msg, qtxt, format);
- }
+ } catch (Exception ex) {
+ String msg = makeBadSearchMessage(qtxt, ex.getMessage());
+ log.error("could not run Solr query",ex);
+ return doFailedSearch(msg, qtxt, format);
}
if (response == null) {
- log.error("Search response was null");
- String msg = "The search request contained errors.";
- return doFailedSearch(msg, qtxt, format);
+ log.error("Search response was null");
+ return doFailedSearch("The search request contained errors.", qtxt, format);
}
SolrDocumentList docs = response.getResults();
-
if (docs == null) {
log.error("Document list for a search was null");
- String msg = "The search request contained errors.";
- return doFailedSearch(msg, qtxt,format);
+ return doFailedSearch("The search request contained errors.", qtxt,format);
}
long hitCount = docs.getNumFound();
@@ -218,30 +184,20 @@ public class PagedSearchController extends FreemarkerHttpServlet {
if ( hitCount < 1 ) {
return doNoHits(qtxt,format);
}
-
- long lastHitToShow = 0;
- if ((startIndex + hitsPerPage) > hitCount ) {
- lastHitToShow = hitCount;
- } else {
- lastHitToShow = startIndex + hitsPerPage;
- }
- List individuals = new LinkedList();
- for(int i = startIndex; i < lastHitToShow; i++){
- try {
- SolrDocument doc = docs.get(i);
- String uri = doc.get(VitroSearchTermNames.URI).toString();
- log.debug("Retrieving individual with uri "+ uri);
- Individual ent = new IndividualImpl();
- ent.setURI(uri);
- ent = iDao.getIndividualByURI(uri);
- if(ent!=null) {
- ent.setSearchSnippet(getSnippet(doc, response));
- individuals.add(ent);
+ List individuals = new ArrayList(docs.size());
+ Iterator docIter = docs.iterator();
+ while( docIter.hasNext() ){
+ try {
+ SolrDocument doc = docIter.next();
+ String uri = doc.get(VitroSearchTermNames.URI).toString();
+ Individual ind = iDao.getIndividualByURI(uri);
+ if(ind != null) {
+ ind.setSearchSnippet( getSnippet(doc, response) );
+ individuals.add(ind);
}
} catch(Exception e) {
- log.error("Problem getting usable individuals from search hits. " +
- e.getMessage());
+ log.error("Problem getting usable individuals from search hits. ",e);
}
}
@@ -275,31 +231,19 @@ public class PagedSearchController extends FreemarkerHttpServlet {
body.put("typeName", type.getName());
}
- /* Add classgroup and type refinement links to body */
+ /* Add ClassGroup and type refinement links to body */
if( wasHtmlRequested ){
- // Search request includes no classgroup and no type, so add classgroup search refinement links.
- if ( !classGroupFilterRequested && !typeFilterRequested ) {
- List classgroups = getClassGroups(grpDao, docs, maxHitCount);
- List classGroupLinks = new ArrayList(classgroups.size());
- for (VClassGroup vcg : classgroups) {
- if (vcg.getPublicName() != null) {
- classGroupLinks.add(new VClassGroupSearchLink(qtxt, vcg));
- }
- }
- body.put("classGroupLinks", classGroupLinks);
-
- // Search request is for a classgroup, so add rdf:type search refinement links
- // but try to filter out classes that are subclasses
- } else if ( classGroupFilterRequested && !typeFilterRequested ) {
- List vClasses = getVClasses(vclassDao, docs);
- List vClassLinks = new ArrayList(vClasses.size());
- for (VClass vc : vClasses) {
- vClassLinks.add(new VClassSearchLink(qtxt, vc));
- }
- body.put("classLinks", vClassLinks);
+ if ( !classGroupFilterRequested && !typeFilterRequested ) {
+ // Search request includes no ClassGroup and no type, so add ClassGroup search refinement links.
+ body.put("classGroupLinks", getClassGroupsLinks(grpDao, docs, response, qtxt));
+ } else if ( classGroupFilterRequested && !typeFilterRequested ) {
+ // Search request is for a ClassGroup, so add rdf:type search refinement links
+ // but try to filter out classes that are subclasses
+ body.put("classLinks", getVClassLinks(vclassDao, docs, response, qtxt));
pagingLinkParams.put(PARAM_CLASSGROUP, classGroupParam);
} else {
+ //search request is for a class so there are no more refinements
pagingLinkParams.put(PARAM_RDFTYPE, typeParam);
}
}
@@ -314,9 +258,10 @@ public class PagedSearchController extends FreemarkerHttpServlet {
body.put("hitCount", hitCount);
body.put("startIndex", startIndex);
- body.put("pagingLinks", getPagingLinks(startIndex, hitsPerPage,
- hitCount, maxHitCount, vreq.getServletPath(),
- pagingLinkParams));
+ body.put("pagingLinks",
+ getPagingLinks(startIndex, hitsPerPage, hitCount,
+ vreq.getServletPath(),
+ pagingLinkParams));
if (startIndex != 0) {
body.put("prevPage", getPreviousPageLink(startIndex,
@@ -336,6 +281,28 @@ public class PagedSearchController extends FreemarkerHttpServlet {
}
+ private int getHitsPerPage(VitroRequest vreq) {
+ int hitsPerPage = DEFAULT_HITS_PER_PAGE;
+ try{
+ hitsPerPage = Integer.parseInt(vreq.getParameter(PARAM_HITS_PER_PAGE));
+ } catch (Throwable e) {
+ hitsPerPage = DEFAULT_HITS_PER_PAGE;
+ }
+ log.debug("hitsPerPage is " + hitsPerPage);
+ return hitsPerPage;
+ }
+
+ private int getStartIndex(VitroRequest vreq) {
+ int startIndex = 0;
+ try{
+ startIndex = Integer.parseInt(vreq.getParameter(PARAM_START_INDEX));
+ }catch (Throwable e) {
+ startIndex = 0;
+ }
+ log.debug("startIndex is " + startIndex);
+ return startIndex;
+ }
+
private String badQueryText(String qtxt) {
if( qtxt == null || "".equals( qtxt.trim() ) )
return "Please enter a search term.";
@@ -348,80 +315,103 @@ public class PagedSearchController extends FreemarkerHttpServlet {
/**
* Get the class groups represented for the individuals in the documents.
+ * @param qtxt
*/
- private List getClassGroups(VClassGroupDao grpDao, SolrDocumentList docs, int maxHitCount) {
- LinkedHashMap grpMap = grpDao.getClassGroupMap();
- int n = grpMap.size();
+ private List getClassGroupsLinks(VClassGroupDao grpDao, SolrDocumentList docs, QueryResponse rsp, String qtxt) {
+ Map cgURItoCount = new HashMap();
- HashSet classGroupsInHits = new HashSet(n);
- int grpsFound = 0;
+ List classgroups = new ArrayList( );
+ List ffs = rsp.getFacetFields();
+ for(FacetField ff : ffs){
+ if(VitroSearchTermNames.CLASSGROUP_URI.equals(ff.getName())){
+ List counts = ff.getValues();
+ for( Count ct: counts){
+ VClassGroup vcg = grpDao.getGroupByURI( ct.getName() );
+ if( vcg == null ){
+ log.debug("could not get classgroup for URI " + ct.getName());
+ }else{
+ classgroups.add(vcg);
+ cgURItoCount.put(vcg.getURI(), ct.getCount());
+ }
+ }
+ }
+ }
- long maxHits = Math.min(docs.getNumFound(), maxHitCount);
- for(int i = 0; i < maxHits && n > grpsFound ;i++){
- try{
- SolrDocument doc = docs.get(i);
- Collection