Merge pull request #52 from EKT/DS-1223

[DS-1223] Display frequencies of items in single browsing for selected indices
This commit is contained in:
abollini
2012-09-17 02:49:10 -07:00
9 changed files with 126 additions and 11 deletions

View File

@@ -386,4 +386,8 @@ public interface BrowseDAO
public void setAuthorityValue(String value);
public String getAuthorityValue();
public boolean isEnableBrowseFrequencies();
public void setEnableBrowseFrequencies(boolean enableBrowseFrequencies);
}

View File

@@ -117,6 +117,8 @@ public class BrowseDAOOracle implements BrowseDAO
private boolean itemsInArchive = true;
private boolean itemsWithdrawn = false;
private boolean enableBrowseFrequencies = true;
public BrowseDAOOracle(Context context)
throws BrowseException
{
@@ -405,7 +407,12 @@ public class BrowseDAOOracle implements BrowseDAO
TableRow row = tri.next();
String valueResult = row.getStringColumn("value");
String authorityResult = row.getStringColumn("authority");
results.add(new String[]{valueResult,authorityResult});
if (enableBrowseFrequencies){
long frequency = row.getLongColumn("num");
results.add(new String[]{valueResult,authorityResult, String.valueOf(frequency)});
}
else
results.add(new String[]{valueResult,authorityResult, ""});
}
return results;
@@ -768,6 +775,17 @@ public class BrowseDAOOracle implements BrowseDAO
// prepare the limit and offset clauses
buildRowLimitAndOffset(queryBuf, params);
//If we want frequencies and this is not a count query, enchance the query accordingly
if (isEnableBrowseFrequencies() && countValues==null){
String before = "SELECT count(*) AS num, dvalues.value, dvalues.authority FROM (";
String after = ") dvalues , "+tableMap+" WHERE dvalues.id = "+tableMap+".distinct_id GROUP BY "+tableMap+
".distinct_id, dvalues.value, dvalues.authority, dvalues.sort_value";
queryBuf.insert(0, before);
queryBuf.append(after);
buildOrderBy(queryBuf);
}
return queryBuf.toString();
}
@@ -1395,4 +1413,12 @@ public class BrowseDAOOracle implements BrowseDAO
public String getAuthorityValue() {
return authority;
}
public boolean isEnableBrowseFrequencies() {
return enableBrowseFrequencies;
}
public void setEnableBrowseFrequencies(boolean enableBrowseFrequencies) {
this.enableBrowseFrequencies = enableBrowseFrequencies;
}
}

View File

@@ -117,6 +117,8 @@ public class BrowseDAOPostgres implements BrowseDAO
private boolean itemsInArchive = true;
private boolean itemsWithdrawn = false;
private boolean enableBrowseFrequencies = true;
/**
* Required constructor for use by BrowseDAOFactory
*
@@ -392,6 +394,7 @@ public class BrowseDAOPostgres implements BrowseDAO
throws BrowseException
{
String query = getQuery();
Object[] params = getQueryParams();
log.debug(LogManager.getHeader(context, "executing_value_query", "query=" + query));
@@ -409,7 +412,12 @@ public class BrowseDAOPostgres implements BrowseDAO
TableRow row = tri.next();
String valueResult = row.getStringColumn("value");
String authorityResult = row.getStringColumn("authority");
results.add(new String[]{valueResult,authorityResult});
if (enableBrowseFrequencies){
long frequency = row.getLongColumn("num");
results.add(new String[]{valueResult,authorityResult, String.valueOf(frequency)});
}
else
results.add(new String[]{valueResult,authorityResult, ""});
}
return results;
@@ -773,6 +781,17 @@ public class BrowseDAOPostgres implements BrowseDAO
// prepare the limit and offset clauses
buildRowLimitAndOffset(queryBuf, params);
//If we want frequencies and this is not a count query, enchance the query accordingly
if (isEnableBrowseFrequencies() && countValues==null){
String before = "SELECT count(*) AS num, dvalues.value, dvalues.authority FROM (";
String after = ") dvalues , "+tableMap+" WHERE dvalues.id = "+tableMap+".distinct_id GROUP BY "+tableMap+
".distinct_id, dvalues.value, dvalues.authority, dvalues.sort_value";
queryBuf.insert(0, before);
queryBuf.append(after);
buildOrderBy(queryBuf);
}
return queryBuf.toString();
}
@@ -1392,4 +1411,12 @@ public class BrowseDAOPostgres implements BrowseDAO
public String getAuthorityValue() {
return authority;
}
}
public boolean isEnableBrowseFrequencies() {
return enableBrowseFrequencies;
}
public void setEnableBrowseFrequencies(boolean enableBrowseFrequencies) {
this.enableBrowseFrequencies = enableBrowseFrequencies;
}
}

View File

@@ -414,13 +414,22 @@ public class BrowseEngine
// tell the browse query whether we are ascending or descending on the value
dao.setAscending(scope.isAscending());
// inform dao about the display frequencies flag
dao.setEnableBrowseFrequencies(browseIndex.isDisplayFrequencies());
// if we want to display frequencies, we need to pass the map table
if (browseIndex.isDisplayFrequencies()){
dao.setFilterMappingTables(null, browseIndex.getMapTableName());
}
// set our constraints on community or collection
if (scope.inCollection() || scope.inCommunity())
{
// Scoped browsing of distinct metadata requires the mapping
// Scoped browsing of distinct metadata requires the mapping
// table to be specified.
dao.setFilterMappingTables(null, browseIndex.getMapTableName());
if (!browseIndex.isDisplayFrequencies())
dao.setFilterMappingTables(null, browseIndex.getMapTableName());
if (scope.inCollection())
{
Collection col = (Collection) scope.getBrowseContainer();
@@ -747,7 +756,7 @@ public class BrowseEngine
dao.setOrderField(null);
dao.setLimit(-1);
dao.setOffset(-1);
// perform the query and get the result
int count = dao.doCountQuery();

View File

@@ -57,6 +57,9 @@ public final class BrowseIndex
/** default order (asc / desc) for this index */
private String defaultOrder = SortOption.ASCENDING;
/** whether to display frequencies or not, in case of a "metadata" browse index*/
private boolean displayFrequencies = true;
/** additional 'internal' tables that are always defined */
private static BrowseIndex itemIndex = new BrowseIndex("bi_item");
@@ -303,6 +306,10 @@ public final class BrowseIndex
return sortOption;
}
public boolean isDisplayFrequencies() {
return displayFrequencies;
}
/**
* Populate the internal array containing the bits of metadata, for
* ease of use later
@@ -594,7 +601,7 @@ public final class BrowseIndex
/**
* Is the browse index of display type single?
*
* @return true if single, false if not
* @return true if singe, false if not
*/
public boolean isMetadataIndex()
{
@@ -682,6 +689,12 @@ public final class BrowseIndex
while ( ((definition = ConfigurationManager.getProperty("webui.browse.index." + idx))) != null)
{
BrowseIndex bi = new BrowseIndex(definition, idx);
//Load the frequency configuration
String freqDefinition = ConfigurationManager.getProperty("webui.browse.metadata.show-freq." + idx);
if (freqDefinition!=null)
bi.displayFrequencies = Boolean.valueOf(freqDefinition);
browseIndices.add(bi);
idx++;
}

View File

@@ -134,6 +134,8 @@ public class SolrBrowseDAO implements BrowseDAO
private boolean itemsWithdrawn = false;
private boolean itemsPrivate = false;
private boolean showFrequencies;
private DiscoverResult getSolrResponse() throws BrowseException
{
@@ -265,8 +267,10 @@ public class SolrBrowseDAO implements BrowseDAO
for (int i = start; i < (start + max) && i < count; i++)
{
FacetResult c = facet.get(i);
String freq = showFrequencies ? String.valueOf(c.getCount())
: "";
result.add(new String[] { c.getDisplayedValue(),
c.getAuthorityKey() });
c.getAuthorityKey(), freq });
}
}
else
@@ -275,8 +279,10 @@ public class SolrBrowseDAO implements BrowseDAO
&& i >= 0; i--)
{
FacetResult c = facet.get(i);
String freq = showFrequencies ? String.valueOf(c.getCount())
: "";
result.add(new String[] { c.getDisplayedValue(),
c.getAuthorityKey() });
c.getAuthorityKey(), freq });
}
}
@@ -375,6 +381,18 @@ public class SolrBrowseDAO implements BrowseDAO
return doCountQuery() - ascValue;
}
}
@Override
public boolean isEnableBrowseFrequencies()
{
return showFrequencies;
}
@Override
public void setEnableBrowseFrequencies(boolean enableBrowseFrequencies)
{
showFrequencies = enableBrowseFrequencies;
}
/*
* (non-Javadoc)

View File

@@ -25,6 +25,7 @@
<%@ page import="java.net.URLEncoder" %>
<%@ page import="org.dspace.core.Utils" %>
<%@ page import="org.dspace.app.webui.util.UIUtil" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%
request.setAttribute("LanguageSwitch", "hide");
@@ -308,6 +309,7 @@
<tr>
<td class="<%= row %>RowOddCol">
<a href="<%= sharedLink %><% if (results[i][1] != null) { %>&amp;authority=<%= URLEncoder.encode(results[i][1], "UTF-8") %>" class="authority <%= bix.getName() %>"><%= Utils.addEntities(results[i][0]) %></a> <% } else { %>&amp;value=<%= URLEncoder.encode(results[i][0], "UTF-8") %>"><%= Utils.addEntities(results[i][0]) %></a> <% } %>
<%= StringUtils.isNotBlank(results[i][2])?" ["+results[i][2]+"]":""%>
</td>
</tr>
<%

View File

@@ -18,6 +18,7 @@ import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.http.HttpEnvironment;
import org.apache.cocoon.util.HashUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.excalibur.source.SourceValidity;
import org.apache.log4j.Logger;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
@@ -328,6 +329,10 @@ public class ConfigurableBrowse extends AbstractDSpaceTransformer implements
Cell cell = singleTable.addRow().addCell();
cell.addXref(super.generateURL(BROWSE_URL_BASE, queryParams),
singleEntry[0]);
if (StringUtils.isNotEmpty(singleEntry[2]))
{
cell.addContent(" ["+singleEntry[2]+"]");
}
}
}
}

View File

@@ -1063,7 +1063,18 @@ plugin.named.org.dspace.sort.OrderFormatDelegate= \
#
webui.browse.link.1 = author:dc.contributor.*
#### Display browse frequencies
#
# webui.browse.metadata.show-freq.<n> = true | false
# where n is the same index as in webui.browse.index.<n> configurations
#
# For the browse indexes that this property is omitted, it is assumed as true
# please note that only a few overhead is required to compute frequencies when
# DBMS BrowseDAO is used and not overhead at all when SOLRBrowseDAO is used
# webui.browse.metadata.show-freq.1 = false
# webui.browse.metadata.show-freq.2 = false
# webui.browse.metadata.show-freq.3 = false
# webui.browse.metadata.show-freq.4 = true
#### Additional configuration for Recent Submissions code ####