Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ufal/update-index-for-language #424

Merged
merged 5 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dspace.authorize.AuthorizeException;
Expand All @@ -23,6 +24,7 @@
import org.dspace.content.service.ItemService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.discovery.IsoLangCodes;
import org.dspace.embargo.service.EmbargoService;
import org.dspace.event.Event;
import org.dspace.identifier.Identifier;
Expand Down Expand Up @@ -200,6 +202,9 @@ protected void populateMetadata(Context c, Item item)
// Add provenance description
itemService.addMetadata(c, item, MetadataSchemaEnum.DC.getName(),
"description", "provenance", "en", provDescription);

// Add language name into metadata. The lang name is fetched from the `lang_codes.txt`.
addLanguageNameToMetadata(c, item);
}

/**
Expand Down Expand Up @@ -271,4 +276,32 @@ public String getBitstreamProvenanceMessage(Context context, Item myitem)

return myMessage.toString();
}

/**
* Language is stored in the metadatavalue in the ISO format e.g., `fra, cse,..` and not in the human satisfying
* format e.g., `France, Czech`. This method converts ISO format into human satisfying format e.g., `cse -> Czech`
* and stores it into `local.language.name` metadata field.
* @param c
* @param item
* @throws SQLException
*/
private void addLanguageNameToMetadata(Context c, Item item) throws SQLException {
itemService.clearMetadata(c, item, "local", "language", "name", null);
List<MetadataValue> languageMetadata = itemService.getMetadataByMetadataString(item, "dc.language.iso");
for (MetadataValue mv: languageMetadata) {
if (StringUtils.isBlank(mv.getValue())) {
log.error("Cannot get name of the iso language (`dc.language.iso`) because the value is blank.");
return;
}
String langName = IsoLangCodes
.getLangForCode(mv.getValue());
if (StringUtils.isBlank(langName)) {
log.error(String
.format("No language found for iso code %s",
langName));
return;
}
itemService.addMetadata(c, item, "local", "language", "name", null, langName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

/* Created for LINDAT/CLARIAH-CZ (UFAL) */
package org.dspace.utils;
package org.dspace.discovery;

import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -21,6 +21,7 @@
/**
* Class is copied from the LINDAT/CLARIAH-CZ (https://github.com/ufal/clarin-dspace/blob
* /si-master-origin/dspace-api/src/main/java/cz/cuni/mff/ufal/IsoLangCodes.java) and modified by
*
* @author Marian Berger (marian.berger at dataquest.sk)
*/
public class IsoLangCodes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,12 @@ protected String transformFacetField(DiscoverFacetField facetFieldConfig, String
}
} else if (facetFieldConfig.getType().equals(DiscoveryConfigurationParameters.TYPE_STANDARD)) {
return field;
} else if (facetFieldConfig.getType().equals(DiscoveryConfigurationParameters.TYPE_ISO_LANG)) {
if (removePostfix) {
return field.substring(0, field.lastIndexOf("_filter"));
} else {
return field + "_filter";
}
} else {
return field;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class DiscoveryConfigurationParameters {
public static final String TYPE_AUTHORITY = "authority";
public static final String TYPE_STANDARD = "standard";

public static final String TYPE_ISO_LANG = "iso_language";

public static enum SORT { VALUE, COUNT }

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
import org.dspace.core.Context;
import org.dspace.core.LogHelper;
import org.dspace.discovery.FullTextContentStreams;
import org.dspace.discovery.IsoLangCodes;
import org.dspace.discovery.SearchUtils;
import org.dspace.discovery.SolrServiceImpl;
import org.dspace.discovery.configuration.DiscoveryConfiguration;
import org.dspace.discovery.configuration.DiscoveryConfigurationParameters;
import org.dspace.discovery.configuration.DiscoveryHitHighlightFieldConfiguration;
Expand Down Expand Up @@ -819,6 +821,20 @@ private void indexIfFilterTypeFacet(SolrInputDocument doc, DiscoverySearchFilter
}
//Also add prefix field with all parts of value
saveFacetPrefixParts(doc, searchFilter, value, separator, authority, preferedLabel);
} else if (searchFilter.getType().equals(DiscoveryConfigurationParameters.TYPE_ISO_LANG)) {
String langName = IsoLangCodes
.getLangForCode(value);
if (StringUtils.isBlank(langName)) {
log.error(String
.format("No language found for iso code %s",
value));
return;
}
String convertedValue = langName.toLowerCase() + SearchUtils.FILTER_SEPARATOR + langName;
doc.addField(searchFilter.getIndexFieldName() + "_filter", convertedValue);
doc.addField(searchFilter.getIndexFieldName(), langName);
doc.addField(searchFilter.getIndexFieldName() + "_keyword", langName);
doc.addField(searchFilter.getIndexFieldName() + "_ac", langName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

package org.dspace.xoai.services.impl.resources.functions;

import org.dspace.utils.IsoLangCodes;
import org.dspace.discovery.IsoLangCodes;

/**
* Serves as proxy for call from XSL engine. Calls SpecialItemService.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static Matcher<? super Object> clarinLicenseRightsFacet(boolean hasNext)
public static Matcher<? super Object> clarinItemsLanguageFacet(boolean hasNext) {
return allOf(
hasJsonPath("$.name", is("language")),
hasJsonPath("$.facetType", is("standard")),
hasJsonPath("$.facetType", is("iso_language")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/language")),
hasJsonPath("$._links", matchNextLink(hasNext, "api/discover/facets/language"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public static Matcher<? super Object> clarinItemsLanguageFilter() {
return allOf(
hasJsonPath("$.filter", is("language")),
hasJsonPath("$.hasFacets", is(true)),
hasJsonPath("$.type", is("standard")),
hasJsonPath("$.type", is("iso_language")),
hasJsonPath("$.openByDefault", is(false)),
checkOperators()
);
Expand Down
7 changes: 7 additions & 0 deletions dspace/config/registries/local-types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,11 @@
. Check/extend html.xsl for available variables.</scope_note>
</dc-type>

<dc-type>
<schema>local</schema>
<element>language</element>
<qualifier>name</qualifier>
<scope_note>ISO language name</scope_note>
</dc-type>

</dspace-dc-types>
2 changes: 1 addition & 1 deletion dspace/config/spring/api/discovery.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2463,7 +2463,7 @@
<property name="facetLimit" value="5"/>
<property name="sortOrderSidebar" value="COUNT"/>
<property name="sortOrderFilterPage" value="COUNT"/>
<property name="type" value="standard"/>
<property name="type" value="iso_language"/>
</bean>

<bean id="searchFilterItemsCommunity" class="org.dspace.discovery.configuration.DiscoverySearchFilterFacet">
Expand Down
1 change: 1 addition & 0 deletions scripts/fast-build/dspace-api-package-update.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ call mvn clean package

rem copy created jar into tomcat/webapps/server
xcopy /e /h /i /q /y %dspace_source%\dspace-api\target\dspace-api-7.5.jar %tomcat%\webapps\server\WEB-INF\lib\
xcopy /e /h /i /q /y %dspace_source%\dspace-api\target\dspace-api-7.5.jar %dspace_application%\lib\

cd %dspace_source%\scripts\fast-build\

Loading