From b23cb050d1639bb5eedc70b36e4e3964c94a9925 Mon Sep 17 00:00:00 2001 From: Rania Stathopoulou Date: Mon, 17 Sep 2012 11:13:30 +0200 Subject: [PATCH] Merge pull request #55 from EKT/DS-1231 [DS-1231] Indexing both stored and display-value from input-forms for search Squashed commit of the following: commit 426db183fc10b0f3a2e96dd1a27d4bf926f36bb8 Merge: b05c6a3 8334fce Author: kstamatis Date: Sat Sep 15 08:52:12 2012 -0700 Merge pull request #2 from abollini/DS-1231 Ds 1231 commit 8334fceed0c00358a54c9d0562e0564becc48e22 Author: Andrea Bollini Date: Sat Sep 15 17:31:08 2012 +0200 Use the default input set if the item is not yet archived commit c6be36259241f84a3eb8f84cbf2efccb01a41c5e Author: Andrea Bollini Date: Sat Sep 15 17:23:48 2012 +0200 Minor changes Code formatted using the dspace style eclipse formatter No store values in the index as the lucene projection is not currently used use generics to avoid raw type warning commit 6e6933d174a2dfaf649c220865f51fa35829f8a2 Merge: 3b1cc06 b05c6a3 Author: Andrea Bollini Date: Sat Sep 15 16:19:20 2012 +0200 Merge remote-tracking branch 'EKT/DS-1231' into DS-1231 commit b05c6a32886bfb7349e86aa94812092f65360222 Author: Rania Stathopoulou Date: Fri Sep 14 19:49:27 2012 +0300 Search indexing all values (now getControlledVocabulariesDisplayValueLocalized returns a list of all the values and the DSIndexer manages these values) A return statement is added if the item has no collection commit 33da186e6c6558646d636056ebe3ae91783e18e9 Author: Rania Stathopoulou Date: Thu Sep 13 11:19:56 2012 +0300 Code Indentation commit c31651bdd8de15588d78b97eba2abeb69b803924 Author: Rania Stathopoulou Date: Tue Sep 11 11:54:43 2012 +0300 Code changed in order to index both stored and display-value for all localized input-forms if the user specifies 'inputform' in Search Index Configuration of dspace.cfg, e.g: search.index.12 = language:dc.language:inputform commit d278958c22fc1a1ef33b5f5562135eec5f299e0f Author: Rania Stathopoulou Date: Fri Sep 7 12:19:25 2012 +0300 Package name 'gr.ekt.repositories.dspace.utils' removed. All functions in gr.ekt.repositories.dspace.utils.Utilities.java were transfered in org.dspace.app.util.Util.java Documentation added for the above functions commit 8135fd4eb70b25a7fc1b0e77b5e36199c68b02dd Author: EKT Date: Wed Aug 8 18:40:40 2012 +0300 Unthrown exceptions added commit fa8796bfebaee3cd0c2e9f2d7a0cc86b8f936a76 Author: EKT Date: Wed Aug 8 17:06:20 2012 +0300 Indexing both stored and display-value from input-forms for search --- .../main/java/org/dspace/app/util/Util.java | 116 ++++++++++++++++++ .../java/org/dspace/search/DSIndexer.java | 55 ++++++++- dspace/config/dspace.cfg | 7 +- 3 files changed, 171 insertions(+), 7 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/app/util/Util.java b/dspace-api/src/main/java/org/dspace/app/util/Util.java index ff487ca8db..c714f2e94b 100644 --- a/dspace-api/src/main/java/org/dspace/app/util/Util.java +++ b/dspace-api/src/main/java/org/dspace/app/util/Util.java @@ -9,16 +9,23 @@ package org.dspace.app.util; import java.io.IOException; import java.io.InputStream; +import java.sql.SQLException; import java.text.DecimalFormat; import java.text.NumberFormat; +import java.util.ArrayList; import java.util.Enumeration; +import java.util.List; import java.util.Locale; import java.util.Properties; import javax.servlet.http.HttpServletRequest; import org.apache.log4j.Logger; +import org.dspace.content.Collection; +import org.dspace.content.DCValue; +import org.dspace.content.Item; import org.dspace.core.Constants; +import org.dspace.core.I18nUtil; /** @@ -350,4 +357,113 @@ public class Util { } return sourceVersion; } + + /** + * Get a list of all the respective "displayed-value(s)" from the given + * "stored-value(s)" for a specific metadata field of a DSpace Item, by + * reading input-forms.xml + * + * @param item + * The Dspace Item + * @param values + * A DCValue[] array of the specific "stored-value(s)" + * @param schema + * A String with the schema name of the metadata field + * @param element + * A String with the element name of the metadata field + * @param qualifier + * A String with the qualifier name of the metadata field + * @return A list of the respective "displayed-values" + */ + + public static List getControlledVocabulariesDisplayValueLocalized( + Item item, DCValue[] values, String schema, String element, + String qualifier, Locale locale) throws SQLException, + DCInputsReaderException + { + List toReturn = new ArrayList(); + DCInput myInputs = null; + boolean myInputsFound = false; + String formFileName = I18nUtil.getInputFormsFileName(locale); + String col_handle = ""; + + Collection collection = item.getOwningCollection(); + + if (collection == null) + { + // set an empty handle so to get the default input set + col_handle = ""; + } + else + { + col_handle = collection.getHandle(); + } + + // Read the input form file for the specific collection + DCInputsReader inputsReader = new DCInputsReader(formFileName); + + DCInputSet inputSet = inputsReader.getInputs(col_handle); + + // Replace the values of DCValue[] with the correct ones in case of + // controlled vocabularies + String currentField = schema + "." + element + + (qualifier == null ? "" : "." + qualifier); + + if (inputSet != null) + { + + int pageNums = inputSet.getNumberPages(); + + for (int p = 0; p < pageNums; p++) + { + + DCInput[] inputs = inputSet.getPageRows(p, false, false); + + if (inputs != null) + { + + for (int i = 0; i < inputs.length; i++) + { + String inputField = inputs[i].getSchema() + + "." + + inputs[i].getElement() + + (inputs[i].getQualifier() == null ? "" : "." + + inputs[i].getQualifier()); + if (currentField.equals(inputField)) + { + + myInputs = inputs[i]; + myInputsFound = true; + break; + + } + } + } + if (myInputsFound) + break; + } + } + + if (myInputsFound) + { + + for (int j = 0; j < values.length; j++) + { + + String pairsName = myInputs.getPairsType(); + String stored_value = values[j].value; + String displayVal = myInputs.getDisplayString(pairsName, + stored_value); + + if (displayVal != null && !"".equals(displayVal)) + { + + toReturn.add(displayVal); + } + + } + } + + return toReturn; + } } diff --git a/dspace-api/src/main/java/org/dspace/search/DSIndexer.java b/dspace-api/src/main/java/org/dspace/search/DSIndexer.java index fdbb686e77..d104e95505 100644 --- a/dspace-api/src/main/java/org/dspace/search/DSIndexer.java +++ b/dspace-api/src/main/java/org/dspace/search/DSIndexer.java @@ -66,6 +66,9 @@ import org.dspace.handle.HandleManager; import org.dspace.sort.SortOption; import org.dspace.sort.OrderFormat; +import org.dspace.app.util.DCInputsReaderException; +import org.dspace.app.util.Util; + /** * DSIndexer contains the methods that index Items and their metadata, * collections, communities, etc. It is meant to either be invoked from the @@ -251,7 +254,7 @@ public class DSIndexer * @throws SQLException * @throws IOException */ - public static void indexContent(Context context, DSpaceObject dso) throws SQLException + public static void indexContent(Context context, DSpaceObject dso) throws SQLException, DCInputsReaderException { indexContent(context, dso, false); } @@ -267,7 +270,7 @@ public class DSIndexer * @throws SQLException * @throws IOException */ - public static void indexContent(Context context, DSpaceObject dso, boolean force) throws SQLException + public static void indexContent(Context context, DSpaceObject dso, boolean force) throws SQLException, DCInputsReaderException { try { @@ -649,7 +652,7 @@ public class DSIndexer } - static IndexingTask prepareIndexingTask(DSpaceObject dso, boolean force) throws SQLException, IOException + static IndexingTask prepareIndexingTask(DSpaceObject dso, boolean force) throws SQLException, IOException, DCInputsReaderException { String handle = dso.getHandle(); Term term = new Term("handle", handle); @@ -1037,7 +1040,7 @@ public class DSIndexer * @throws SQLException * @throws IOException */ - private static Document buildDocumentForItem(Item item) throws SQLException, IOException + private static Document buildDocumentForItem(Item item) throws SQLException, IOException, DCInputsReaderException { String handle = item.getHandle(); @@ -1065,7 +1068,49 @@ public class DSIndexer mydc = item.getMetadata(indexConfigArr[i].schema, indexConfigArr[i].element, indexConfigArr[i].qualifier, Item.ANY); } - for (j = 0; j < mydc.length; j++) + + //Index the controlled vocabularies localized display values for all localized input-forms.xml (e.g. input-forms_el.xml) + if ("inputform".equalsIgnoreCase(indexConfigArr[i].type)){ + + List newValues = new ArrayList(); + Locale[] supportedLocales=I18nUtil.getSupportedLocales(); + + // Get the display value of the respective stored value + for (int k = 0; k < supportedLocales.length; k++) + { + List displayValues = Util + .getControlledVocabulariesDisplayValueLocalized( + item, mydc, indexConfigArr[i].schema, + indexConfigArr[i].element, + indexConfigArr[i].qualifier, + supportedLocales[k]); + if (displayValues != null && !displayValues.isEmpty()) + { + for (int d = 0; d < displayValues.size(); d++) + { + newValues.add(displayValues.get(d)); + } + } + + } + + if (newValues!=null){ + for (int m=0;m In case we have different input-forms for different repository supported locales (e.g input-forms_el.xml, input-forms_pt.xml etc). In this case, the +# stored and the displayed value from all input-forms are indexed. If the stored value is not found in input-forms, it is indexed anyway. +# e.g.:search.index.12 = language:dc.language:inputform +# ### changing these will change your search results, ### ### but will NOT automatically change your search displays ###