diff --git a/src/main/java/eu/openaire/api/mappers/query/ProjectRequestMapper.java b/src/main/java/eu/openaire/api/mappers/query/ProjectRequestMapper.java index 6c78c10..50720c6 100644 --- a/src/main/java/eu/openaire/api/mappers/query/ProjectRequestMapper.java +++ b/src/main/java/eu/openaire/api/mappers/query/ProjectRequestMapper.java @@ -12,16 +12,10 @@ import java.util.Optional; @Mapper(componentModel = "spring") public interface ProjectRequestMapper { - Map sortFieldMapping = Map.ofEntries( - Map.entry("relevance", "score"), - Map.entry("startDate", "projectstartyear"), - Map.entry("endDate", "projectendyear") - ); - @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.projectSortMapping) )") SolrQueryParams toSolrQuery(ProjectRequest src); @Named("calculateStart") @@ -32,31 +26,7 @@ public interface ProjectRequestMapper { @AfterMapping default void paramsCustomMapping(ProjectRequest src, @MappingTarget SolrQueryParams solrQueryParams) { - final Map solrFieldMapping = Map.ofEntries( - // search field mapping - Map.entry("search", "__all:(%s)"), - Map.entry("title", "projecttitle:(%s)"), - Map.entry("keywords", "projectkeywords:(%s)"), - - // filter query field mapping - Map.entry("id", "__indexrecordidentifier:(%s)"), - Map.entry("code", "projectcode_nt:(%s)"), - Map.entry("acronym", "projectacronym:(%s)"), - Map.entry("fundingShortName", "fundershortname:(%s)"), - Map.entry("fundingStreamId", "fundinglevel0_name:(%s) OR fundinglevel1_name:(%s) OR fundinglevel2_name:(%s)"), - Map.entry("callIdentifier", "projectcallidentifier:(%s)"), - - Map.entry("startDate", "projectstartdate:[%s TO %s]"), - Map.entry("endDate", "projectenddate:[%s TO %s]"), - - // filter by related entity fields - Map.entry("relCommunityId", "communityid:(%s)"), - Map.entry("relOrganizationCountryCode", "relorganizationcountryid:(%s)"), - Map.entry("relOrganizationName", "relorganizationname: (%s) or relorganizationshortname: (%s)"), - Map.entry("relOrganizationId", "relorganizationid:(%s)"), - Map.entry("relCollectedFromDatasourceId", "collectedfromdatasourceid:(%s)") - - ); + final Map solrFieldMapping = SolrFieldsMapper.projectFieldMapping; var qList = new ArrayList(); @@ -93,7 +63,7 @@ public interface ProjectRequestMapper { } if (!Utils.isNullOrEmpty(src.getAcronym())) { - fqList.add(String.format(solrFieldMapping.get("acronym"), Utils.escapeAndJoin(src.getAcronym(), "OR", false))); + fqList.add(String.format(solrFieldMapping.get("acronym"), Utils.escapeAndJoin(src.getAcronym(), "OR", true))); } if (!Utils.isNullOrEmpty(src.getFundingShortName())) { @@ -101,12 +71,12 @@ public interface ProjectRequestMapper { } if (!Utils.isNullOrEmpty(src.getFundingStreamId())) { - String fundingStreamId = Utils.escapeAndJoin(src.getFundingStreamId(), "OR", false); + String fundingStreamId = Utils.escapeAndJoin(src.getFundingStreamId(), "OR", true); fqList.add(String.format(solrFieldMapping.get("fundingStreamId"), fundingStreamId, fundingStreamId, fundingStreamId)); } if (!Utils.isNullOrEmpty(src.getCallIdentifier())) { - fqList.add(String.format(solrFieldMapping.get("callIdentifier"), Utils.escapeAndJoin(src.getCallIdentifier(), "OR", false))); + fqList.add(String.format(solrFieldMapping.get("callIdentifier"), Utils.escapeAndJoin(src.getCallIdentifier(), "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 7157899..bdaac84 100644 --- a/src/main/java/eu/openaire/api/mappers/query/SolrFieldsMapper.java +++ b/src/main/java/eu/openaire/api/mappers/query/SolrFieldsMapper.java @@ -5,7 +5,7 @@ import java.util.Map; public class SolrFieldsMapper { // mappings for the organization entity - public static final Map organizationFieldsMapping = Map.ofEntries( + public static final Map organizationFieldsMapping = java.util.Map.ofEntries( // search field mapping Map.entry("search", "__all:(%s)"), Map.entry("legalName", "organizationlegalname:(%s)"), @@ -50,4 +50,38 @@ public class SolrFieldsMapper { Map.entry("relevance", "score") ); + + // mappings for the project entity + public static final Map projectFieldMapping = Map.ofEntries( + // search field mapping + Map.entry("search", "__all:(%s)"), + Map.entry("title", "projecttitle:(%s)"), + Map.entry("keywords", "projectkeywords:(%s)"), + + // filter query field mapping + Map.entry("id", "__indexrecordidentifier:(%s)"), + Map.entry("code", "projectcode_nt:(%s)"), + Map.entry("acronym", "projectacronym:(%s)"), + Map.entry("fundingShortName", "fundershortname:(%s)"), + Map.entry("fundingStreamId", "fundinglevel0_name:(%s) OR fundinglevel1_name:(%s) OR fundinglevel2_name:(%s)"), + Map.entry("callIdentifier", "projectcallidentifier:(%s)"), + + Map.entry("startDate", "projectstartdate:[%s TO %s]"), + Map.entry("endDate", "projectenddate:[%s TO %s]"), + + // filter by related entity fields + Map.entry("relCommunityId", "communityid:(%s)"), + Map.entry("relOrganizationCountryCode", "relorganizationcountryid:(%s)"), + Map.entry("relOrganizationName", "relorganizationname: (%s) OR relorganizationshortname: (%s)"), + Map.entry("relOrganizationId", "relorganizationid:(%s)"), + Map.entry("relCollectedFromDatasourceId", "collectedfromdatasourceid:(%s)") + + ); + + public static final Map projectSortMapping = Map.ofEntries( + Map.entry("relevance", "score"), + Map.entry("startDate", "projectstartyear"), + Map.entry("endDate", "projectendyear") + ); + }