diff --git a/src/main/java/eu/openaire/api/dto/request/DataSourceRequest.java b/src/main/java/eu/openaire/api/dto/request/DataSourceRequest.java index 917a322..7e92774 100644 --- a/src/main/java/eu/openaire/api/dto/request/DataSourceRequest.java +++ b/src/main/java/eu/openaire/api/dto/request/DataSourceRequest.java @@ -67,7 +67,7 @@ public class DataSourceRequest { private String[] contentTypes; @Parameter( - description = "Retrieve data sources connected to the organization with OpenAIRE id", + description = "Retrieve data sources connected to the organization (with OpenAIRE id)", array = @ArraySchema(schema = @Schema(type = "string")) ) private String[] relOrganizationId; diff --git a/src/main/java/eu/openaire/api/mappers/query/DataSourceRequestMapper.java b/src/main/java/eu/openaire/api/mappers/query/DataSourceRequestMapper.java index be18d4c..6e91132 100644 --- a/src/main/java/eu/openaire/api/mappers/query/DataSourceRequestMapper.java +++ b/src/main/java/eu/openaire/api/mappers/query/DataSourceRequestMapper.java @@ -11,14 +11,10 @@ import java.util.Map; @Mapper(componentModel = "spring") public interface DataSourceRequestMapper { - Map sortFieldMapping = Map.ofEntries( - Map.entry("relevance", "score") - ); - @Mapping(target = "start", expression = "java( calculateStart(src.getPage(), src.getPageSize()) )") @Mapping(target = "rows", source = "pageSize") @Mapping(target = "debugQuery", source = "debugQuery") - @Mapping(target = "sort", expression = "java( eu.openaire.api.mappers.Utils.formatSortByParam(src.getSortBy(), sortFieldMapping) )") + @Mapping(target = "sort", expression = "java( eu.openaire.api.mappers.Utils.formatSortByParam(src.getSortBy(), SolrFieldsMapper.dataSourceSortMapping) )") SolrQueryParams toSolrQuery(DataSourceRequest src); @Named("calculateStart") @@ -29,24 +25,7 @@ public interface DataSourceRequestMapper { @AfterMapping default void paramsCustomMapping(DataSourceRequest src, @MappingTarget SolrQueryParams solrQueryParams) { - final Map solrFieldMapping = Map.ofEntries( - // search field mapping - Map.entry("search", "__all:(%s)"), - Map.entry("officialName", "datasourceofficialname:(%s)"), - Map.entry("englishName", "datasourceenglishname:(%s)"), - - // filter query field mapping - Map.entry("id", "__indexrecordidentifier:(%s)"), - Map.entry("pid", "pid:(%s)"), - Map.entry("subjects", "datasourceodsubjects:(%s)"), - Map.entry("dataSourceTypeName", "datasourcetypename:(%s)"), - Map.entry("contentTypes", "datasourceodcontenttypes:(%s)"), - Map.entry("relOrganizationId", "relorganizationid:(%s)"), - - // filter by related entity fields - Map.entry("relCommunityId", "communityid:(%s)"), - Map.entry("relCollectedFromDatasourceId", "collectedfromdatasourceid:(%s)") - ); + final Map solrFieldMapping = SolrFieldsMapper.dataSourceFieldMapping; var qList = new ArrayList(); @@ -84,7 +63,7 @@ public interface DataSourceRequestMapper { } if (!Utils.isNullOrEmpty(src.getSubjects())) { - fqList.add(String.format(solrFieldMapping.get("subjects"), Utils.escapeAndJoin(src.getSubjects(), "OR", false))); + fqList.add(String.format(solrFieldMapping.get("subjects"), Utils.escapeAndJoin(src.getSubjects(), "OR", true))); } if (!Utils.isNullOrEmpty(src.getDataSourceTypeName())) { @@ -92,7 +71,7 @@ public interface DataSourceRequestMapper { } if (!Utils.isNullOrEmpty(src.getContentTypes())) { - fqList.add(String.format(solrFieldMapping.get("contentTypes"), Utils.escapeAndJoin(src.getContentTypes(), "OR", false))); + fqList.add(String.format(solrFieldMapping.get("contentTypes"), Utils.escapeAndJoin(src.getContentTypes(), "OR", true))); } // related entity fields diff --git a/src/main/java/eu/openaire/api/mappers/query/SolrFieldsMapper.java b/src/main/java/eu/openaire/api/mappers/query/SolrFieldsMapper.java index ae578d4..7157899 100644 --- a/src/main/java/eu/openaire/api/mappers/query/SolrFieldsMapper.java +++ b/src/main/java/eu/openaire/api/mappers/query/SolrFieldsMapper.java @@ -4,6 +4,7 @@ import java.util.Map; public class SolrFieldsMapper { + // mappings for the organization entity public static final Map organizationFieldsMapping = Map.ofEntries( // search field mapping Map.entry("search", "__all:(%s)"), @@ -25,5 +26,28 @@ public class SolrFieldsMapper { Map.entry("relevance", "score") ); + // mappings for the datasource entity + public static final Map dataSourceFieldMapping = Map.ofEntries( + // search field mapping + Map.entry("search", "__all:(%s)"), + Map.entry("officialName", "datasourceofficialname:(%s)"), + Map.entry("englishName", "datasourceenglishname:(%s)"), + + // filter query field mapping + Map.entry("id", "__indexrecordidentifier:(%s)"), + Map.entry("pid", "pid:(%s)"), + Map.entry("subjects", "datasourceodsubjects:(%s)"), + Map.entry("dataSourceTypeName", "datasourcetypename:(%s)"), + Map.entry("contentTypes", "datasourceodcontenttypes:(%s)"), + + // filter by related entity fields + Map.entry("relOrganizationId", "relorganizationid:(%s)"), + Map.entry("relCommunityId", "communityid:(%s)"), + Map.entry("relCollectedFromDatasourceId", "collectedfromdatasourceid:(%s)") + ); + + public static final Map dataSourceSortMapping = Map.ofEntries( + Map.entry("relevance", "score") + ); }