Revision: 2508
http://dspace.svn.sourceforge.net/dspace/?rev=2508&view=rev
Author: grahamtriggs
Date: 2008-01-10 06:03:36 -0800 (Thu, 10 Jan 2008)
Log Message:
-----------
First part of search update - reduce search size, add in fields for sorting content, lessen dependency on handles
Modified Paths:
--------------
branches/dspace-1_5_x/dspace/config/dspace.cfg
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseEngine.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseIndex.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseInfo.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowserScope.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/IndexBrowse.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/content/ItemComparator.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/DSAnalyzer.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/DSIndexer.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/DSQuery.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/QueryArgs.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/QueryResults.java
branches/dspace-1_5_x/dspace-jspui/src/main/java/org/dspace/app/webui/components/RecentSubmissionsManager.java
branches/dspace-1_5_x/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/BrowseListTag.java
branches/dspace-1_5_x/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/AbstractBrowserServlet.java
branches/dspace-1_5_x/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/FeedServlet.java
branches/dspace-1_5_x/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/SimpleSearchServlet.java
branches/dspace-1_5_x/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/admin/ItemMapServlet.java
branches/dspace-1_5_x/dspace-jspui/src/main/webapp/browse/full.jsp
branches/dspace-1_5_x/dspace-jspui/src/main/webapp/layout/navbar-admin.jsp
branches/dspace-1_5_x/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/administrative/WithdrawnItems.java
branches/dspace-1_5_x/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/CollectionViewer.java
branches/dspace-1_5_x/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/CommunityViewer.java
branches/dspace-1_5_x/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/ConfigurableBrowse.java
branches/dspace-1_5_x/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/cocoon/DSpaceFeedGenerator.java
Added Paths:
-----------
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/AbstractTextFilterOFD.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/sort/
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/sort/OrderFormat.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/sort/OrderFormatAuthor.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/sort/OrderFormatDelegate.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/sort/OrderFormatText.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/sort/OrderFormatTitle.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/sort/OrderFormatTitleMarc21.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/sort/SortException.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/sort/SortOption.java
Removed Paths:
-------------
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/AbstractTextFilterBOD.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrder.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderAuthor.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderDelegate.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderText.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderTitle.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderTitleMarc21.java
branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/SortOption.java
Modified: branches/dspace-1_5_x/dspace/config/dspace.cfg
===================================================================
--- branches/dspace-1_5_x/dspace/config/dspace.cfg 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace/config/dspace.cfg 2008-01-10 14:03:36 UTC (rev 2508)
@@ -474,7 +474,7 @@
# webui.browse.index.<n> = <index name> : item : <sort option name> : (asc | desc)
#
# sort option name: this is the sorting to be applied to the display. It must match the
-# name given to one of the webui.browse.sort-option entries given below.
+# name given to one of the webui.itemlist.sort-option entries given below.
#
# The final part of the configuration is optional, and specifies the default ordering
# for the index - whether it is ASCending (the default, and best for text indexes), or
@@ -499,13 +499,13 @@
# Set the options for what can be sorted by
#
-# Sort options will be available when browsing a list of items (i.e. only in
-# "full" mode, not "single" mode). You can define an arbitrary number of fields
+# Sort options will be available when browsing a list of items (i.e. an 'item' browse,
+# or search results). You can define an arbitrary number of fields
# to sort on, irrespective of which fields you display using webui.itemlist.columns
#
# the format is:
#
-# webui.browse.sort-option.<n> = <option name> : \
+# webui.itemlist.sort-option.<n> = <option name> : \
# <schema prefix>.<element>[.<qualifier>|.*] : \
# (date | text | ...) : (show | hide)
#
@@ -518,9 +518,9 @@
# you need to define a specific date sort for use by the recent items lists,
# but otherwise don't want users to choose that option.
#
-webui.browse.sort-option.1 = title:dc.title:title
-webui.browse.sort-option.2 = dateissued:dc.date.issued:date
-webui.browse.sort-option.3 = dateaccessioned:dc.date.accessioned:date
+webui.itemlist.sort-option.1 = title:dc.title:title
+webui.itemlist.sort-option.2 = dateissued:dc.date.issued:date
+webui.itemlist.sort-option.3 = dateaccessioned:dc.date.accessioned:date
# Set the options for the size (number of characters) of the fields stored in the database.
#
@@ -550,9 +550,9 @@
#
# The default datatypes (and delegates) are:
#
-# author = org.dspace.browse.BrowseOrderAuthor
-# title = org.dspace.browse.BrowseOrderTitle
-# text = org.dspace.browse.BrowseOrderText
+# author = org.dspace.sort.OrderFormatAuthor
+# title = org.dspace.sort.OrderFormatTitle
+# text = org.dspace.sort.OrderFormatText
#
# If you redefine a default datatype here, the configuration will be used in preference
# to the default, however, if you do not explicitly redefine a datatype, then the
@@ -560,8 +560,8 @@
#
# Uncomment the configuration below to use the multi-lingual MARC 21 title ordering.
#
-#plugin.named.org.dspace.browse.BrowseOrderDelegate= \
-# org.dspace.browse.BrowseOrderTitleMarc21=title
+#plugin.named.org.dspace.sort.OrderFormatDelegate= \
+# org.dspace.sort.OrderFormatTitleMarc21=title
## Set the options for how authors are displayed in the browse listing
Deleted: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/AbstractTextFilterBOD.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/AbstractTextFilterBOD.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/AbstractTextFilterBOD.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -1,121 +0,0 @@
-/*
- * AbstractTextFilterBOD.java
- *
- * Version: $Revision: 1.0 $
- *
- * Date: $Date: 2007/03/02 11:22:13 $
- *
- * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
- * Institute of Technology. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of the Hewlett-Packard Company nor the name of the
- * Massachusetts Institute of Technology nor the names of their
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- */
-
-package org.dspace.browse;
-
-import org.apache.log4j.Logger;
-import org.dspace.text.filter.TextFilter;
-
-/**
- * Helper class for creating order delegates.
- *
- * To configure the filters create a subclass and, in an object initializer,
- * create an array of classes that implement TextFilter:
- *
- * class MyLocaleDelegate extends AbstractTextFilterBOD {
- * {
- * filters = new TextFilter[] { new LocaleOrderingFilter(); }
- * }
- * }
- *
- * The order they are in the array, is the order that they are executed.
- * (this may be important for some filters - read their documentation!)
- *
- * Example configurations that could be used:
- * { new DecomposeDiactritics(), new StripDiacritics(), new LowerCaseAndTrim() }
- * - Decompose and then strip the diacritics, lowercase and trim the string.
- *
- * { new MARC21InitialArticleWord(), new DecomposeDiactritics(), new LowerCaseTrim() }
- * - Parse the initial article words based on the Library of Congress list of
- * definite/indefinite article words, decompose diacritics, and lowercase/trim.
- *
- * { new LowerCaseTrim(), new LocaleOrderingFilter() }
- * - Lowercase the string, then make a locale dependent sort text
- * (note that the sort text is not human readable)
- *
- * @author Graham Triggs
- */
-public abstract class AbstractTextFilterBOD implements BrowseOrderDelegate
-{
- private final static Logger log = Logger.getLogger(AbstractTextFilterBOD.class);
-
- // Initialised in subclass in an object initializer
- protected TextFilter[] filters;
-
- /**
- * Prepare the appropriate sort string for the given value in the
- * given language. Languate should be supplied with the ISO-6390-1
- * or ISO-639-2 standards. For example "en" or "eng".
- *
- * @param value the string value
- * @param language the language to interpret in
- */
- public String makeSortString(String value, String language)
- {
- if (filters == null)
- {
- // Log an error if the class is not configured correctly
- log.error("No filters defined for " + this.getClass().getName());
- }
- else
- {
- // Normalize language into a two or three character code
- if (language != null)
- {
- if (language.length() > 2 && language.charAt(2) == '_')
- language = language.substring(0,2);
-
- if (language.length() > 3)
- language = language.substring(0,3);
- }
-
- // Iterate through filters, applying each in turn
- for (int idx = 0; idx < filters.length; idx++)
- {
- if (language != null)
- value = filters[idx].filter(value, language);
- else
- value = filters[idx].filter(value);
- }
- }
-
- return value;
- }
-}
Copied: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/AbstractTextFilterOFD.java (from rev 2488, branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/AbstractTextFilterBOD.java)
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/AbstractTextFilterOFD.java (rev 0)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/AbstractTextFilterOFD.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -0,0 +1,122 @@
+/*
+ * AbstractTextFilterOFD.java
+ *
+ * Version: $Revision: 1.0 $
+ *
+ * Date: $Date: 2007/03/02 11:22:13 $
+ *
+ * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
+ * Institute of Technology. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - Neither the name of the Hewlett-Packard Company nor the name of the
+ * Massachusetts Institute of Technology nor the names of their
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+package org.dspace.browse;
+
+import org.apache.log4j.Logger;
+import org.dspace.text.filter.TextFilter;
+import org.dspace.sort.OrderFormatDelegate;
+
+/**
+ * Helper class for creating order delegates.
+ *
+ * To configure the filters create a subclass and, in an object initializer,
+ * create an array of classes that implement TextFilter:
+ *
+ * class MyLocaleDelegate extends AbstractTextFilterOFD {
+ * {
+ * filters = new TextFilter[] { new LocaleOrderingFilter(); }
+ * }
+ * }
+ *
+ * The order they are in the array, is the order that they are executed.
+ * (this may be important for some filters - read their documentation!)
+ *
+ * Example configurations that could be used:
+ * { new DecomposeDiactritics(), new StripDiacritics(), new LowerCaseAndTrim() }
+ * - Decompose and then strip the diacritics, lowercase and trim the string.
+ *
+ * { new MARC21InitialArticleWord(), new DecomposeDiactritics(), new LowerCaseTrim() }
+ * - Parse the initial article words based on the Library of Congress list of
+ * definite/indefinite article words, decompose diacritics, and lowercase/trim.
+ *
+ * { new LowerCaseTrim(), new LocaleOrderingFilter() }
+ * - Lowercase the string, then make a locale dependent sort text
+ * (note that the sort text is not human readable)
+ *
+ * @author Graham Triggs
+ */
+public abstract class AbstractTextFilterOFD implements OrderFormatDelegate
+{
+ private final static Logger log = Logger.getLogger(AbstractTextFilterOFD.class);
+
+ // Initialised in subclass in an object initializer
+ protected TextFilter[] filters;
+
+ /**
+ * Prepare the appropriate sort string for the given value in the
+ * given language. Languate should be supplied with the ISO-6390-1
+ * or ISO-639-2 standards. For example "en" or "eng".
+ *
+ * @param value the string value
+ * @param language the language to interpret in
+ */
+ public String makeSortString(String value, String language)
+ {
+ if (filters == null)
+ {
+ // Log an error if the class is not configured correctly
+ log.error("No filters defined for " + this.getClass().getName());
+ }
+ else
+ {
+ // Normalize language into a two or three character code
+ if (language != null)
+ {
+ if (language.length() > 2 && language.charAt(2) == '_')
+ language = language.substring(0,2);
+
+ if (language.length() > 3)
+ language = language.substring(0,3);
+ }
+
+ // Iterate through filters, applying each in turn
+ for (int idx = 0; idx < filters.length; idx++)
+ {
+ if (language != null)
+ value = filters[idx].filter(value, language);
+ else
+ value = filters[idx].filter(value);
+ }
+ }
+
+ return value;
+ }
+}
Modified: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseEngine.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseEngine.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseEngine.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -49,6 +49,8 @@
import org.dspace.content.Community;
import org.dspace.core.Context;
import org.dspace.core.LogManager;
+import org.dspace.sort.SortOption;
+import org.dspace.sort.OrderFormat;
/**
* This class does most of the actual grunt work of preparing a browse
@@ -285,7 +287,7 @@
rawValue = value;
// make sure the incoming value is normalised
- value = BrowseOrder.makeSortString(value, scope.getFilterValueLang(),
+ value = OrderFormat.makeSortString(value, scope.getFilterValueLang(),
scope.getBrowseIndex().getDataType());
// set the values in the Browse Query
@@ -737,12 +739,12 @@
if (scope.hasJumpToValue())
{
// Normalize it based on the specified language as appropriate for this index
- return BrowseOrder.makeSortString(scope.getJumpToValue(), scope.setJumpToValueLang(), scope.getBrowseIndex().getDataType());
+ return OrderFormat.makeSortString(scope.getJumpToValue(), scope.setJumpToValueLang(), scope.getBrowseIndex().getDataType());
}
else if (scope.hasStartsWith())
{
// Scope has a starts with, so normalize that instead
- return BrowseOrder.makeSortString(scope.getStartsWith(), null, scope.getBrowseIndex().getDataType());
+ return OrderFormat.makeSortString(scope.getStartsWith(), null, scope.getBrowseIndex().getDataType());
}
// No focus value on the scope (ie. focus by id), so just return the passed focus value
Modified: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseIndex.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseIndex.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseIndex.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -41,12 +41,13 @@
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.dspace.core.ConfigurationManager;
+import org.dspace.sort.SortOption;
+import org.dspace.sort.SortException;
/**
* This class holds all the information about a specifically configured
@@ -113,7 +114,7 @@
displayType = "item";
sortOption = SortOption.getDefaultSortOption();
}
- catch (BrowseException be)
+ catch (SortException se)
{
// FIXME Exception handling
}
@@ -140,83 +141,90 @@
private BrowseIndex(String definition, int number)
throws BrowseException
{
- boolean valid = true;
- this.defaultOrder = SortOption.ASCENDING;
- this.number = number;
-
- String rx = "(\\w+):(\\w+):([\\w\\.\\*,]+):?(\\w*):?(\\w*)";
- Pattern pattern = Pattern.compile(rx);
- Matcher matcher = pattern.matcher(definition);
-
- if (matcher.matches())
+ try
{
- name = matcher.group(1);
- displayType = matcher.group(2);
-
- if (isMetadataIndex())
- {
- metadataAll = matcher.group(3);
- datatype = matcher.group(4);
+ boolean valid = true;
+ this.defaultOrder = SortOption.ASCENDING;
+ this.number = number;
- if (metadataAll != null)
- metadata = metadataAll.split(",");
+ String rx = "(\\w+):(\\w+):([\\w\\.\\*,]+):?(\\w*):?(\\w*)";
+ Pattern pattern = Pattern.compile(rx);
+ Matcher matcher = pattern.matcher(definition);
- if (metadata == null || metadata.length == 0)
- valid = false;
-
- if (datatype == null || datatype.equals(""))
- valid = false;
+ if (matcher.matches())
+ {
+ name = matcher.group(1);
+ displayType = matcher.group(2);
- // If an optional ordering configuration is supplied,
- // set the defaultOrder appropriately (asc or desc)
- if (matcher.groupCount() > 4)
+ if (isMetadataIndex())
{
- String order = matcher.group(5);
- if (SortOption.DESCENDING.equalsIgnoreCase(order))
- this.defaultOrder = SortOption.DESCENDING;
- }
+ metadataAll = matcher.group(3);
+ datatype = matcher.group(4);
- tableBaseName = makeTableBaseName(number);
- }
- else if (isItemIndex())
- {
- String sortName = matcher.group(3);
+ if (metadataAll != null)
+ metadata = metadataAll.split(",");
- for (SortOption so : SortOption.getSortOptions())
+ if (metadata == null || metadata.length == 0)
+ valid = false;
+
+ if (datatype == null || datatype.equals(""))
+ valid = false;
+
+ // If an optional ordering configuration is supplied,
+ // set the defaultOrder appropriately (asc or desc)
+ if (matcher.groupCount() > 4)
+ {
+ String order = matcher.group(5);
+ if (SortOption.DESCENDING.equalsIgnoreCase(order))
+ this.defaultOrder = SortOption.DESCENDING;
+ }
+
+ tableBaseName = makeTableBaseName(number);
+ }
+ else if (isItemIndex())
{
- if (so.getName().equals(sortName))
- sortOption = so;
- }
+ String sortName = matcher.group(3);
- if (sortOption == null)
- valid = false;
+ for (SortOption so : SortOption.getSortOptions())
+ {
+ if (so.getName().equals(sortName))
+ sortOption = so;
+ }
- // If an optional ordering configuration is supplied,
- // set the defaultOrder appropriately (asc or desc)
- if (matcher.groupCount() > 3)
+ if (sortOption == null)
+ valid = false;
+
+ // If an optional ordering configuration is supplied,
+ // set the defaultOrder appropriately (asc or desc)
+ if (matcher.groupCount() > 3)
+ {
+ String order = matcher.group(4);
+ if (SortOption.DESCENDING.equalsIgnoreCase(order))
+ this.defaultOrder = SortOption.DESCENDING;
+ }
+
+ tableBaseName = getItemBrowseIndex().tableBaseName;
+ }
+ else
{
- String order = matcher.group(4);
- if (SortOption.DESCENDING.equalsIgnoreCase(order))
- this.defaultOrder = SortOption.DESCENDING;
+ valid = false;
}
-
- tableBaseName = getItemBrowseIndex().tableBaseName;
}
else
{
valid = false;
}
+
+ if (!valid)
+ {
+ throw new BrowseException("Browse Index configuration is not valid: webui.browse.index." +
+ number + " = " + definition);
+ }
}
- else
+ catch (SortException se)
{
- valid = false;
+ throw new BrowseException("Error in SortOptions", se);
}
-
- if (!valid)
- {
- throw new BrowseException("Browse Index configuration is not valid: webui.browse.index." +
- number + " = " + definition);
- }
}
/**
Modified: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseInfo.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseInfo.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseInfo.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -40,7 +40,6 @@
package org.dspace.browse;
import java.sql.SQLException;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -51,6 +50,7 @@
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.core.Context;
+import org.dspace.sort.SortOption;
/**
* The results of a Browse, including all the contextual information about
Deleted: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrder.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrder.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrder.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -1,142 +0,0 @@
-/*
- * BrowseOrder.java
- *
- * Version: $Revision: 1.0 $
- *
- * Date: $Date: 2007/03/02 11:22:13 $
- *
- * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
- * Institute of Technology. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of the Hewlett-Packard Company nor the name of the
- * Massachusetts Institute of Technology nor the names of their
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- */
-
-package org.dspace.browse;
-
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
-import org.dspace.core.PluginManager;
-
-/**
- * Class implementing static helpers for anywhere that interacts with the sort columns
- * (ie. ItemsByAuthor.sort_author, ItemsByTitle.sort_title)
- *
- * This class maps index 'types' to delegates that implement the sort string creation
- *
- * Types can be defined or configured using the plugin manager:
- *
- * plugin.named.org.dspace.browse.BrowseOrderDelegate=
- * org.dspace.browse.BrowseOrderTitleMarc21=title
- * org.dspace.browse.BrowseOrderAuthor=author
- *
- * The following standard types have been defined by default, but can be reconfigured
- * via the plugin manager:
- *
- * author = org.dspace.browse.BrowseOrderAuthor
- * title = org.dspace.browse.BrowseOrderTitle
- * text = org.dspace.browse.BrowseOrderText
- *
- * IMPORTANT - If you change any of the orderings, you need to rebuild the browse sort columns
- * (ie. run 'index-all', or 'dsrun org.dspace.browse.InitializeBrowse')
- *
- * @author Graham Triggs
- * @version $Revision: 1.0 $
- */
-public class BrowseOrder
-{
- private final static Logger log = LogManager.getLogger(BrowseOrder.class);
-
- public final static String AUTHOR = "author";
- public final static String TITLE = "title";
- public final static String TEXT = "text";
-
- // Array of all available order delegates - avoids excessive calls to plugin manager
- private final static String[] delegates = PluginManager.getAllPluginNames(BrowseOrderDelegate.class);
-
- private final static BrowseOrderDelegate authorDelegate = new BrowseOrderAuthor();
- private final static BrowseOrderDelegate titleDelegate = new BrowseOrderTitle();
- private final static BrowseOrderDelegate textDelegate = new BrowseOrderText();
-
- /**
- * Generate a sort string for the given DC metadata
- */
- public static String makeSortString(String value, String language, String type)
- {
- BrowseOrderDelegate delegate = null;
-
- // If a named index has been supplied
- if (type != null && type.length() > 0)
- {
- // Use a delegate if one is configured
- if ((delegate = BrowseOrder.getDelegate(type)) != null)
- {
- return delegate.makeSortString(value, language);
- }
- }
-
- // No delegates found, so apply defaults
- if (type.equalsIgnoreCase(BrowseOrder.AUTHOR) && authorDelegate != null)
- {
- return authorDelegate.makeSortString(value, language);
- }
-
- if (type.equalsIgnoreCase(BrowseOrder.TITLE) && titleDelegate != null)
- {
- return titleDelegate.makeSortString(value, language);
- }
-
- if (type.equalsIgnoreCase(BrowseOrder.TEXT) && textDelegate != null)
- {
- return textDelegate.makeSortString(value, language);
- }
-
- return value;
- }
-
- /**
- * Retrieve the named delegate
- */
- private static BrowseOrderDelegate getDelegate(String name)
- {
- if (name != null && name.length() > 0)
- {
- // Check the cached array of names to see if the delegate has been configured
- for (int idx = 0; idx < delegates.length; idx++)
- {
- if (delegates[idx].equals(name))
- {
- return (BrowseOrderDelegate)PluginManager.getNamedPlugin(BrowseOrderDelegate.class, name);
- }
- }
- }
-
- return null;
- }
-}
Deleted: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderAuthor.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderAuthor.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderAuthor.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -1,58 +0,0 @@
-/*
- * BrowseOrderAuthor.java
- *
- * Version: $Revision: 1.0 $
- *
- * Date: $Date: 2007/03/02 11:22:13 $
- *
- * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
- * Institute of Technology. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of the Hewlett-Packard Company nor the name of the
- * Massachusetts Institute of Technology nor the names of their
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- */
-
-package org.dspace.browse;
-
-import org.dspace.text.filter.DecomposeDiactritics;
-import org.dspace.text.filter.LowerCaseAndTrim;
-import org.dspace.text.filter.TextFilter;
-
-/**
- * Standard author ordering delegate implementation
- *
- * @author Graham Triggs
- */
-public class BrowseOrderAuthor extends AbstractTextFilterBOD
-{
- {
- filters = new TextFilter[] { new DecomposeDiactritics(),
- new LowerCaseAndTrim() };
- }
-}
Deleted: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderDelegate.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderDelegate.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderDelegate.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -1,59 +0,0 @@
-/*
- * BrowseOrderDelegate.java
- *
- * Version: $Revision: 1.0 $
- *
- * Date: $Date: 2007/03/02 11:22:13 $
- *
- * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
- * Institute of Technology. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of the Hewlett-Packard Company nor the name of the
- * Massachusetts Institute of Technology nor the names of their
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- */
-
-package org.dspace.browse;
-
-/**
- * Interface for browse order delegates
- *
- * @author Graham Triggs
- */
-public interface BrowseOrderDelegate
-{
- /**
- * Prepare the appropriate sort string for the given value in the
- * given language. Languate should be supplied with the ISO-6390-1
- * or ISO-639-2 standards. For example "en" or "eng".
- *
- * @param value the string value
- * @param language the language to interpret in
- */
- public String makeSortString(String value, String language);
-}
Deleted: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderText.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderText.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderText.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -1,58 +0,0 @@
-/*
- * BrowseOrderText.java
- *
- * Version: $Revision: 1.0 $
- *
- * Date: $Date: 2007/03/02 11:22:13 $
- *
- * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
- * Institute of Technology. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of the Hewlett-Packard Company nor the name of the
- * Massachusetts Institute of Technology nor the names of their
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- */
-
-package org.dspace.browse;
-
-import org.dspace.text.filter.DecomposeDiactritics;
-import org.dspace.text.filter.LowerCaseAndTrim;
-import org.dspace.text.filter.TextFilter;
-
-/**
- * Standard text ordering delegate implementation
- *
- * @author Graham Triggs
- */
-public class BrowseOrderText extends AbstractTextFilterBOD
-{
- {
- filters = new TextFilter[] { new DecomposeDiactritics(),
- new LowerCaseAndTrim() };
- }
-}
Deleted: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderTitle.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderTitle.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderTitle.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -1,60 +0,0 @@
-/*
- * BrowseOrderTitle.java
- *
- * Version: $Revision: 1.0 $
- *
- * Date: $Date: 2007/03/02 11:22:13 $
- *
- * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
- * Institute of Technology. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of the Hewlett-Packard Company nor the name of the
- * Massachusetts Institute of Technology nor the names of their
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- */
-
-package org.dspace.browse;
-
-import org.dspace.text.filter.DecomposeDiactritics;
-import org.dspace.text.filter.LowerCaseAndTrim;
-import org.dspace.text.filter.StandardInitialArticleWord;
-import org.dspace.text.filter.TextFilter;
-
-/**
- * Standard title ordering delegate implementation
- *
- * @author Graham Triggs
- */
-public class BrowseOrderTitle extends AbstractTextFilterBOD
-{
- {
- filters = new TextFilter[] { new StandardInitialArticleWord(),
- new DecomposeDiactritics(),
- new LowerCaseAndTrim() };
- }
-}
Deleted: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderTitleMarc21.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderTitleMarc21.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderTitleMarc21.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -1,58 +0,0 @@
-/*
- * BrowseOrderTitleMarc21.java
- *
- * Version: $Revision: 1.0 $
- *
- * Date: $Date: 2007/03/02 11:22:13 $
- *
- * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
- * Institute of Technology. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of the Hewlett-Packard Company nor the name of the
- * Massachusetts Institute of Technology nor the names of their
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- */
-
-package org.dspace.browse;
-
-import org.dspace.text.filter.*;
-
-/**
- * MARC 21 title ordering delegate implementation
- *
- * @author Graham Triggs
- */
-public class BrowseOrderTitleMarc21 extends AbstractTextFilterBOD
-{
- {
- filters = new TextFilter[] { new MARC21InitialArticleWord(),
- new DecomposeDiactritics(),
- new StripLeadingNonAlphaNum(),
- new LowerCaseAndTrim() };
- }
-}
Modified: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowserScope.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowserScope.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowserScope.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -39,6 +39,8 @@
import org.dspace.content.Community;
import org.dspace.content.DSpaceObject;
import org.dspace.core.Context;
+import org.dspace.sort.SortOption;
+import org.dspace.sort.SortException;
import org.apache.log4j.Logger;
/**
@@ -404,53 +406,60 @@
public SortOption getSortOption()
throws BrowseException
{
- // If a sortOption hasn't been set, work out the default
- if (sortOption == null)
- {
- // We need a browse index first though
- if (browseIndex != null)
- {
- // If a sorting hasn't been specified, and it's a metadata browse
- if (sortBy <= 0 && browseIndex.isMetadataIndex())
- {
- // Create a dummy sortOption for the metadata sort
- String dataType = browseIndex.getDataType();
- String type = ("date".equals(dataType) ? "date" : "text");
- sortOption = new SortOption(0, browseIndex.getName(), browseIndex.getMetadata(0), type);
- }
- else
- {
- // If a sorting hasn't been specified
- if (sortBy <= 0)
- {
- // Get the sort option from the index
- sortOption = browseIndex.getSortOption();
-
- if (sortOption == null)
- {
- // No sort option, so default to the first one defined in the config
- for (SortOption so : SortOption.getSortOptions())
- {
- sortOption = so;
- break;
- }
- }
- }
- else
- {
- // A sorting has been specified, so get it from the configured sort columns
- for (SortOption so : SortOption.getSortOptions())
+ try
+ {
+ // If a sortOption hasn't been set, work out the default
+ if (sortOption == null)
+ {
+ // We need a browse index first though
+ if (browseIndex != null)
+ {
+ // If a sorting hasn't been specified, and it's a metadata browse
+ if (sortBy <= 0 && browseIndex.isMetadataIndex())
+ {
+ // Create a dummy sortOption for the metadata sort
+ String dataType = browseIndex.getDataType();
+ String type = ("date".equals(dataType) ? "date" : "text");
+ sortOption = new SortOption(0, browseIndex.getName(), browseIndex.getMetadata(0), type);
+ }
+ else
+ {
+ // If a sorting hasn't been specified
+ if (sortBy <= 0)
{
- if (so.getNumber() == sortBy)
- sortOption = so;
+ // Get the sort option from the index
+ sortOption = browseIndex.getSortOption();
+
+ if (sortOption == null)
+ {
+ // No sort option, so default to the first one defined in the config
+ for (SortOption so : SortOption.getSortOptions())
+ {
+ sortOption = so;
+ break;
+ }
+ }
}
- }
- }
- }
- }
-
- return sortOption;
- }
+ else
+ {
+ // A sorting has been specified, so get it from the configured sort columns
+ for (SortOption so : SortOption.getSortOptions())
+ {
+ if (so.getNumber() == sortBy)
+ sortOption = so;
+ }
+ }
+ }
+ }
+ }
+
+ return sortOption;
+ }
+ catch (SortException se)
+ {
+ throw new BrowseException("Error in SortOptions", se);
+ }
+ }
/**
* @return Returns the startsWith.
Modified: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/IndexBrowse.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/IndexBrowse.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/IndexBrowse.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -54,6 +54,9 @@
import org.dspace.content.DCValue;
import org.dspace.content.Item;
import org.dspace.core.Context;
+import org.dspace.sort.SortOption;
+import org.dspace.sort.SortException;
+import org.dspace.sort.OrderFormat;
/**
* Tool to create Browse indexes. This class is used from the command line to
@@ -433,7 +436,7 @@
for (int x = 0; x < values.length; x++)
{
// get the normalised version of the value
- String nVal = BrowseOrder.makeSortString(values[x].value, values[x].language, bis[i].getDataType());
+ String nVal = OrderFormat.makeSortString(values[x].value, values[x].language, bis[i].getDataType());
Map sortMap = getSortValues(item, itemMDMap);
@@ -469,51 +472,59 @@
private Map<Integer, String> getSortValues(ItemMetadataProxy item, Map itemMDMap)
throws BrowseException, SQLException
{
- // now obtain the sort order values that we will use
- Map<Integer, String> sortMap = new HashMap<Integer, String>();
- for (SortOption so : SortOption.getSortOptions())
+ try
{
- Integer key = new Integer(so.getNumber());
- String metadata = so.getMetadata();
-
- // If we've already used the metadata for this Item
- // it will be cached in the map
- DCValue value = null;
-
- if (itemMDMap != null)
- value = (DCValue) itemMDMap.get(metadata);
-
- // We haven't used this metadata before, so grab it from the item
- if (value == null)
+ // now obtain the sort order values that we will use
+ Map<Integer, String> sortMap = new HashMap<Integer, String>();
+ for (SortOption so : SortOption.getSortOptions())
{
- String[] somd = so.getMdBits();
- DCValue[] dcv = item.getMetadata(somd[0], somd[1], somd[2], Item.ANY);
-
- if (dcv == null)
+ Integer key = new Integer(so.getNumber());
+ String metadata = so.getMetadata();
+
+ // If we've already used the metadata for this Item
+ // it will be cached in the map
+ DCValue value = null;
+
+ if (itemMDMap != null)
+ value = (DCValue) itemMDMap.get(metadata);
+
+ // We haven't used this metadata before, so grab it from the item
+ if (value == null)
{
- continue;
+ String[] somd = so.getMdBits();
+ DCValue[] dcv = item.getMetadata(somd[0], somd[1], somd[2], Item.ANY);
+
+ if (dcv == null)
+ {
+ continue;
+ }
+
+ // we only use the first dc value
+ if (dcv.length > 0)
+ {
+ // Set it as the current metadata value to use
+ // and add it to the map
+ value = dcv[0];
+
+ if (itemMDMap != null)
+ itemMDMap.put(metadata, dcv[0]);
+ }
}
-
- // we only use the first dc value
- if (dcv.length > 0)
+
+ // normalise the values as we insert into the sort map
+ if (value != null && value.value != null)
{
- // Set it as the current metadata value to use
- // and add it to the map
- value = dcv[0];
-
- if (itemMDMap != null)
- itemMDMap.put(metadata, dcv[0]);
+ String nValue = OrderFormat.makeSortString(value.value, value.language, so.getType());
+ sortMap.put(key, nValue);
}
}
- // normalise the values as we insert into the sort map
- if (value != null && value.value != null)
- {
- String nValue = BrowseOrder.makeSortString(value.value, value.language, so.getType());
- sortMap.put(key, nValue);
- }
+ return sortMap;
}
- return sortMap;
+ catch (SortException se)
+ {
+ throw new BrowseException("Error in SortOptions", se);
+ }
}
/**
@@ -696,27 +707,34 @@
private void prepTables()
throws BrowseException
{
- // first, erase the existing indexes
- clearDatabase();
-
- createItemTables();
-
- // for each current browse index, make all the relevant tables
- for (int i = 0; i < bis.length; i++)
+ try
{
- createTables(bis[i]);
-
- // prepare some CLI output
- StringBuffer logMe = new StringBuffer();
- for (SortOption so : SortOption.getSortOptions())
- {
- logMe.append(" " + so.getMetadata() + " ");
- }
-
- output.message("Creating browse index " + bis[i].getName() +
- ": index by " + bis[i].getMetadata() +
- " sortable by: " + logMe.toString());
+ // first, erase the existing indexes
+ clearDatabase();
+
+ createItemTables();
+
+ // for each current browse index, make all the relevant tables
+ for (int i = 0; i < bis.length; i++)
+ {
+ createTables(bis[i]);
+
+ // prepare some CLI output
+ StringBuffer logMe = new StringBuffer();
+ for (SortOption so : SortOption.getSortOptions())
+ {
+ logMe.append(" " + so.getMetadata() + " ");
+ }
+
+ output.message("Creating browse index " + bis[i].getName() +
+ ": index by " + bis[i].getMetadata() +
+ " sortable by: " + logMe.toString());
+ }
}
+ catch (SortException se)
+ {
+ throw new BrowseException("Error in SortOptions", se);
+ }
}
/**
@@ -884,6 +902,10 @@
context.commit();
}
}
+ catch (SortException se)
+ {
+ throw new BrowseException("Error in SortOptions", se);
+ }
catch (SQLException e)
{
log.error("caught exception: ", e);
@@ -994,6 +1016,10 @@
context.commit();
}
}
+ catch (SortException se)
+ {
+ throw new BrowseException("Error in SortOptions", se);
+ }
catch (SQLException e)
{
log.error("caught exception: ", e);
Deleted: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/SortOption.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/SortOption.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/SortOption.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -1,376 +0,0 @@
-/*
- * SortOption.java
- *
- * Copyright (c) 2002-2007, Hewlett-Packard Company and Massachusetts
- * Institute of Technology. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of the Hewlett-Packard Company nor the name of the
- * Massachusetts Institute of Technology nor the names of their
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- */
-package org.dspace.browse;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.dspace.core.ConfigurationManager;
-
-/**
- * Class to mediate with the sort configuration
- *
- * @author Richard Jones
- *
- */
-public class SortOption
-{
- public static final String ASCENDING = "ASC";
- public static final String DESCENDING = "DESC";
-
- /** the sort configuration number */
- private int number;
-
- /** the name of the sort */
- private String name;
-
- /** the metadata field to sort on */
- private String metadata;
-
- /** the type of data we are sorting by */
- private String type;
-
- /** the metadata broken down into bits for convenience */
- private String[] mdBits;
-
- /** should the sort option be visible for user selection */
- private boolean visible;
-
- /** the sort options available for this index */
- private static Set<SortOption> sortOptionsSet = null;
- private static Map<Integer, SortOption> sortOptionsMap = null;
-
- /**
- * Construct a new SortOption object with the given parameters
- *
- * @param number
- * @param name
- * @param md
- * @param type
- * @throws BrowseException
- */
- public SortOption(int number, String name, String md, String type)
- throws BrowseException
- {
- this.name = name;
- this.type = type;
- this.metadata = md;
- this.number = number;
- this.visible = true;
- generateMdBits();
- }
-
- /**
- * Construct a new SortOption object using the definition from the configuration
- *
- * @param number
- * @param definition
- * @throws BrowseException
- */
- public SortOption(int number, String definition)
- throws BrowseException
- {
- this.number = number;
-
- String rx = "(\\w+):([\\w\\.\\*]+):(\\w+):?(\\w*)";
- Pattern pattern = Pattern.compile(rx);
- Matcher matcher = pattern.matcher(definition);
-
- if (!matcher.matches())
- {
- throw new BrowseException("Sort Order configuration is not valid: webui.browse.sort-order." +
- number + " = " + definition);
- }
-
- name = matcher.group(1);
- metadata = matcher.group(2);
- type = matcher.group(3);
-
- // If the option is configured to be hidden, then set the visible flag to false
- // otherwise, flag it as visible (true)
- if (matcher.groupCount() > 3 && "hide".equalsIgnoreCase(matcher.group(4)))
- visible = false;
- else
- visible = true;
-
- generateMdBits();
- }
-
- /**
- * @return Returns the metadata.
- */
- public String getMetadata()
- {
- return metadata;
- }
-
- /**
- * @param metadata The metadata to set.
- */
- public void setMetadata(String metadata)
- {
- this.metadata = metadata;
- }
-
- /**
- * @return Returns the name.
- */
- public String getName()
- {
- return name;
- }
-
- /**
- * @param name The name to set.
- */
- public void setName(String name)
- {
- this.name = name;
- }
-
- /**
- * @return Returns the type.
- */
- public String getType()
- {
- return type;
- }
-
- /**
- * @param type The type to set.
- */
- public void setType(String type)
- {
- this.type = type;
- }
-
- /**
- * @return Returns the number.
- */
- public int getNumber()
- {
- return number;
- }
-
- /**
- * @param number The number to set.
- */
- public void setNumber(int number)
- {
- this.number = number;
- }
-
- /**
- * Should this sort option be made visible in the UI
- * @return true if visible, false otherwise
- */
- public boolean isVisible()
- {
- return visible;
- }
-
- /**
- * @return a 3 element array of the metadata bits
- */
- public String[] getMdBits()
- {
- return mdBits;
- }
-
- /**
- * Tell the class to generate the metadata bits
- *
- * @throws BrowseException
- */
- public void generateMdBits()
- throws BrowseException
- {
- try
- {
- mdBits = interpretField(metadata, null);
- }
- catch(IOException e)
- {
- throw new BrowseException(e);
- }
- }
-
- /**
- * Take a string representation of a metadata field, and return it as an array.
- * This is just a convenient utility method to basically break the metadata
- * representation up by its delimiter (.), and stick it in an array, inserting
- * the value of the init parameter when there is no metadata field part.
- *
- * @param mfield the string representation of the metadata
- * @param init the default value of the array elements
- * @return a three element array with schema, element and qualifier respectively
- */
- public String[] interpretField(String mfield, String init)
- throws IOException
- {
- StringTokenizer sta = new StringTokenizer(mfield, ".");
- String[] field = {init, init, init};
-
- int i = 0;
- while (sta.hasMoreTokens())
- {
- field[i++] = sta.nextToken();
- }
-
- // error checks to make sure we have at least a schema and qualifier for both
- if (field[0] == null || field[1] == null)
- {
- throw new IOException("at least a schema and element be " +
- "specified in configuration. You supplied: " + mfield);
- }
-
- return field;
- }
-
- /**
- * Is this a date field
- *
- * @return
- */
- public boolean isDate()
- {
- if (type != null)
- {
- if ("date".equals(type))
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Is the default sort option
- *
- * @return
- */
- public boolean isDefault()
- {
- if (number == 0)
- {
- return true;
- }
- return false;
- }
-
- /**
- * @return a map of the configured sort options
- */
- public static Map<Integer, SortOption> getSortOptionsMap() throws BrowseException
- {
- if (SortOption.sortOptionsMap != null)
- return SortOption.sortOptionsMap;
-
- SortOption.sortOptionsMap = new HashMap<Integer, SortOption>();
- synchronized (SortOption.sortOptionsMap)
- {
- for (SortOption so : SortOption.getSortOptions())
- {
- SortOption.sortOptionsMap.put(new Integer(so.getNumber()), so);
- }
- }
-
- return SortOption.sortOptionsMap;
- }
-
- /**
- * Return all the configured sort options
- * @return
- * @throws BrowseException
- */
- public static Set<SortOption> getSortOptions() throws BrowseException
- {
- if (SortOption.sortOptionsSet != null)
- return SortOption.sortOptionsSet;
-
- SortOption.sortOptionsSet = new HashSet<SortOption>();
- synchronized (SortOption.sortOptionsSet)
- {
- int idx = 1;
- String option;
-
- while ( ((option = ConfigurationManager.getProperty("webui.browse.sort-option." + idx))) != null)
- {
- SortOption so = new SortOption(idx, option);
- SortOption.sortOptionsSet.add(so);
- idx++;
- }
- }
-
- return SortOption.sortOptionsSet;
- }
-
- /**
- * Get the defined sort option by number (.1, .2, etc)
- * @param number
- * @return
- * @throws BrowseException
- */
- public static SortOption getSortOption(int number) throws BrowseException
- {
- for (SortOption so : SortOption.getSortOptions())
- {
- if (so.getNumber() == number)
- return so;
- }
-
- return null;
- }
-
- /**
- * Get the default sort option - initially, just the first one defined
- * @return
- * @throws BrowseException
- */
- public static SortOption getDefaultSortOption() throws BrowseException
- {
- for (SortOption so : getSortOptions())
- return so;
-
- return null;
- }
-}
Modified: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/content/ItemComparator.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/content/ItemComparator.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/content/ItemComparator.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -45,7 +45,7 @@
import java.util.Map;
import java.util.Set;
-import org.dspace.browse.BrowseOrder;
+import org.dspace.sort.OrderFormat;
/**
* Compare two Items by their DCValues.
@@ -256,6 +256,6 @@
return value.value;
}
- return BrowseOrder.makeSortString(value.value, value.language, BrowseOrder.TITLE);
+ return OrderFormat.makeSortString(value.value, value.language, OrderFormat.TITLE);
}
}
Modified: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/DSAnalyzer.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/DSAnalyzer.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/DSAnalyzer.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -48,6 +48,7 @@
import org.apache.lucene.analysis.StopFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.standard.StandardFilter;
+import org.dspace.core.ConfigurationManager;
/**
* Custom Lucene Analyzer that combines the standard filter, lowercase filter,
@@ -94,4 +95,14 @@
return result;
}
+
+ public int getPositionIncrementGap(String fieldName)
+ {
+ // If it is the default field, or bounded fields is turned off in the config, return the default value
+ if ("default".equalsIgnoreCase(fieldName) || !ConfigurationManager.getBooleanProperty("search.boundedfields", false))
+ return super.getPositionIncrementGap(fieldName);
+
+ // Not the default field, and we want bounded fields, so return an large gap increment
+ return 10;
+ }
}
Modified: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/DSIndexer.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/DSIndexer.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/DSIndexer.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -47,16 +47,22 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
+import java.util.Calendar;
+import java.util.TimeZone;
+import java.text.SimpleDateFormat;
+import java.text.ParseException;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.PosixParser;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
+import org.apache.lucene.document.DateTools;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
@@ -75,6 +81,8 @@
import org.dspace.core.Email;
import org.dspace.core.LogManager;
import org.dspace.handle.HandleManager;
+import org.dspace.sort.SortOption;
+import org.dspace.sort.OrderFormat;
/**
* DSIndexer contains the methods that index Items and their metadata,
@@ -111,6 +119,20 @@
String schema;
String element;
String qualifier = null;
+ String type = "text";
+
+ IndexConfig()
+ {
+ }
+
+ IndexConfig(String indexName, String schema, String element, String qualifier, String type)
+ {
+ this.indexName = indexName;
+ this.schema = schema;
+ this.element = element;
+ this.qualifier = qualifier;
+ this.type = type;
+ }
}
private static String index_directory = ConfigurationManager.getProperty("search.dir");
@@ -121,9 +143,23 @@
/** The analyzer for this DSpace instance */
private static Analyzer analyzer = null;
- // Static initialisation of index configuration /
- private static IndexConfig[] indexConfigArr = new IndexConfig[0];
-
+ /** Static initialisation of index configuration */
+ /** Includes backwards compatible default configuration */
+ private static IndexConfig[] indexConfigArr = new IndexConfig[]
+ {
+ new IndexConfig("author", "dc", "contributor", Item.ANY, "text") ,
+ new IndexConfig("author", "dc", "creator", Item.ANY, "text"),
+ new IndexConfig("author", "dc", "description", "statementofresponsibility", "text"),
+ new IndexConfig("title", "dc", "title", Item.ANY, "text"),
+ new IndexConfig("keyword", "dc", "subject", Item.ANY, "text"),
+ new IndexConfig("abstract", "dc", "description", "abstract", "text"),
+ new IndexConfig("abstract", "dc", "description", "tableofcontents", "text"),
+ new IndexConfig("series", "dc", "relation", "ispartofseries", "text"),
+ new IndexConfig("mimetype", "dc", "format", "mimetype", "text"),
+ new IndexConfig("sponsor", "dc", "description", "sponsorship", "text"),
+ new IndexConfig("identifier", "dc", "identifier", Item.ANY, "text")
+ };
+
static {
// calculate maxfieldlength
@@ -133,7 +169,7 @@
}
// read in indexes from the config
- ArrayList indexConfigList = new ArrayList();
+ ArrayList<String> indexConfigList = new ArrayList<String>();
// read in search.index.1, search.index.2....
for (int i = 1; ConfigurationManager.getProperty("search.index." + i) != null; i++)
@@ -148,7 +184,7 @@
for (int i = 0; i < indexConfigList.size(); i++)
{
indexConfigArr[i] = new IndexConfig();
- String index = (String) indexConfigList.get(i);
+ String index = indexConfigList.get(i);
String[] configLine = index.split(":");
@@ -172,6 +208,11 @@
throw new RuntimeException(
"Malformed configuration line: search.index." + i);
}
+
+ if (configLine.length > 2)
+ {
+ indexConfigArr[i].type = configLine[2];
+ }
}
}
@@ -246,7 +287,7 @@
Item item = (Item)dso;
if (item.isArchived() && !item.isWithdrawn())
{
- if(requiresIndexing(handle, ((Item)dso).getLastModified()) || force)
+ if (requiresIndexing(handle, ((Item)dso).getLastModified()) || force)
{
Document doc = buildDocument(context, (Item) dso);
@@ -696,7 +737,7 @@
* to determine if the index is stale.
*
* @param handle
- * @param dso
+ * @param lastModified
* @return
* @throws SQLException
* @throws IOException
@@ -810,17 +851,17 @@
throws SQLException, IOException
{
// Create Lucene Document
- Document doc = buildDocument(Constants.COMMUNITY, community.getHandle(), null);
+ Document doc = buildDocument(Constants.COMMUNITY, community.getID(), community.getHandle(), null);
// and populate it
String name = community.getMetadata("name");
- if(name != null)
+ if (name != null)
{
- doc.add(new Field("name", name, Field.Store.YES, Field.Index.TOKENIZED));
- doc.add(new Field("default", name, Field.Store.YES, Field.Index.TOKENIZED));
+ doc.add(new Field("name", name, Field.Store.NO, Field.Index.TOKENIZED));
+ doc.add(new Field("default", name, Field.Store.NO, Field.Index.TOKENIZED));
}
-
+
return doc;
}
@@ -839,15 +880,15 @@
String location_text = buildCollectionLocationString(context, collection);
// Create Lucene Document
- Document doc = buildDocument(Constants.COLLECTION, collection.getHandle(), location_text);
+ Document doc = buildDocument(Constants.COLLECTION, collection.getID(), collection.getHandle(), location_text);
// and populate it
String name = collection.getMetadata("name");
- if(name != null)
+ if (name != null)
{
- doc.add(new Field("name", name, Field.Store.YES, Field.Index.TOKENIZED));
- doc.add(new Field("default", name, Field.Store.YES, Field.Index.TOKENIZED));
+ doc.add(new Field("name", name, Field.Store.NO, Field.Index.TOKENIZED));
+ doc.add(new Field("default", name, Field.Store.NO, Field.Index.TOKENIZED));
}
return doc;
@@ -866,7 +907,6 @@
private static Document buildDocument(Context context, Item item)
throws SQLException, IOException
{
-
String handle = item.getHandle();
if(handle == null)
@@ -877,7 +917,7 @@
// get the location string (for searching by collection & community)
String location = buildItemLocationString(context, item);
- Document doc = buildDocument(Constants.ITEM, handle, location);
+ Document doc = buildDocument(Constants.ITEM, item.getID(), handle, location);
log.debug("Building Item: " + handle);
@@ -902,131 +942,70 @@
mydc = item.getMetadata(indexConfigArr[i].schema, indexConfigArr[i].element, indexConfigArr[i].qualifier, Item.ANY);
}
- // put them all from an array of strings to one string for
- // writing out pack all of the arrays of DCValues into plain
- // text strings for the indexer
- String content_text = "";
-
for (j = 0; j < mydc.length; j++)
{
- content_text = new String(content_text + mydc[j].value + " ");
+ if (!StringUtils.isEmpty(mydc[j].value))
+ {
+ if ("timestamp".equalsIgnoreCase(indexConfigArr[i].type))
+ {
+ Date d = toDate(mydc[j].value);
+ if (d != null)
+ {
+ doc.add( new Field(indexConfigArr[i].indexName,
+ DateTools.dateToString(d, DateTools.Resolution.SECOND),
+ Field.Store.NO,
+ Field.Index.TOKENIZED));
+ }
+ }
+ else if ("date".equalsIgnoreCase(indexConfigArr[i].type))
+ {
+ Date d = toDate(mydc[j].value);
+ if (d != null)
+ {
+ doc.add( new Field(indexConfigArr[i].indexName,
+ DateTools.dateToString(d, DateTools.Resolution.DAY),
+ Field.Store.NO,
+ Field.Index.TOKENIZED));
+ }
+ }
+ else
+ {
+ // TODO: use a delegate to allow custom 'types' to be used to reformat the field
+ doc.add( new Field(indexConfigArr[i].indexName,
+ mydc[j].value,
+ Field.Store.NO,
+ Field.Index.TOKENIZED));
+ }
+
+ doc.add( new Field("default", mydc[j].value, Field.Store.NO, Field.Index.TOKENIZED));
+ }
}
+ }
+ }
- // arranges content with fields in ArrayLists with same index to
- // put
- // into hash later
- k = fields.indexOf(indexConfigArr[i].indexName);
+ log.debug(" Added Metadata");
- if (k < 0)
+ try
+ {
+ // Now get the configured sort options, and add those as untokenized fields
+ // Note that we will use the sort order delegates to normalise the values written
+ for (SortOption so : SortOption.getSortOptions())
+ {
+ String[] somd = so.getMdBits();
+ DCValue[] dcv = item.getMetadata(somd[0], somd[1], somd[2], Item.ANY);
+ if (dcv.length > 0)
{
- fields.add(indexConfigArr[i].indexName);
- content.add(content_text);
+ String value = OrderFormat.makeSortString(dcv[0].value, dcv[0].language, so.getType());
+ doc.add( new Field("sort_" + so.getName(), value, Field.Store.NO, Field.Index.UN_TOKENIZED) );
}
- else
- {
- content_text = new String(content_text
- + (String) content.get(k) + " ");
- content.set(k, content_text);
- }
}
-
- // build the hash
- for (int i = 0; i < fields.size(); i++)
- {
-
- doc.add(
- new Field(
- (String) fields.get(i),
- (String) content.get(i),
- Field.Store.YES, Field.Index.TOKENIZED
- ));
-
- doc.add(new Field("default", (String) content.get(i), Field.Store.YES, Field.Index.TOKENIZED));
- }
}
- else
- // if no search indexes found in cfg file, for backward compatibility
+ catch (Exception e)
{
- // extract metadata (ANY is wildcard from Item class)
- DCValue[] authors = item.getDC("contributor", Item.ANY, Item.ANY);
- for (j = 0; j < authors.length; j++)
- {
- doc.add(new Field("author", authors[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- doc.add(new Field("default", authors[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- }
-
- DCValue[] creators = item.getDC("creator", Item.ANY, Item.ANY);
- for (j = 0; j < creators.length; j++) //also authors
- {
- doc.add(new Field("author", creators[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- doc.add(new Field("default", creators[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- }
-
- DCValue[] sors = item.getDC("description", "statementofresponsibility", Item.ANY);
- for (j = 0; j < sors.length; j++) //also authors
- {
- doc.add(new Field("author", sors[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- doc.add(new Field("default", sors[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- }
-
- DCValue[] titles = item.getDC("title", Item.ANY, Item.ANY);
- for (j = 0; j < titles.length; j++)
- {
- doc.add(new Field("title", titles[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- doc.add(new Field("default", titles[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- }
-
- DCValue[] keywords = item.getDC("subject", Item.ANY, Item.ANY);
- for (j = 0; j < keywords.length; j++)
- {
- doc.add(new Field("keyword", keywords[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- doc.add(new Field("default", keywords[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- }
-
- DCValue[] abstracts = item.getDC("description", "abstract", Item.ANY);
- for (j = 0; j < abstracts.length; j++)
- {
- doc.add(new Field("abstract", abstracts[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- doc.add(new Field("default", abstracts[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- }
-
- DCValue[] tocs = item.getDC("description", "tableofcontents", Item.ANY);
- for (j = 0; j < tocs.length; j++)
- {
- doc.add(new Field("abstract", tocs[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- doc.add(new Field("default", tocs[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- }
-
- DCValue[] series = item.getDC("relation", "ispartofseries", Item.ANY);
- for (j = 0; j < series.length; j++)
- {
- doc.add(new Field("series", series[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- doc.add(new Field("default", series[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- }
-
- DCValue[] mimetypes = item.getDC("format", "mimetype", Item.ANY);
- for (j = 0; j < mimetypes.length; j++)
- {
- doc.add(new Field("mimetype", mimetypes[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- doc.add(new Field("default", mimetypes[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- }
-
- DCValue[] sponsors = item.getDC("description", "sponsorship", Item.ANY);
- for (j = 0; j < sponsors.length; j++)
- {
- doc.add(new Field("sponsor", sponsors[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- doc.add(new Field("default", sponsors[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- }
-
- DCValue[] identifiers = item.getDC("identifier", Item.ANY, Item.ANY);
- for (j = 0; j < identifiers.length; j++)
- {
- doc.add(new Field("identifier", identifiers[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- doc.add(new Field("default", identifiers[j].value, Field.Store.YES, Field.Index.TOKENIZED));
- }
+ log.error(e.getMessage(),e);
}
- log.debug(" Added Metadata");
+ log.debug(" Added Sorting");
try
{
@@ -1077,11 +1056,11 @@
* Create Lucene document with all the shared fields initialized.
*
* @param type Type of DSpace Object
- * @param handle
- * @param location
- * @return
+ * @param id
+ *@param handle
+ * @param location @return
*/
- private static Document buildDocument(int type, String handle, String location)
+ private static Document buildDocument(int type, int id, String handle, String location)
{
Document doc = new Document();
@@ -1089,10 +1068,14 @@
// (not tokenized, but it is indexed)
doc.add(new Field(LAST_INDEXED_FIELD, Long.toString(System.currentTimeMillis()), Field.Store.YES, Field.Index.UN_TOKENIZED));
-
+ // KEPT FOR BACKWARDS COMPATIBILITY
// do location, type, handle first
doc.add(new Field("type", Integer.toString(type), Field.Store.YES, Field.Index.NO));
+ // New fields to weaken the dependence on handles, and allow for faster list display
+ doc.add(new Field("search.resourcetype", Integer.toString(type), Field.Store.YES, Field.Index.NO));
+ doc.add(new Field("search.resourceid", Integer.toString(id), Field.Store.YES, Field.Index.NO));
+
// want to be able to search for handle, so use keyword
// (not tokenized, but it is indexed)
if (handle != null)
@@ -1105,17 +1088,72 @@
doc.add(new Field("handle", handle, Field.Store.YES, Field.Index.UN_TOKENIZED));
// add to full text index
- doc.add(new Field("default", handle, Field.Store.YES, Field.Index.TOKENIZED));
+ doc.add(new Field("default", handle, Field.Store.NO, Field.Index.TOKENIZED));
}
if(location != null)
{
- doc.add(new Field("location", location, Field.Store.YES, Field.Index.TOKENIZED));
- doc.add(new Field("default", location, Field.Store.YES, Field.Index.TOKENIZED));
+ doc.add(new Field("location", location, Field.Store.NO, Field.Index.TOKENIZED));
+ doc.add(new Field("default", location, Field.Store.NO, Field.Index.TOKENIZED));
}
return doc;
}
+ /**
+ * Helper function to retrieve a date using a best guess of the potential date encodings on a field
+ *
+ * @param t
+ * @return
+ */
+ private static Date toDate(String t)
+ {
+ SimpleDateFormat[] dfArr;
+ // Choose the likely date formats based on string length
+ switch (t.length())
+ {
+ case 4:
+ dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy") };
+ break;
+ case 6:
+ dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyyMM") };
+ break;
+ case 7:
+ dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy-MM") };
+ break;
+ case 8:
+ dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyyMMdd"), new SimpleDateFormat("yyyy MMM") };
+ break;
+ case 10:
+ dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy-MM-dd") };
+ break;
+ case 11:
+ dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy MMM dd") };
+ break;
+ case 20:
+ dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") };
+ break;
+ default:
+ dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") };
+ break;
+ }
+
+
+ for (SimpleDateFormat df : dfArr)
+ {
+ try
+ {
+ // Parse the date
+ df.setCalendar(Calendar.getInstance(TimeZone.getTimeZone("UTC")));
+ return df.parse(t);
+ }
+ catch (ParseException pe)
+ {
+ log.error("Unable to parse date format", pe);
+ }
+ }
+
+ return null;
+ }
}
Modified: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/DSQuery.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/DSQuery.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/DSQuery.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -40,7 +40,6 @@
package org.dspace.search;
import java.io.IOException;
-import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -56,6 +55,8 @@
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortField;
import org.apache.oro.text.perl.Perl5Util;
import org.dspace.content.Collection;
import org.dspace.content.Community;
@@ -63,6 +64,7 @@
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.LogManager;
+import org.dspace.sort.SortOption;
// issues
// need to filter query string for security
@@ -123,10 +125,12 @@
String querystring = args.getQuery();
QueryResults qr = new QueryResults();
List hitHandles = new ArrayList();
- List hitTypes = new ArrayList();
+ List hitIds = new ArrayList();
+ List hitTypes = new ArrayList();
// set up the QueryResults object
qr.setHitHandles(hitHandles);
+ qr.setHitIds(hitIds);
qr.setHitTypes(hitTypes);
qr.setStart(args.getStart());
qr.setPageSize(args.getPageSize());
@@ -159,8 +163,18 @@
}
Query myquery = qp.parse(querystring);
- Hits hits = searcher.search(myquery);
+ Hits hits = null;
+ if (args.getSortOption() == null)
+ {
+ hits = searcher.search(myquery, new Sort(new SortField[] { new SortField("type"), SortField.FIELD_SCORE }));
+ }
+ else
+ {
+ SortField[] sortFields = new SortField[] { new SortField("type"), new SortField("sort_" + args.getSortOption().getName(), SortOption.DESCENDING.equals(args.getSortOrder())), SortField.FIELD_SCORE };
+ hits = searcher.search(myquery, new Sort(sortFields));
+ }
+
// set total number of hits
qr.setHitCount(hits.length());
@@ -181,52 +195,47 @@
{
Document d = hits.doc(i);
+ String resourceId = d.get("search.resourceid");
+ String resourceType = d.get("search.resourcetype");
+
String handleText = d.get("handle");
- String handletype = d.get("type");
+ String handleType = d.get("type");
- hitHandles.add(handleText);
+ switch (Integer.parseInt( resourceType != null ? resourceType : handleType))
+ {
+ case Constants.ITEM:
+ hitTypes.add(new Integer(Constants.ITEM));
+ break;
- if (handletype.equals("" + Constants.ITEM))
- {
- hitTypes.add(new Integer(Constants.ITEM));
+ case Constants.COLLECTION:
+ hitTypes.add(new Integer(Constants.COLLECTION));
+ break;
+
+ case Constants.COMMUNITY:
+ hitTypes.add(new Integer(Constants.COMMUNITY));
+ break;
}
- else if (handletype.equals("" + Constants.COLLECTION))
- {
- hitTypes.add(new Integer(Constants.COLLECTION));
- }
- else if (handletype.equals("" + Constants.COMMUNITY))
- {
- hitTypes.add(new Integer(Constants.COMMUNITY));
- }
- else
- {
- // error! unknown type!
- }
+
+ hitHandles.add( handleText );
+ hitIds.add( resourceId == null ? null: Integer.parseInt(resourceId) );
}
}
}
catch (NumberFormatException e)
{
- log
- .warn(LogManager.getHeader(c, "Number format exception", ""
- + e));
-
+ log.warn(LogManager.getHeader(c, "Number format exception", "" + e));
qr.setErrorMsg("Number format exception");
}
catch (ParseException e)
{
// a parse exception - log and return null results
log.warn(LogManager.getHeader(c, "Invalid search string", "" + e));
-
qr.setErrorMsg("Invalid search string");
}
catch (TokenMgrError tme)
{
// Similar to parse exception
- log
- .warn(LogManager.getHeader(c, "Invalid search string", ""
- + tme));
-
+ log.warn(LogManager.getHeader(c, "Invalid search string", "" + tme));
qr.setErrorMsg("Invalid search string");
}
catch(BooleanQuery.TooManyClauses e)
@@ -387,6 +396,25 @@
}
}
+ /**
+ * Close any IndexSearcher that is currently open.
+ */
+ public static void close()
+ {
+ if (searcher != null)
+ {
+ try
+ {
+ searcher.close();
+ searcher = null;
+ }
+ catch (IOException ioe)
+ {
+ log.error("DSQuery: Unable to close open IndexSearcher", ioe);
+ }
+ }
+ }
+
public static void main(String[] args)
{
if (args.length > 0)
Modified: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/QueryArgs.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/QueryArgs.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/QueryArgs.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -47,6 +47,7 @@
import javax.servlet.http.HttpServletRequest;
import org.dspace.core.Constants;
+import org.dspace.sort.SortOption;
import org.apache.oro.text.perl.Perl5Util;
@@ -64,6 +65,10 @@
private int pageSize = 10;
+ private SortOption sortOption = null;
+
+ private String sortOrder = SortOption.ASCENDING;
+
/**
* set the query string
*
@@ -128,6 +133,26 @@
return pageSize;
}
+ public SortOption getSortOption()
+ {
+ return sortOption;
+ }
+
+ public void setSortOption(SortOption sortOption)
+ {
+ this.sortOption = sortOption;
+ }
+
+ public String getSortOrder()
+ {
+ return sortOrder;
+ }
+
+ public void setSortOrder(String sortOrder)
+ {
+ this.sortOrder = sortOrder;
+ }
+
/**
* Builds an advanced-query description string.
*
Modified: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/QueryResults.java
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/QueryResults.java 2008-01-10 10:20:48 UTC (rev 2507)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/search/QueryResults.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -56,8 +56,8 @@
private List hitHandles; // handles of content (items, collections,
// communities)
- private List hitTypes; // Integers from Constants defng types of
- // corresponding handles
+ private List hitTypes; // Resource type - from Constants
+ private List hitIds; // Resource ids
private String errorMsg; //error string, if there is one
@@ -112,6 +112,18 @@
return hitHandles;
}
+ /** set the List of ids corresponding to hits */
+ public void setHitIds(List myHits)
+ {
+ hitIds = myHits;
+ }
+
+ /** get the List of handles corresponding to hits */
+ public List getHitIds()
+ {
+ return hitIds;
+ }
+
/** set the List of types corresponding to handles */
public void setHitTypes(List newTypes)
{
Copied: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/sort/OrderFormat.java (from rev 2488, branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrder.java)
===================================================================
--- branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/sort/OrderFormat.java (rev 0)
+++ branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/sort/OrderFormat.java 2008-01-10 14:03:36 UTC (rev 2508)
@@ -0,0 +1,146 @@
+/*
+ * OrderFormat.java
+ *
+ * Version: $Revision: 1.0 $
+ *
+ * Date: $Date: 2007/03/02 11:22:13 $
+ *
+ * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
+ * Institute of Technology. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - Neither the name of the Hewlett-Packard Company nor the name of the
+ * Massachusetts Institute of Technology nor the names of their
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+package org.dspace.sort;
+
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.dspace.core.PluginManager;
+import org.dspace.sort.OrderFormatDelegate;
+import org.dspace.sort.OrderFormatAuthor;
+import org.dspace.sort.OrderFormatTitle;
+import org.dspace.sort.OrderFormatText;
+
+/**
+ * Class implementing static helpers for anywhere that interacts with the sort columns
+ * (ie. ItemsByAuthor.sort_author, ItemsByTitle.sort_title)
+ *
+ * This class maps index 'types' to delegates that implement the sort string creation
+ *
+ * Types can be defined or configured using the plugin manager:
+ *
+ * plugin.named.org.dspace.sort.OrderFormatDelegate=
+ * org.dspace.sort.OrderFormatTitleMarc21=title
+ * org.dspace.sort.OrderFormatAuthor=author
+ *
+ * The following standard types have been defined by default, but can be reconfigured
+ * via the plugin manager:
+ *
+ * author = org.dspace.sort.OrderFormatAuthor
+ * title = org.dspace.sort.OrderFormatTitle
+ * text = org.dspace.sort.OrderFormatText
+ *
+ * IMPORTANT - If you change any of the orderings, you need to rebuild the browse sort columns
+ * (ie. run 'index-all', or 'dsrun org.dspace.browse.InitializeBrowse')
+ *
+ * @author Graham Triggs
+ * @version $Revision: 1.0 $
+ */
+public class OrderFormat
+{
+ private final static Logger log = LogManager.getLogger(OrderFormat.class);
+
+ public final static String AUTHOR = "author";
+ public final static String TITLE = "title";
+ public final static String TEXT = "text";
+
+ // Array of all available order delegates - avoids excessive calls to plugin manager
+ private final static String[] delegates = PluginManager.getAllPluginNames(OrderFormatDelegate.class);
+
+ private final static OrderFormatDelegate authorDelegate = new OrderFormatAuthor();
+ private final static OrderFormatDelegate titleDelegate = new OrderFormatTitle();
+ private final static OrderFormatDelegate textDelegate = new OrderFormatText();
+
+ /**
+ * Generate a sort string for the given DC metadata
+ */
+ public static String makeSortString(String value, String language, String type)
+ {
+ OrderFormatDelegate delegate = null;
+
+ // If a named index has been supplied
+ if (type != null && type.length() > 0)
+ {
+ // Use a delegate if one is configured
+ if ((delegate = OrderFormat.getDelegate(type)) != null)
+ {
+ return delegate.makeSortString(value, language);
+ }
+ }
+
+ // No delegates found, so apply defaults
+ if (type.equalsIgnoreCase(OrderFormat.AUTHOR) && authorDelegate != null)
+ {
+ return authorDelegate.makeSortString(value, language);
+ }
+
+ if (type.equalsIgnoreCase(OrderFormat.TITLE) && titleDelegate != null)
+ {
+ return titleDelegate.makeSortString(value, language);
+ }
+
+ if (type.equalsIgnoreCase(OrderFormat.TEXT) && textDelegate != null)
+ {
+ return textDelegate.makeSortString(value, language);
+ }
+
+ return value;
+ }
+
+ /**
+ * Retrieve the named delegate
+ */
+ private static OrderFormatDelegate getDelegate(String name)
+ {
+ if (name != null && name.length() > 0)
+ {
+ // Check the cached array of names to see if the delegate has been configured
+ for (int idx = 0; idx < delegates.length; idx++)
+ {
+ if (delegates[idx].equals(name))
+ {
+ return (OrderFormatDelegate)PluginManager.getNamedPlugin(OrderFormatDelegate.class, name);
+ }
+ }
+ }
+
+ return null;
+ }
+}
Copied: branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/sort/OrderFormatAuthor.java (from rev 2488, branches/dspace-1_5_x/dspace-api/src/main/java/org/dspace/browse/BrowseOrderAuthor.java)
===================================================================
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|